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

Jeff Gilmore jeff at thegilmores.net
Wed Oct 26 01:26:03 CEST 2011


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.

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.  

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 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.

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?

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?

Thanks,

Jeff


More information about the rrd-users mailing list