Monitor bandwidth utilization in WUG

Another good Jscript for Whats Up Gold. Customize the nMaxUtilizationPercentage based on your situation.

For instance, the ISP provides my client 10Mbps WAN connection, and my client firewall’s outside interface is 100Mbps. So if I want a alarm to be trigger when the bandwidth utilization higher than 90% (9Mbps), I need to change the nMaxUtilizationPercentage to 9.

Very useful script!!


// Get the Open DB connection from the Context NameSpace

var oDb = Context.GetDB;

if (null == oDb)


   Context.SetResult( 1, ”  Problem creating the DB object”);





// Get the device ID

  var nDeviceID = Context.GetProperty(“DeviceID”);


// Definition  of Maximum allowable Interface utilization percentage

//   Change this value to what you want to alarm at.

  var nMaxUtilizationPercentage = 9;



// Retrieve the nPivotStatisticalMonitorTypeToDeviceID for Interface (Monitor Type=1), Refer to dboStatisticalMonitorType for ComponentType

  var sSql = “SELECT nPivotStatisticalMonitorTypeToDeviceID from PivotStatisticalMonitorTypeToDevice WHERE  nStatisticalMonitorTypeID=1 and nDeviceID = ” + nDeviceID;

  var oRs = oDb.Execute(sSql);

  var nPivotStatisticalMonitorTypeToDeviceID = oRs(“nPivotStatisticalMonitorTypeToDeviceID”);


// Retrieve the data for the device

  var sSql2 = “SELECT nStatisticalInterfaceIdentificationID AS StatisticalInterfaceIdentificationID, nIfIndex AS  OIDinstance, sIfDescr AS IfName FROM StatisticalInterfaceIdentification WHERE nPivotStatisticalMonitorTypeToDeviceID = “+nPivotStatisticalMonitorTypeToDeviceID;

  oRs2 = oDb.Execute(sSql2);



  var nExceed = 0;

  var oDisplay=”High Interface Usage at\n\n “;


  while ( !oRs2.EOF )



    var IfMonID = oRs2(“StatisticalInterfaceIdentificationID”);

    var IfName = oRs2(“IfName”);


    var sSql3 = “SELECT nIfInOctets_Avg AS nInOctetsAvg, nIfOutOctets_Avg AS nOutOctetsAvg, nIfSpeedIn AS nIfSpeedInBps, nIfSpeedOut AS nIfSpeedOutBps FROM StatisticalInterfaceCache WHERE nStatisticalInterfaceIdentificationID = ” +IfMonID;

    var oRs3 = oDb.Execute(sSql3);

    if (!oRs3.EOF ) {


       var nIfSpeedIn = oRs3(“nIfSpeedInBps”);

       var nIfSpeedOut = oRs3(“nIfSpeedOutBps”);

       var nIfIn_Avg = oRs3(“nInOctetsAvg”);

       var nIfOut_Avg = oRs3(“nOutOctetsAvg”);


       if ( nIfSpeedIn > 0 )


         var nInPercentage = Math.round((nIfIn_Avg / nIfSpeedIn * 800),2);

         var nOutPercentage = Math.round((nIfOut_Avg / nIfSpeedOut * 800),2);




         var nInPercentage = 0;

         var nOutPercentage = 0;



       if ( nInPercentage > nMaxUtilizationPercentage || nOutPercentage > nMaxUtilizationPercentage)


               nExceed += 1; 

               oDisplay += “InterfaceName=” + IfName + ” is running at “+ nInPercentage + “% (In) /  ” + nOutPercentage + “%(Out). \n\n”;








  oDb.Close(); //Close database connection

  if ( nExceed > 0)


    Context.SetResult( 1, oDisplay);




    Context.SetResult(0, ”     Ok”);




2 thoughts on “Monitor bandwidth utilization in WUG

  1. Hey Jackie,

    Great script. Are you using this as an active monitor? Have you played around with the performance monitors and alert center? I think you might be able to accomplish the same result without the need for the script. Either way, it is a great script and a useful one too. Thanks for sharing it with the world and showing WhatsUp some love.

    Would you mind sharing it on our community web site as well? We have a section dedicated to scripts called the Script Library.

    1. Hi Jason, Thanks for commenting.

      Yes, I use it as an active monitor. And I also use performance monitors and alert center, but I did not see a place to do such thing. If I remember correctly, I get the script from the community library 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s