Search code examples
rrdtoolrrd

How to calculate given time average only


Curretly I am using below CDEF settings in my rrdcgi to show day time i.e. 7AM to 11 PM. Is there any setting to calculate the average of perticular time period only. I need to show the 7 day graphs so the average should be of 7 day, day time (7AM to 11 PM) only.

<h3>7 Day Performance</h3>
<RRD::GRAPH
        <RRD::GETVAR PATH>/rrdimg/7dayperformance.png
        --title="Performance"
        -w 1048 -h 266
        --imginfo '<IMG SRC=<RRD::GETVAR PATH>/rrdimg/%s WIDTH=%lu HEIGHT=%lu >'
        DEF:p1=<RRD::GETVAR PATH>/data1.rrd:data:AVERAGE
        DEF:p2=<RRD::GETVAR PATH>/data2.rrd:data:AVERAGE
        CDEF:p=p1,p2,2,AVG

        CDEF:gate=p1,POP,LTIME,86400,%,3600,/,FLOOR,DUP,23,LT,*,6,GT,INF,UNKN,IF   #for daytime image
        --end=midnight
        --start=end-7d
        AREA:gate#e0e0ff:"Day time"
        LINE2:p#ff6666:"performance"

EDIT

I am planning to filter out the logs from 7AM to 11PM and create new rrd files to create graphs. Is this a good approch. I dont think so because it will also include the null values.


Solution

  • When you use VDEF to calculate an average, it will build the average of the valid data, since you are already turning the non-office hours data to UNKN, all you have todo is to use VDEF and you should get what you are looking for.