📜 ⬆️ ⬇️

The sum of the measurements in rrdtool

What about

RRD and RRDTool are firmly established in our life as a means of storing statistical data and drawing graphs on them. If with graphs, in principle, everything is clear, then a little more benefit can be gained from the field of legend. In particular, it is possible to output the sum of all data source values ​​(datasource), for example, incoming traffic over a period of time, which can be used later for approximate estimations. My example is for pnp4nagios , but true for all other rrdtool based systems.


How to make

rrdtool allows you to set custom data representations using built-in functions based on the original, in particular, there are functions MIN, MAX, addition, subtraction, and so on, in this case we can use the TOTAL function. What does it make clear from the name - returns the level from each interval multiplied by the step size, which will give the total amount of the indicator.
The original template looked like this:

$opt[1] = " --vertical-label \"Traffic\" -b 1000 --title \"Interface Traffic for $hostname / $servicedesc\" ";
$def[1] = "DEF:var1=$rrdfile:$DS[1]:AVERAGE " ;
$def[1] .= "DEF:var2=$rrdfile:$DS[2]:AVERAGE " ;
$def[1] .= "LINE1:var1#003300:\"in \" " ;
$def[1] .= "GPRINT:var1:LAST:\"%7.2lf %Sb/s last\" " ;
$def[1] .= "GPRINT:var1:AVERAGE:\"%7.2lf %Sb/s avg\" " ;
$def[1] .= "GPRINT:var1:MAX:\"%7.2lf %Sb/s max\\n\" " ;
$def[1] .= "LINE1:var2#00ff00:\"out \" " ;
$def[1] .= "GPRINT:var2:LAST:\"%7.2lf %Sb/s last\" " ;
$def[1] .= "GPRINT:var2:AVERAGE:\"%7.2lf %Sb/s avg\" " ;
$def[1] .= "GPRINT:var2:MAX:\"%7.2lf %Sb/s max\\n\" ";

')
Define two new data sources from var1 (input traffic) and var2 (output traffic)

$def[1] .= "VDEF:totalin=var1,TOTAL ";
$def[1] .= "VDEF:totalout=var2,TOTAL ";

Now in the totalin & totalout variables we have just the amounts, it remains to display them in legends, for this we add

$def[1] .= "GPRINT:totalin:\"%3.2lf %s ttl\\n\" ";
$def[1] .= "GPRINT:totalout:\"%3.2lf %s ttl\\n\" ";

Along the way, we remove line breaks and as a result we get:
$opt[1] = " --vertical-label \"Traffic\" -b 1000 --title \"Interface Traffic for $hostname / $servicedesc\" ";
$def[1] = "DEF:var1=$rrdfile:$DS[1]:AVERAGE " ;
$def[1] .= "DEF:var2=$rrdfile:$DS[2]:AVERAGE " ;
$def[1] .= "VDEF:totalin=var1,TOTAL ";
$def[1] .= "VDEF:totalout=var2,TOTAL ";
$def[1] .= "LINE1:var1#003300:\"in \" " ;
$def[1] .= "GPRINT:var1:LAST:\"%7.2lf %Sb/s last\" " ;
$def[1] .= "GPRINT:var1:AVERAGE:\"%7.2lf %Sb/s avg\" " ;
$def[1] .= "GPRINT:var1:MAX:\"%7.2lf %Sb/s max\" " ;
$def[1] .= "GPRINT:totalin:\"%3.2lf %s ttl\\n\" ";
$def[1] .= "LINE1:var2#00ff00:\"out \" " ;
$def[1] .= "GPRINT:var2:LAST:\"%7.2lf %sb/s last\" " ;
$def[1] .= "GPRINT:var2:AVERAGE:\"%7.2lf %Sb/s avg\" " ;
$def[1] .= "GPRINT:var2:MAX:\"%7.2lf %Sb/s max\" ";
$def[1] .= "GPRINT:totalout:\"%3.2lf %s ttl\\n\" ";


Total was:
It was

It became:

has become

Well, as without nginksa and counting millions of hits on our website download and its statistics!
It was:

It was

It became:

image

Source: https://habr.com/ru/post/88100/


All Articles