Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to make an average of 5 samples and calculate a single value:

Current output - I put resolution of 5 minutes but receive 5 samples:

$ rrdtool fetch file.rrd  AVERAGE -r 300 --start 1200000000 --end 1200000300
1200000000: 1.3938888889e+00
1200000060: 4.9572222222e+00
1200000120: 7.1675000000e+00
1200000180: 1.0982500000e+01
1200000240: 7.6136111111e+00
1200000300: 7.2169444444e+00

Desired result:

$ rrdtool fetch file.rrd  AVERAGE -r 300 --start 1200000000 --end 1200000300
1200000000: 1.3938888889e+00
1200000300: x.xxxxxxxxxxe+00 - average

I want calculate it with rrdtool or other language like perl, bash, etc...

share|improve this question
    
post a small amount of the source data –  igelkott Feb 21 '13 at 20:25

1 Answer 1

The fetch command only retrieves data from the raw RRA; if you do not have an RRA of the requested granularity, then the nearest available will be used, but no additional calculations will be performed.

Add a new RRA to your RRD file when you create your RRD file, with a 1cdp==5pdp rule. EG

    rrdtool create file.rrd -s 60 
        DS:ds0:GAUGE:120:0:100 
        RRA:AVERAGE:0.5:1:400 RRA:AVERAGE:0.5:5:400

This example sets 400 rows; you may wish to use more.

When you have a 5pdp RRA, then you can use rrdtool fetch -r 300, otherwise if you only have a 1pdp RRA, you can only use a resolution of 60 (one step).

You may also like to take a look at rrdtool xport which (in the same way as rrdtool graph) allows you to define output calculated values which can be summaries.

   rrdtool xport  --step 300 --start 1200000000 --end 1200000300
        --maxrows 400
        DEF:value=file.rrd:ds0:AVERAGE
        XPORT:value

This assumes your DS to be names ds0 of course, and is not as efficient as doing a fetch when you already have the required RRA.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.