RRDTool

From dbawiki
Revision as of 22:12, 9 December 2013 by Stuart (talk | contribs) (Update the database and print out the latest graph)
Jump to: navigation, search

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

Schedule this shell to run on a regular basis

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

References

Original page