[rrd-users] How to add up traffic logged with DERIVE?

Raimund Berger raimund.berger at gmail.com
Fri Jul 4 12:38:09 CEST 2008


Vadim <rrdtool at vadim.ws> writes:

> Hi,
>
> I've got a "wireless Internet" 3G modem. I want to generate bandwidth usage 
> graphs with projections of how long it will take to reach my bandwidth limit 
> at the current rate.
>
> I went with a DERIVE counter, because I'm tracking traffic on the ppp0 
> interface, which appears and disappears often (multiple times per day), which 
> resets the count. Also I want to be able to begin summing from any arbitrary 
> point.
>
> I want to take this DERIVE counter, and add up all the values up to each point 
> on the graph. Ideally, I also want to force the counter to 0  at the start of 
> a month, if possible.
>
> Unfortunately, all attempts so far have been unsuccessful. RRD doesn't seem to 
> let me reference a CDEF in itself. My first approach 
> was: "CDEF:acc_rx=acc_rx,rx,+". This produces an "invalid RPN expression". 
> Trying "CDEF:acc_rx=rx,TOTAL" doesn't work either, since TOTAL only works for 
> VDEFs. TOTAL is nearly what I want to get, if I give up on the zeroing the 
> count on the start of the month.
>

Interesting question. Been looking in the docs (note that I'm
comparatively new to rrdtool myself) a bit, and I'd say it should work
but only for a single point in time.

More specifically, you want to know how much time is left until you
hit your download cap at the current rate. So you might want to create
a graph which shows a history of those "times left". That, I believe,
is not possible, at least not without computing and storing
intermediate results. Namely since you need a VDEF TOTAL which runs
over the entire history to accumulate a single value.

What should work though is printing out the time left at one
particular moment, as a single value.

Example: let's assume the month started 20 days ago and $cap stores
your download cap. Something along the lines of this I guess should
print the value you want:

rrdtool graph /dev/null \
 DEF:rate=infile.rrd:value:AVERAGE \
 DEF:ttmp=infile.rrd:value:AVERAGE:start=-20days \
 VDEF:total=ttmp,TOTAL \
 CDEF:stmp=$cap,total,-,rate,/ \
 VDEF:left=stmp,LAST \
 PRINT:left:"%lf secs 'til dawn"

As said, for a single point in time, in this case "now". You won't get
a history this way because VDEF doesn't compute it.

Also, I can only guess the TOTAL gets your resets right, thanks to
DERIVE being hopefully defined with minimum 0 by you on rrd creation,
so you don't have any negative rates. It might possibly be still a bit
off, but not too far I'd say (didn't think it through though).

Maybe somebody else has a more sophisticated suggestion..

Regards,
R.



More information about the rrd-users mailing list