More excerpts from collector.sh. These come right after gathering the cpu data from sar and feeding it into rrd_cpu_collector.sh:
rrdtool graph /data/reporting/html/images/${i}_sar_thumb.png -u 100 -j -w 200 -h 80 -s `perl -e 'print time-86400'` DEF:linea=${i}_sarcpu.rrd:user:AVERAGE DEF:lineb=${i}_sarcpu.rrd:sys:AVERAGE AREA:lineb#00FF00:"Sys" LINE2:linea#FF0000:"User" |grep -v 200
rrdtool graph /data/reporting/html/images/${i}_sar_daily.png -u 100 -t "last updated at $UPDATED" -s `perl -e 'print time-86400'` DEF:linea=${i}_sarcpu.rrd:user:AVERAGE DEF:lineb=${i}_sarcpu.rrd:sys:AVERAGE AREA:lineb#00FF00:"Sys" LINE2:linea#FF0000:"User" |grep -v 481
rrdtool graph /data/reporting/html/images/${i}_sar_weekly.png -u 100 -s `perl -e 'print time-604800'` DEF:linea=${i}_sarcpu.rrd:user:AVERAGE DEF:lineb=${i}_sarcpu.rrd:sys:AVERAGE AREA:lineb#00FF00:"Sys" LINE2:linea#FF0000:"User" |grep -v 481
rrdtool graph /data/reporting/html/images/${i}_sar_monthly.png -u 100 -s `perl -e 'print time-2592000'` DEF:linea=${i}_sarcpu.rrd:user:AVERAGE DEF:lineb=${i}_sarcpu.rrd:sys:AVERAGE AREA:lineb#00FF00:"Sys" LINE2:linea#FF0000:"User" |grep -v 481
rrdtool graph /data/reporting/html/images/${i}_sar_yearly.png -u 100 -s `perl -e 'print time-31536000'` DEF:linea=${i}_sarcpu.rrd:user:AVERAGE DEF:lineb=${i}_sarcpu.rrd:sys:AVERAGE AREA:lineb#00FF00:"Sys" LINE2:linea#FF0000:"User" |grep -v 481
I warned you, it's ugly. Okay, let's dissect one of those lines -- I'll pick out the daily one, since I showed you that graph a few posts ago.
rrdtool graph /data/reporting/html/images/${i}_sar_daily.png -u 100 -t "last updated at $UPDATED" -s `perl -e 'print time-86400'` DEF:linea=${i}_sarcpu.rrd:user:AVERAGE DEF:lineb=${i}_sarcpu.rrd:sys:AVERAGE AREA:lineb#00FF00:"Sys" LINE2:linea#FF0000:"User" |grep -v 481
So we call rrdtool and tell it we're going to generate a graph. We're saving it in /data/reporting/html/images/XXX_sar_daily.png, where XXX is the hostname we're iterating over. So far, not so bad. The -u 100 forces the graph to scale to 100%. The -t is the title we put on the graph (and $UPDATED is set earlier in the script to the current time). The -s is the start time for the graph (how far to go back). The perl scriptlet that's called prints the current time minus 24 hours. The DEF: bits say that the first line is the user cpu and the second is the system cpu, taken as averages from the rrd. We then pipe the output (a message saying a 481x??? pixel png graph was created) to grep -v 481 so we don't have pesky messages coming out of the script. The graph this generates is far easier to read than what goes into it:

No comments:
Post a Comment