Search code examples
fetchrrdtool

rrd fetch last 4hr and last 24 hr


Would this be a valid way to get the total AVG from the first datasource in a rrd database file for the past 4 hrs? The parent solution is pnp4nagios and records a value every 5minuts/300 seconds and all that works great. Just want to learn how to query the rrd file manually and accurately.

I use some awk statements to average the data source column that I am interested in. This isn't pressing or anything, I am just trying to learn a little bit more about rrdtool

rrdtool fetch rrdfile.rrd AVERAGE -r 300 -s -4hr|awk '{print $2}'|grep -v nan|cut -c 1-4|awk 'NR>2'|awk '{ sum += $1; n++ } END { if (n > 0) print sum / n; }'

--Edit-- Found this solution after some time of reading and testing. If you use pnp4nagios and want to query a rrd database to print the values vs. graphing them, this worked for me.

rrdtool graph test.png --start -4hour 'DEF:data=test.rrd:1:AVERAGE' PRINT:data:AVERAGE:%lf|awk 'NR>1'

simply replace GPRINT with Print. you will then be able to compare the output against the pnp4nagios graphs and see that the Datasoure output that is printed is the same value as the graphs.


Solution

  • rrdtool graph test.png --start -4hour 'DEF:data=test.rrd:1:AVERAGE' PRINT:data:AVERAGE:%lf|awk 'NR>1'