Difference between revisions of "RRDTool"

From dbawiki
Jump to: navigation, search
(Update the database and print out the latest graph)
(Update the database and print out the latest graph)
Line 20: Line 20:
 
<pre>
 
<pre>
 
#!/bin/bash
 
#!/bin/bash
 +
 
# update data
 
# update data
 
mem_used=`free -m | grep Mem | awk '{print $3}'`
 
mem_used=`free -m | grep Mem | awk '{print $3}'`
 
/usr/bin/rrdtool update /root/mem.rrd --template mem N:$mem_used
 
/usr/bin/rrdtool update /root/mem.rrd --template mem N:$mem_used
 +
 
# create graph
 
# create graph
/usr/bin/rrdtool graph /var/www/html/mem.png \
+
/usr/bin/rrdtool graph /var/www/html/mem.png   \
-w 500 -h 150 -a PNG \
+
    -w 500 -h 150 -a PNG                       \
--slope-mode \
+
    --slope-mode                               \
--start -3600 --end now \
+
    --start -3600 --end now                   \
--font DEFAULT:7: \
+
    --font DEFAULT:7:                         \
--title &quot;Memory used (last hour)&quot; \
+
    --title "Memory used (last hour)"          \
--watermark &quot;`date`&quot; \
+
    --watermark "`date`"                      \
--x-grid MINUTE:5:MINUTE:10:MINUTE:10:0:%R \
+
    --x-grid MINUTE:5:MINUTE:10:MINUTE:10:0:%R \
--alt-y-grid --rigid \
+
    --alt-y-grid                               \
--lower-limit=0 \
+
    --rigid                                   \
--color BACK#363636 \
+
    --lower-limit=0                           \
--color CANVAS#000000 \
+
    --color BACK#363636                       \
--color GRID#999999 \
+
    --color CANVAS#000000                     \
--color MGRID#B5B5B5 \
+
    --color GRID#999999                       \
--color FONT#CCCCCC \
+
    --color MGRID#B5B5B5                       \
DEF:memory=/root/mem.rrd:mem:MAX \
+
    --color FONT#CCCCCC                       \
AREA:memory#FFD700 \
+
    DEF:memory=/root/mem.rrd:mem:MAX           \
LINE1:memory#FFD700:&quot;Memory used (MB)&quot; \
+
    AREA:memory#FFD700                         \
GPRINT:memory:LAST:&quot;Last\: %5.2lf&quot; \
+
    LINE1:memory#FFD700:Memory used (MB)       \
GPRINT:memory:AVERAGE:&quot;Avg\: %5.2lf&quot; \
+
    GPRINT:memory:LAST:Last\: %5.2lf           \
GPRINT:memory:MAX:&quot;Max\: %5.2lf&quot; \
+
    GPRINT:memory:AVERAGE:Avg\: %5.2lf         \
GPRINT:memory:MIN:&quot;Min\: %5.2lf&quot;
+
    GPRINT:memory:MAX:Max\: %5.2lf             \
 +
    GPRINT:memory:MIN:Min\: %5.2lf
 
</pre>
 
</pre>
 +
 +
====References====
 +
[http://khmel.org/?p=236 Original page]

Revision as of 22:09, 9 December 2013

Data Source

free -m
             total       used       free     shared    buffers     cached
Mem:           499        214        284          0          2        169
 
# Total
free -m | grep Mem | awk '{print $2}'
499
 
# Used
free -m | grep Mem | awk '{print $3}'
65

Create a database

rrdtool create /root/mem.rrd --step 60 DS:mem:GAUGE:120:0:499 RRA:MAX:0.5:1:31622400

Update the database and print out the latest graph

#!/bin/bash

# update data
mem_used=`free -m | grep Mem | awk '{print $3}'`
/usr/bin/rrdtool update /root/mem.rrd --template mem N:$mem_used

# create graph
/usr/bin/rrdtool graph /var/www/html/mem.png   \
    -w 500 -h 150 -a PNG                       \
    --slope-mode                               \
    --start -3600 --end now                    \
    --font DEFAULT:7:                          \
    --title "Memory used (last hour)"          \
    --watermark "`date`"                       \
    --x-grid MINUTE:5:MINUTE:10:MINUTE:10:0:%R \
    --alt-y-grid                               \
    --rigid                                    \
    --lower-limit=0                            \
    --color BACK#363636                        \
    --color CANVAS#000000                      \
    --color GRID#999999                        \
    --color MGRID#B5B5B5                       \
    --color FONT#CCCCCC                        \
    DEF:memory=/root/mem.rrd:mem:MAX           \
    AREA:memory#FFD700                         \
    LINE1:memory#FFD700:Memory used (MB)       \
    GPRINT:memory:LAST:Last\: %5.2lf           \
    GPRINT:memory:AVERAGE:Avg\: %5.2lf         \
    GPRINT:memory:MAX:Max\: %5.2lf             \
    GPRINT:memory:MIN:Min\: %5.2lf

References

Original page