Active Script Performance Monitor context code examples

The following table lists several active script performance monitor code examples that you can use to create useful performance monitors for your devices. To use these examples, select the text of the context and then copy and paste the code into the Script text box of the Add Active Script Performance Monitor dialog.

Note: You may need to remove the copyright information from the cut and paste if it appears when you copy from this help file.



Polling one reference variable and perform arithmetic calculation with it.

/ this script is a jscript that demonstrates how to use a reference variable in a script.
// The reference variable "RVsysUpTime" is an SNMP reference variable defined
// with an OID of and instance of 0.

// Poll reference variable RVsysUpTime

var RVsysUpTime = Context.GetReferenceVariable("RVsysUpTime");

if (RVsysUpTime == null)

// Pass a non zero error code upon failure with an error message.
// The error message will be logged in the Performance Monitor Error Log
// and in the eventviewer.
Context.SetResult(1, "Failed to poll the reference variable.");
// Success, use the polled value to convert sysUpTime in hours.
// sysUpTime is an SNMP timestamp which is in hundredths of seconds:
var sysUpTimeHours = RVsysUpTime / 3600 / 100;

// Save the final value to graph:

Using SNMP "GetNext."

// This scripts walks hrStorageType to find hard disks in the storage table.
// A hard disk as a hrStorageType of "" (hrStorageFixedDisk).
// Then it gets the indexes of the hard disk in that table and for each index, it polls two new
// objects in that table, the storage size and the units of that entry.
// It adds everything up and converts it in Gigabytes.

var hrStorageType ="";

// Create and initialize the snmp object
var oSnmpRqst = new ActiveXObject("CoreAsp.SnmpRqst");
var nDeviceID = Context.GetProperty("DeviceID");
var oResult = oSnmpRqst.Initialize(nDeviceID);

var arrIndexes = new Array(); // array containing the indexes of the disks we found

// walk the column in the table:
var oSnmpResponse = oSnmpRqst.GetNext(hrStorageType);
if (oSnmpResponse.Failed) Context.SetResult(1, oSnmpResponse.GetPayload);
var sOid = String(oSnmpResponse.GetOid);
var sPayload = String(oSnmpResponse.GetPayload);

while (!oSnmpResponse.Failed && sOid < (hrStorageType + ".99999999999"))

if (sPayload == "")
// This storage entry is a disk, add the index to the table.
// the index is the last element of the OID:
var arrOid = sOid.split(".");

oSnmpResponse = oSnmpRqst.GetNext(sOid);
if (oSnmpResponse.Failed) Context.SetResult(1, oSnmpResponse.GetPayload);
sOid = String(oSnmpResponse.GetOid);
sPayload = String(oSnmpResponse.GetPayload);

Context.LogMessage("Found disk indexes: " + arrIndexes.toString());

if (arrIndexes.length == 0) Context.SetResult(1, "No disk found");

// now that we have the indexes of the disks. Poll their utilization and units
var nTotalDiskSize = 0;
for (var i=0; i<arrIndexes.length; i++)

oSnmpResponse = oSnmpRqst.Get("" + arrIndexes[i])
if (oSnmpResponse.Failed) Context.SetResult(1,oSnmpResponse.GetPayload);
nSize = oSnmpResponse.GetPayload;
oSnmpResponse = oSnmpRqst.Get("" + arrIndexes[i])
if (oSnmpResponse.Failed) Context.SetResult(1, oSnmpResponse.GetPayload);
nUnits = oSnmpResponse.GetPayload;

nTotalDiskSize += (nSize * nUnits);


// return the total size in gigabytes.
Context.SetValue(nTotalDiskSize / 1024 / 1024 / 1024); // output in Gigabytes

Polling multiple reference variables.

// This script is a Jscript that will allow you to graph the percentage of restransmitted TCP
//' segments over time on a device.

// For this script, we use two SNMP reference variables:
//' The first Reference variable RVtcpOutSegs is defined with OID and instance 0. It polls the
//' SNMP object tcpOutSegs.0, the total number of tcp segments sent out on the network.

var RVtcpOutSegs = parseInt(Context.GetReferenceVariable("RVtcpOutSegs"));

// The second reference variable RVtcpRetransSegs is defined with OID and instance 0. It polls
// the SNMP object tcpRetransSegs.0, the total number of TCP segments that were retransmitted on the system.

var RVtcpRetransSegs = parseInt(Context.GetReferenceVariable("RVtcpRetransSegs"));

if (isNaN(RVtcpRetransSegs) || isNaN(RVtcpOutSegs))
Context.SetResult(1, "Failed to poll the reference variables.");
// Compute the percentage:
var TCPRetransmittedPercent = 100 * RVtcpRetransSegs / RVtcpOutSegs;

// Set the performance monitor value to graph