Your Linux Data Center Experts

This morning I figured out how to get rrdtool to report the 95%ile utilization to stdout. It's kind of convoluted how you do it, you have to use the “graph” subcommand, but write the graph to /dev/null, and use “PRINT” instead of “GPRINT”. For example:

eval `$RRDTOOL graph -f '' -s "$1" /dev/null \
   DEF:in="$2":in:AVERAGE \
   DEF:out="$2":out:AVERAGE \
   CDEF:inbits=in,8,* \
   CDEF:outbits=out,8,* \
   VDEF:95pct_out=outbits,95,PERCENT \
   PRINT:95pct_in:"IN='%.2lf %Sb'" \
   PRINT:95pct_out:"OUT='%.2lf %Sb'"

Where “$1” is the period start time (like “-1d” for showing the 95%ile of today), and “$2” is the .rrd file name. I do an “eval” to parse the output (making $IN and $OUT shell variables). The “-f ''” tells is not to write an image size string.

It may also be useful to change the last two lines to use a format something like “IN='%.2lf; IN_MAGNITUDE=%S” (to get something like IN=2.50 and IN_MAGNITUDE=M) or just “IN=%.0lf” (to get the full bits like IN=2500000).

Again, rrdtool proves to be amazingly flexible, given enough time to wrap your mind around it.

comments powered by Disqus

Join our other satisfied clients. Contact us today.