1

I have a data feed that has a single value that increases over time until a forced wrap-around. I have the wrap-around under control. The value from the data feed I pass into a RRD GAUGE as ds1. I want to add a couple data sources to handle exceptions where on a certain condition detected by my script (that calls rrdupdate) to add some details for reporting. When the condition is true in the script, I want to update the RRD with:

  • the normal value into ds1
  • the difference of the prior value to the current value to be marked as batch exceptions into ds2
  • count (sum) all ds2 values in a similar way to ds1.

I've been playing with the below but wonder if there is a method using COMPUTE or do I need to code all the logic into the bash script to poll rrdinfo, fetch the last_ds lines and prep the data accordingly? Does the rrd COMPUTE type have the ability to read other DS's?

If ds2.value > 0 then set ds3.value to (ds3.last_ds + ds2.value) ?

I looked at the rpn-expression and found it references 'input' but does not show how to feed those inputs into the COMPUTE operation?

eg: Currently state

DS:ds1:GAUGE:28800:0:U
DS:ds2:COUNTER:1800:0:U
DS:ds3:GAUGE:1800:0:U
RRA:LAST:0.99999:1:72000
RRA:LAST:0.99999:4:17568
RRA:LAST:0.99999:8:18000
RRA:LAST:0.99999:32:4500
RRA:LAST:0.99999:96:1825

Desired state?

DS:ds1:GAUGE:28800:0:U
DS:ds2:COUNTER:1800:0:U
DS:ds3:COMPUTE:1800:0:U
DS:cs1:COMPUTE:input,0,GT,ds3,ds2,+,input,IF  <-- what is 'input' is it passed via rrdupdate cs1:[value]?
RRA:LAST:0.99999:1:72000
RRA:LAST:0.99999:4:17568
RRA:LAST:0.99999:8:18000
RRA:LAST:0.99999:32:4500
RRA:LAST:0.99999:96:1825

Alternatively ds1 could have store the total without the exceptions and I could use an AREA and a STACK to plot the total.

If someone is knowledgeable of rpn-expressions when used with rrd it would be a massive help to clarity the rpn-express input reference & what is possible. There is very limited info online about this. If the script has to poll the RRD files for last_ds and do the calculations that is fine just it RRA has the smarts in the COMPUTE DS type, I'd rather use them.

Thank you.

1 Answers1

0

A COMPUTE type datasource needs to have an RPN formula that completely describes it in terms of the other (non-compute) datasources. So, you cannot have multiple definitions of the same source, nor can it populate until the last of the other DS for that time window have been populated.

So, for example, if you have datasources a and b, and you want a COMPUTE type datasource that is equal to a if b<0, and a+b otherwise, you can use

DS:a:COUNTER:1800:0:U
DS:b:GAUGE:1800:0:U
DS:c:COMPUTE:b,0,GT,a,b,+,a,IF

From this, you can see how the definition of c uses RPN to define a single value using the values of a and b (and a constant). The calculation is performed solely within the configured time interval, and subsequently all three are stored and aggregated in the defined RRAs in the same way. You can also then use the graphs functions over c exactly as you would for a or b; the compute function is used only at data storing time.

Here is a full working example for the benefit of the original poster:

rrdtool create test.rrd --step 1800 \
 DS:a:COUNTER:28800:0:U \
 DS:b:COUNTER:28000:0:U \
 DS:c:GAUGE:3600:0:U    \
 DS:d:COUNTER:3600:0:U  \
 DS:x:COMPUTE:b,0,GT,a,b,+,a,IF  \
 RRA:LAST:0.99999:1:72000 \
 RRA:LAST:0.99999:4:17568 \
 RRA:LAST:0.99999:8:18000 \
 RRA:LAST:0.99999:32:4500 \
 RRA:LAST:0.99999:96:1825 
Steve Shipway
  • 3,754
  • 3
  • 22
  • 39
  • Ok great, thanks for that. So a & b are the data sources referenced (aka input) and that rrdupdate needs a & b values passed first with c empty. About the COMPUTE data source itself, how does one designate the min/max & heartbeat or are they all ignored becoming irrelevant due to these parameters being inherited from the data sources referenced (a & b). The COMPUTE formula could also handle the min & max parameters using IF's but not the heartbeat? I'll give it a go and thanks for the direction provided, it was helpful. – fireblade-au Feb 13 '22 at 01:49
  • 1
    For the compute item, there are no min/max (use IF if you need to have some) and heartbeat is implicit from that of any contributing DS values – Steve Shipway Feb 13 '22 at 21:52
  • I tried: ` root@mmh-unifi:~# rrdtool create test.rrd --step 1800 \ > DS:a:COUNTER:28800:0:U \ > DS:b:COUNTER:28000:0:U \ > DS:c:GAUGE:3600:0:U \ > DS:d:COUNTER:3600:0:U \ > DS:COMPUTE:b,0,GT,a,b,+,a,IF \ > RRA:LAST:0.99999:1:72000 \ > RRA:LAST:0.99999:4:17568 \ > RRA:LAST:0.99999:8:18000 \ > RRA:LAST:0.99999:32:4500 \ > RRA:LAST:0.99999:96:1825 ERROR: invalid DS format <-- ERROR root@mmh-unifi:~# ` I also tried the COMPUTER to source GAUGE DS types & a GAUGE + COUNTER & get the same error. It don't work. Help wanted with a working example. – fireblade-au Feb 14 '22 at 23:03
  • @fireblade-au You still need to give a name to a COMPUTE datasource. You get the error because you didnt name it. Use `DS:xxx:COMPUTE:....` to name it `xxx` and so on. – Steve Shipway Feb 17 '22 at 04:54