[rrd-users] Probleme using several dbs and unknown values

Simon Hobson linux at thehobsons.co.uk
Wed Jan 30 13:21:09 CET 2013

unicsonline wrote:
I am tracing a long time graph, where datas are dispatched along different dbs

for example for period1, I use db1.rrd, for period2 I use db2.rrd, etc...

Of course depending date my infos are present in only one dbs at the same time, and requests sent to an other one returns an unknown value.

My problem is to deal with this unknown values.

In a first try, I have used a workaround with a cdef adding all the values, and replacing unknown ones with a 0 :

for example, with 3 periods:


that works, average and max values are ok, but min and last are positionned to 0 (it's normal, because some unknown values are present, and are replaced by 0 in syntax)

In fact the better syntax would be something like : 

if period1 != unkown use period1
else period2 != unkown use period2
else period3 != unkown use period3
else use unknown

to preserve unknown values.

There are several ways you can do this. One I used in the past when I was switching between two sets fo DBs was to work on date. Basically, if date < some fixed value then use A, else use B. I don't recall the syntax I used (it was a couple of years ago and I no longer have the code lying around), but it wasn't hard.

But if all you want is the simple expression you've given - ie you will only ever use one source - then this would look something like :

Which means, if A is unknown then use B else use A. You can either use multiple CDEFs (easier to see), just expand the one - I'll put brackets in this one to show the grouping, you take them out to get a valid expression.
Which means If A is unknown then use the result of (if B is unknown then use C, else use B), else use A.
So stripping out the brackets, you getA,UN,B,UN,C,B,IF,A,IF which I think should do what you want - unless I've got it wrong of course !

Bear in mind that if (for example) you consolidate down to daily values, and your data collection switched part way through a day, then you'll have one day when two sources could have a value. Eg if your measured value was a steady 1, and you switched collection at mid day, then A and B would both contain 0.5 for that day. This can be worked around if it's a problem - it just makes the RPN more complicated.

More information about the rrd-users mailing list