# Minimum, Average, Maximum

## Intro

Some people ask why RRDtool shows different maximum rates for different time ranges. Here I hope to explain why this is, and how to do it differently.

If you don't know what PDP and CDP mean, then for now it is enough to understand that these are units of time and data: Primary Data Point and Consolidated Data Point.

This article does also mention consolidation. This process is explained in more detail elsewhere on this site.

## Everything is a rate

Everything is processed as a rate. This means a number of <something> per time interval. If you create a picture, with the rate on the Y-axis and the amount of time on the X-axis, you get the total number of <something> during that time interval. The surface of the rectangle (x times y) is the total amount. This is important to understand! You are not looking at the Y value alone, you are looking at X times Y!

## Consolidate

Remembering each one-minute interval for a total of ten years' worth, is a bit too much. First of all, this consumes too much resources, secondly you're probably not interested in such high detailed information over a long time period. That's why consolidation exists: pack a large number of PDPs into one CDP. The following picture shows one RRA where each CDP is one minute worth of data, and the other RRA has CDPs of three minutes each. It is important to remember that rates are tied to time as well as value, so not just the Y-axis but also the X-axis. The surface of each of these graphs is the same, resulting in the same amount of (e.g.) bytes transfered in the same amount of time: 0x1+3x1+0x1+1x1+2x1+3x1=9, vs. 1x3+2x3=9.

But there's more to see in this picture. If these two graphics would be actual RRDtool graphics, we could use GPRINT to print some properties such as minimum, average and maximum. The following table shows what would happen:

GPRINTSix short intervalsTwo large intervals
Minimum(0,3,0,1,2,3)->0(1,2)->1
Average(0,3,0,1,2,3)->1.5(1,2)->1.5
Maximum(0,3,0,1,2,3)->3(1,2)->2

While correct, this may not be what you were expecting nor what you want/need. Nevertheless, it is what you asked RRDtool to do when you copied an example "rrdtool create" statement.

## CF: Consolidation Function

In the previous chapter you were introduced to RRDtool's consolidation using the AVERAGE consolidation function (CF). When looking at averages, less common high (or low) rates tend to be smoothend towards the average rate. But what if you really would like to know the highest (or lowest) rate seen? You will need to store those as well. Just create another RRA in your RRD, with the CF you desire. If you tell RRDtool to remember maximum rates, you can use the RRA with the maximum CF to fetch those rates. Similarly for minimum, average and last.

CFdescription
MINremember the lowest rate of all PDPs in each CDP
AVERAGEremember the average rate of all PDPs in each CDP
MAXremember the highest rate of all PDPs in each CDP
LASTremember the last of all PDPs in each CDP
Consolidation
Minimum(0,3,0),(1,2,3) -> (0),(1)
Average(0,3,0),(1,2,3) -> (1),(2)
Maximum(0,3,0),(1,2,3) -> (3),(3)
Last(0,3,0),(1,2,3) -> (0),(3)

If you now GPRINT the maximum of all maximums, you will be printing three instead of one. This is what you want and expect. Similarly you get zero instead of one when you GPRINT the minimum of all minimums.

## Beware!

Make sure you get your computations right! When working with averages, you can do all sorts of operations without problem. But as soon as you're introducing minimums and maximums, you need to be careful not to do something unexpected and undesired. An example: suppose you are monitoring two counters. You are remebering minimum, average and maximum values. You are also computing a sum of the two using some CDEF statements. The following mistake is easily made:

```DEF:min1=my.rrd:counter1:MIN
DEF:min2=my.rrd:counter2:MIN
DEF:avg1=my.rrd:counter1:AVERAGE
DEF:avg2=my.rrd:counter2:AVERAGE
DEF:max1=my.rrd:counter1:MAX
DEF:max2=my.rrd:counter2:MAX
CDEF:mintotal=min1,min2,+
CDEF:avgtotal=avg1,avg2,+
CDEF:maxtotal=max1,max2,+
```

This is wrong because you are adding stuff that you cannot add. A picture says more than a thousand words: Instead you will need to find max( max(counter1),max(counter2) ):

```DEF:min1=my.rrd:counter1:MIN
DEF:min2=my.rrd:counter2:MIN
DEF:avg1=my.rrd:counter1:AVERAGE
DEF:avg2=my.rrd:counter2:AVERAGE
DEF:max1=my.rrd:counter1:MAX
DEF:max2=my.rrd:counter2:MAX
CDEF:mintotal=min1,min2,LT,min1,min2,IF
CDEF:avgtotal=avg1,avg2,+
CDEF:maxtotal=max1,max2,GT,max1,max2,IF
```

## Wrapup

This concludes this explanation of how rrdtool stores data in its RRDs. There is of course much more to it. Have a look at the documentation for rrdtool create and notice how it can deal with unknown input (both in the PDP and CDP generating stages). How the stored data is used is also not explained here, look at rrdtool graph and/or rrdtool fetch for that. Important to remember is that data representation works with CDPs inside RRAs. I hope this document aided in your understanding of how these are generated.

Do you like this information? Tell others! Don't you? Tell me!

This page was created by Alex van den Bogaerdt, an independent IT consultant. If you want to provide feedback or if you want to hire me please see .
Back to the top of this page. You can also go to the index