[rrd-users] Use a long-term average to color code results in shortterm graphs

Alex van den Bogaerdt alex at vandenbogaerdt.nl
Wed Oct 26 11:16:35 CEST 2011


----- Original Message ----- 
From: "Jeff Gilmore" <jeff at thegilmores.net>
To: <rrd-users at lists.oetiker.ch>
Cc: "Jeff Amaral" <jeff at freethoughtdesign.com>
Sent: Wednesday, October 26, 2011 1:26 AM
Subject: [rrd-users] Use a long-term average to color code results in shortterm graphs


>I am developing an interface for displaying electric power use (watts) over time.  On a single page (generated through the RRD PHP bindings), I display graphs of various time periods for a single meter.

Watts is energy per second. If you measure Watts per second, you will be measuring the change in power usage, not power usage itself. Compare to speed vs. acceleration.

Make sure to store Joules, not Watts, over time. Then you can get Watts out.


> Each graph uses code like the following to color code the datapoints to indicate if that usage is in a low, medium, high, or extra-high range of expected values (and thanks to Mark Janssen for his example of this!):
> 
>       "CDEF:Low=Watt,0,1000,LIMIT",
>        "CDEF:Mid=Watt,1000,2000,LIMIT",
>        "CDEF:High=Watt,2000,3500,LIMIT",
>        "CDEF:VHigh=Watt,3500,15000,LIMIT",
>        "AREA:Low#00ff00:0-1000",
>        "AREA:Mid#ffbf00:1000-2000",
>        "AREA:High#FF0000:2000-3500",
>        "AREA:VHigh#ffffff:> 3500\c",
> 
> 
> 
> This works fine with these hard-coded values for the LIMIT calculations.  However, I would like to change the code so that these ranges are not hard coded, but instead are scaled automatically to a moving long-term average (LTA) for this meter, such as the average over last 30 days.  

I think this can be done using an appropriate RRA, in combination with setting a specific start and end time in the DEF statement.
I am not sure though.

> For example, my four ranges could be scaled as follows:
> 
> low = from 0 to 60% of LTA
> med = from 60% to 140% of LTA
> high = from 140% to 200% of LTA
> Xhigh = greater than 200% of LTA

I guess you are able to do this part once you have the average.


> I would like all the graphs on the page to use the same range values, even if the period of the graph is shorter or longer than the 30 days used to calculate this LTA.

Not sure what you say here. If you say you want to calculate one average and then use it in more than one graph, it is probably more easy, more wise and more effective to make this a two-pass setup anyway.

If you want to calculate different averages, just 30 days for each graph but from a different source, then "DEF:....:start=....:end=..." will probably work.  Again: I am not sure.

> I assume I would need to call RRDGraph first with a 30 day range and a only PRINT statement to get this LTA value and store it, then use it to generate the real graphs in my PHP code.   But I wonder if there is some way to do this in a single graph definition in RRD?

For one graph: yes. And in theory you could have a PRINT statement in that graph, and use it in the next. But that would probably make things way too complicated.

> 
> If not, then I need to figure out how to get the values from PRINT statements back to PHP.  Normally in command-line RRD, the PRINT statements go to stdout, but it is not clear from the documentation if there is any way for these to get passed back to PHP.  Any suggestions?

No offence, but RTFM. I cannot think of a reason why this would not be supported.


HTH
Alex



More information about the rrd-users mailing list