rrdtool - graph data

Posted on Sun 23 December 2012 by Pavlo Khmel

rrdtool

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}'
499

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

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
rrdtool-1.4.7-1.el6.rfx.i686

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

#!/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.2lfttt"

Add cron job every minute:

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