Transformation: Add previous DCI value to current DCI value?

Started by Millenium7, April 30, 2018, 04:38:31 AM

Previous topic - Next topic

Millenium7

I'm trying to create a usage graph in netXMS and having trouble with the formulas to do so

At the moment i'm polling an interface for the traffic, then using simple delta transformation with "return max($1, 0);" (to avoid negative numbers if i.e. router restarts)
What I need now is a way to read the last dci value and add it to the current result, so that it continually increments

i.e. currently it returns
6pm - 53mb
(router restarts)
7pm - 0mb
8pm - 155mb
9pm - 110mb

I need to add each previous value together so that it shows a running total
i.e.
6pm - 53mb
7pm - (0mb + 53mb) = 53mb
8pm - (53mb + 155mb) = 208mb
9pm - (208mb + 110mb) = 318mb


Tursiops

https://wiki.netxms.org/wiki/NXSL:GetDCIValue might work.
As you are in the transform stage, the value that you just collected can't be returned as a result yet, which means it should return the previous one?

Millenium7

I think that will do it. I've tested with
t = GetDCIValue($node,8347);
return t;

And it does return the previous value. But i'm having trouble with the syntax for the DCI id (since I dont want to type it in manually)
I've tried
t = GetDCIValue($node,$dci->id);
return t;

And its giving my an error. I can't find the syntax I need to return the ID number of the current DCI

While i'm at it, is there a better way for troubleshooting and finding out the correct syntax? I struggle with this all the time because its very difficult to know if i'm typing syntax correctly, or wht values are being returned. Is there a console I can open and type these sorts of commands in and get some realtime help on syntax and output, similar to a SSH terminal i.e. type GetDCI<tab> and it will me all the available commands. As well as manually type those in i.e. "echo GetDCIValue(230,123)" and see the output

Millenium7

Ok I found reference that there's a bug with read access from a forum post back in 2014

https://www.netxms.org/forum/general-support/transformation-script-and-$dci-object/

It seems that bug is still present, test will show an error but $dci->id does work when actually polling the DCI. So this is what I have come up with so far

t = GetDCIValue($node,$dci->id);
if (t != null)
return t + $1;
else
return $1 - $1;


Transformation set to simple delta. The first result will always return 0, after that it counts up usage continuously

The next question is then how do I handle resetting the value back to 0 after a day/week/month?
Is there a scripting command to clear all old data? Then I can simply add some code to check the date/time and clear the values accordingly
Alternatively I could do the same but manually reset the value to 0 which would work fine I suppose. The graph would show a saw-tooth pattern over time
The ultimate solution would be to sum all previous DCI values between the last '0', delete all those entries and replace it with a single sum entry. That would drastically reduce the amount of stored data and let me see a single spike per day/week/month on a history graph separated by a single 0 entry

Victor Kirhenshtein

Hi,

it is not possible to delete data from within script. Reset to 0 will work (you can check current date and time in script and return 0 if it is first poll after midnight).

Another possible option is to create two DCIs - one short term and one long term. Long term DCI will have custom schedule to collect it once per day/week/month/etc. and it will get get sum of values from short term DCI for required period. Retention time for short term DCI can be set to desired time interval plus some extra time to allow long term DCI collector script to run.

Best regards,
Victor

Millenium7

Ok next question

I was considering creating a table instead of lots of individual DCI's. That way I can have daily/weekly/monthly usage as well as other information like number of reconnects etc all on a single line for an interface without dozens/hundreds of DCI entries

Is it possible to do simple delta calculation in table columns yet? I can't see a drop down option for it, can I do it manually somehow?

Victor Kirhenshtein

Delta calculation for tables is not implemented yet.

Best regards,
Victor