Tranform and Condition Scripts

Started by jdlds, August 10, 2007, 04:44:06 AM

Previous topic - Next topic

jdlds

Hi Guys,

I was wondering if anyone could share a non-trivial script for the DCI transform or the condition.
Based on the formal declaration of NXSL i can only get basic expressions and function calls to work.  If i define a function or use any if, switch statements the script seems to not function.

I imagine that i must be doing something wrong but any help would be appreciated.

For example in the condition script i'm trying to do something like:

if ($1>5) return min($2, $3);

Another issue i've encountered is using the PDH.countervalue for data collection.  This seems to work fine for some counters but not others.

I tried: '\Memory\Committed Bytes' and this seems to work just fine
but when i tried
'\PhysicalDisk(_Total)\Disk Write Bytes/sec' this always returns 0.

if anyone can shed some light on this, that would great.

-mike

Victor Kirhenshtein

Hello!

If you write non-trivial scripts (i.e. something more than single expression like $1/1024) you should define main() function. So you script should looks like this:

sub main()
{
   if ($1>5) return min($2, $3);
}

btw, you should return something also in case  when $1>5 is false, so final form will be

sub main()
{
   if ($1>5)
      return min($2, $3);
   return 0; // Or any other default value
}

Best regars,
Victor

Victor Kirhenshtein

Quote from: jdlds on August 10, 2007, 04:44:06 AM

Another issue i've encountered is using the PDH.countervalue for data collection.  This seems to work fine for some counters but not others.

I tried: '\Memory\Committed Bytes' and this seems to work just fine
but when i tried
'\PhysicalDisk(_Total)\Disk Write Bytes/sec' this always returns 0.

if anyone can shed some light on this, that would great.


Some counters (like physical disk counter you mention or CPU utilization counters) requires at least two samples to be taken to calculate value. Such counters should be polled in background by agent. To configure agent to do so, use Counter parameter in WinPerf section, like below:

*WinPerf
Counter = DiskWriteBytes:"\PhysicalDisk(_Total)\Disk Write Bytes/sec":60:A:INT:Average number of bytes per second written to disk for last minute

There are several fields separated by colons (:). First is the name for new parameter (DiskWriteBytes in our example); second is counter path; third is number of samples to calculate average value - minimum is 2, and in our example it's 60 (because we need average value for last minute); fourth field is a collection class - it can be either A (collect values every second), B (collect values every 5 seconds), or C (collect values every 30 seconds); fifth field is a data type - it's only a hint for "select parameter" dialog in console and is not used by agent; and sixth field is a parameter description which will be shown in parameter selection dialog.

After you define your new counter, you can access new parameter on agent by using name specified in the first field.

Best regards,
Victor

Anth0ny

Is it possible to use other multi-sample counters (like "\PhysicalDisk(_Total)\Disk Write Bytes/sec") via interface, not via client's config?

Victor Kirhenshtein

Yes, you can use extended form of PDH.CounterValue:

PDH.CounterValue("counter name",1)

If second argument is present in PDH.CounterValue and set to non-zero, then agent will get two samples with 1 second interval, and use them to calculate resulting value.