[rrd-users] Calculating Totals

Shem Valentine rrdtool at valentinenews.net
Fri Feb 12 19:19:01 CET 2010


I am trying to gather total bytes transferred and am having some 
inconsistencies.

This command will produce a more accurate total (Don't mind the LAST, I 
only have one PDP per CF)

rrdtool graph /dev/null \
   --start -7d --end now \
  DEF:down=test.rrd:Download:LAST \
  DEF:up=test.rrd:Upload:LAST \
  CDEF:tt=down,up,+,8,/ \
  VDEF:total=tt,TOTAL \
  PRINT:total:\%lf


When I try to total using fetch, I get different (lower) results, which I'm 
assuming is related to UNKOWN's, am I missing something?

Here is the sample code in python

#!/usr/bin/env python
import rrdtool

fetch = rrdtool.fetch('test.rrd', 'LAST', '-s -7d', '-e now')
data = fetch[2]
step = fetch[0][2]

total=0
for down, up in data:
	tmp = 0
	if down is not None:
		tmp += down
	if up is not None:
		tmp += up
	total += tmp * step / 8

print total



More information about the rrd-users mailing list