Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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


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.