rrdtool - graph data

Posted on Sun 23 December 2012


rrdtool - store and graph data. This example graph memory usage.

Source data:

free -m
             total       used       free     shared    buffers     cached
Mem:           499        214        284          0          2        169

# Total
free -m | grep Mem | awk '{print $2}'

# Used
free -m | grep Mem | awk '{print $3}'

Latest rrdtool version is recommended. Now it is rrdtool-1.4.7.

It can be install via http://repoforge.org

rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
yum --enablerepo=* install rrdtool
rpm -q  rrdtool

Create data storage:

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

Data update and graph creation via script /root/update_and_create_graph.sh

# 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 
--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 
--color BACK#363636 
--color CANVAS#000000 
--color GRID#999999 
--color MGRID#B5B5B5 
--color FONT#CCCCCC 
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.2lfttt"

Add cron job every minute:

crontab -l
* * * * * /root/update_and_create_graph.sh