Checking if time on different servers is identical

Started by DanG, September 30, 2011, 07:58:13 AM

Previous topic - Next topic

DanG

Hi,

It's easy to collect time on servers individually, but where do I compare the times of the different servers to create an event should they be unequal (within a margin of course)?

Thanks,

Dan

Victor Kirhenshtein

Hi!

You can create a condition object, add DCIs collecting current time from different servers, and write a script which will calculate deviation.

Best regards,
Victor

DanG

Hi Vicror,

I must have missed the "condition objects" in the documentation, thanks.

I'm not sure however how I should reference the DCI's in that object.
Normaly one would use FindDCIByName($node, "System.CurrentTime")
but in the condition object $node represen the the condition object  and there are serveral System.CurrentTime DCI's for the different servers.

Regards,

Dan

Victor Kirhenshtein

You miss "conditions" in documentation because it is not documented :)

Working with the conditions is as follows:

1. Create condition object somewhere in the infrastructure (services) tree.
2. Open properties, and on "Data" page, add DCIs
3. The, on "Script" page, write checking script. DCIs can be referred using variables $1, $2, etc., or via $values array. Script should return true if condition is active, and false otherwise. On status change, appropriate event being generated (configured on "Events and Status" page).

Starting with version 1.1.5, you can use foreach operator for enumerating DCIs, for example:


sum = 0;
foreach(v : $values)
{
trace(1, "+++ value = " . v . " +++");
sum += v;
}
trace(1, "+++ sum = " . sum . " +++");


Best regards,
Victor

DanG

Hi Victor,

Not having 1.1.5 (yet) I tried 1..1.4:


for(i=0; $values != null; i++)
{
...
}

is still giving an error. What's wrong?

Regards,

Dan


Victor Kirhenshtein

#5
This is because you use array instead of referencing it's elements. Correct version should looks like this:


for(i=0; $values[i] != null; i++)
{
  trace(0,"+++" . $values[i] . "+++");

  minTime = min(minTime, $values[i]);
  maxTime = max(minTime, $values[i]);
}


Best regards,
Victor

DanG

Victor

My script above was mistyped (sorry), the script on the server has the same text as your suggestion.

The error returned is for following line:
for(i=0; $values != null; i++)

Could it be something else?

Dan

Victor Kirhenshtein

Oops, that's my failure :( Prior to 1.1.5 DCI values only accessible via $1, $2, etc. variables. Array $values also was added in 1.1.5. I suggest to do upgrade first :)

Best regards,
Victor

DanG

Victor,

I wanted to ask when 1.1.5 will be released, but noticed it was released today (JIT).
I'll upgrade and try again. Thanks.

Regards,

Dan

DanG

Victor,
I upgraded to 1.1.5, this time with no problems. Great!

I set the new syntax for obtaining the values and it works.

In my specific case the result is not what I had expected. I use the DCI System.CurrentTime to get the time on several servers, As they're using NTP their time is within a few milliseconds of each other yet the my script calculates a different deviations each time (up to a minute apart). As the pooling interval of both DCI's was 60 seconds I guess this has to do with the moment NetXMS grabs the value from each of the servers. This bring me to the question of where is the condition object calculated, is it each time one of the DCI's in the list of DCI's of the condition object pool changes?
I changed to pooling interval to 10 seconds and the deviation got to under 10 seconds, I could set is to once every seconds which probably resolve the problem, however it will be using a lot of resources for just knowing if my servers are still in sync.
If I change the pooling to custom schedule, will they be pooled on the same time?

Using the condition object for the first time, I've noticed it behaves differently than a DCI. Would it not be better to make it closer to a DCI? It retains the "Data tab" where one set the different DCI's to be used, the "script tab" should allow calculate any type of  value, a "Thresholds tab" where triggers can be set. This will also allow to have historical result with "last value" and the ability to draw graphs (in my case the max deviation of the time on the severs)

Regards,

Dan

Victor Kirhenshtein

Hi!

Condition uses last collected value of DCIs - checking condition does not cause DCI poll. You can switch to custom schedule - if you will have schedule like * * * * *, you DCI will be collected at the beginning of each minute. Scheduler check DCI schedules once per 2 second, so you will not be able to achieve better than 2 second accuracy.

Converting conditions to something similar to nodes with DCIs makes sense. I'll think about it.

Also, I thought about another way of checking server time sync: you can collect server's system time once per minute and compare it with monitoring server's time. To check that monitoring server's time is accurate, you can check ntp status on monitoring server. That way should be easier probably while still accurate.

Best regards,
Victor

DanG

Hi Victor,

I set the schedule to * * * * * and up to now receive derivation of a second. Having a two second tolerance is more than acceptable in my case.
Your other solution is indeed even better, it's just that while searching for a solution to the problem at hand I learned an interesting NetXMS feature that will without a doubt serve me in the future. Thanks!

Regards,

Dan

DanG

Hi,

I thought I could avoid examining the log file by adding a a custom attribute on the Condition object and set is within the script

The following line:
SetCustomAttribute($node,"MaxTimeDeviation",maxDeviation);
returns the following error:
Failed to execute evaluation script for condition object 1234 "TimeDeviation": Error 14 in line 13: Left argument of -> must be a reference to object

Using the following test line gives the same error:
SetCustomAttribute($node,"MaxTimeDeviation","test");

What am I doing wrong?

Regards,

Dan

Victor Kirhenshtein

Hi!

Variable $node is unset in condition scripts, because it's not a node. Currently it's not possible to access condition's custom attributes from script. I'll add some method to access them.

Best regards,
Victor