CPU Alert monitoring from DB

To the Ipswitch web site

Ipswitch Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



CPU Alert monitoring from DBExpand / Collapse
Author
Message
Posted 8/22/2008 12:49:28 PM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 10/25/2008 7:51:31 PM
Posts: 26, Visits: 105
Hi All,
For my disks monitoring I currently use the script below (found on this forum) to in fact read the data from the previously polled data for disks and depending on the latest value it would trigger the alert.

I would like to use the same system (polling data from DB) to do my CPU monitoring. However I could not find any information about the DB structure to be able construct the right query.

I tried to look for it in the archive not nothing came up so far.

Has anyone tried to do so for CPU monitoring or would someone know the DB structure well enough?

I would think it is possible and it can be done with disk monitoring...

Thank you

// Get the Open DB connection from the Context NameSpace
var oDb = Context.GetDB;

if (null == oDb) {
Context.SetResult( 1, " Problem creating the DB object");
}
else {
// Variable to hold error message
var oDisplay = "Failure: ";

// Variable to determinate if we encountered an alarm
var bAlarm = false;

// Get the device ID
var nDeviceID = Context.GetProperty("DeviceID");

// Definition of Maximum allowable disk utilization percentage
// Change this value to what you want to alarm at. We use 85%.
var nMaxUtilizationPercentage = 85;

// Retrieve the data for the device
var sSql = "SELECT p.nDeviceID, e.sDescription, d.nUsed_Max, d.nSize FROM PivotStatisticalMonitorTypeToDevice p INNER JOIN StatisticalDiskIdentification e ON p.nPivotStatisticalMonitorTypeToDeviceID = e.nPivotStatisticalMonitorTypeToDeviceID INNER JOIN StatisticalDiskCache d ON e.nStatisticalDiskIdentificationID = d.nStatisticalDiskIdentificationID WHERE p.nDeviceID = " + nDeviceID;
oRs2 = oDb.Execute(sSql);
oRs2.moveFirst();

while ( !oRs2.EOF ) {
var sDescription = oRs2("sDescription");
var nUsed_Max = oRs2("nUsed_Max");
var nSize = oRs2("nSize");
if ( nSize > 0 ) {
var nDiskUsedPercentage = Math.round(nUsed_Max/nSize * 100);

if ( nDiskUsedPercentage >= nMaxUtilizationPercentage ) {
bAlarm = true;
oDisplay += "Disk " + sDescription;
oDisplay += " is ";
oDisplay += nDiskUsedPercentage;
oDisplay += " % full | ";

}
}

oRs2.moveNext();
}

if (bAlarm) {
Context.SetResult( 1, oDisplay);
} else {
Context.SetResult(0, "Ok");
}
}
Post #46483
Posted 8/26/2008 8:33:58 AM
Forum Guru

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru

Group: Forum Members
Last Login: 10/13/2008 7:26:33 AM
Posts: 72, Visits: 178
Hi I have written a test on memory Utilization that would fit better the context. Monitoring CPU Usage like HDD will resolve Actions everytime your CPU is over threshold for 5min. That could create a lot of emails. My Memory check (WUG 11) looks like this:

// Set the result code of the check (0=Success, 1=Error)
Context.SetResult( 0, "No error");

// WUP Database connect
var oDb = Context.GetDB;

if (null == oDb) {
result = false;
err += "WUP DB inaccessible! ";
} else {
Context.LogMessage("DB OK");

// Get DeviceID
var deviceID = Context.GetProperty("DeviceID");

// Get the Percentage (3H average to maximum) for check
var sSql = "SELECT Round(AVG(nUsed_Max),0) / nSize AS Perc FROM StatisticalMemory SM JOIN StatisticalMemoryIdentification SMI ON SM.nStatisticalMemoryIdentificationID = SMI.nStatisticalMemoryIdentificationID JOIN PivotStatisticalMonitorTypeToDevice SMT ON SMI.nPivotStatisticalMonitorTypeToDeviceID = SMT.nPivotStatisticalMonitorTypeToDeviceID WHERE dPollTime > DATEADD(hh,-3,GETDATE()) AND sType = 'RAM' AND nDeviceID = '"+deviceID+"' GROUP BY nSize";
var rs = oDb.Execute(sSql);
var perc = rs("Perc")+0;

Context.LogMessage("Perc: "+perc);

rs.Close();
oDb.Close();
}

// Set result Code
if (perc > 0.9) {
Context.SetResult( 1, "The average utilisation during the last 3 hours was greater than 90%");
} else {
Context.SetResult( 0, "Utilisation Ok");
}


This Check is looking at the average usage on three hours and alerts on. If this case happends there might be something wrong, else there was just a heavy process running that is no error. Here http://www.whatsupgold.com/support/guides.aspx you can find the file you need to understand the db layout look for "schema"

Greetings
Jan
Post #46568
Posted 9/12/2008 8:54:16 PM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 10/25/2008 7:51:31 PM
Posts: 26, Visits: 105
thank you for sharing this script. I will test it out shortly.
Post #46978
Posted 10/22/2008 2:25:25 PM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 10/25/2008 7:51:31 PM
Posts: 26, Visits: 105
For those interested, I take the avg of the CPU of the last historical 30min to see if it has been maxing out.

Thanks for your help!

// Set the result code of the check (0=Success, 1=Error)
Context.SetResult( 0, "No error");

// WUP Database connect
var oDb = Context.GetDB;

if (null == oDb) {
result = false;
err += "WUP DB inaccessible! ";
} else {
Context.LogMessage("DB OK");

// Get DeviceID
var deviceID = Context.GetProperty("DeviceID");

// Get the Percentage (0.5H average to maximum) for check
var sSql = "SELECT nProcessorLoad_Avg AS Perc FROM StatisticalCpu SC JOIN StatisticalCpuIdentification SCI ON SC.nStatisticalCpuIdentificationID = SCI.nStatisticalCpuIdentificationID JOIN PivotStatisticalMonitorTypeToDevice SMT ON SCI.nPivotStatisticalMonitorTypeToDeviceID = SMT.nPivotStatisticalMonitorTypeToDeviceID WHERE dPollTime > DATEADD(mi,-30,GETDATE()) AND nDeviceID = '"+deviceID+"'";

var rs = oDb.Execute(sSql);
var perc = rs("Perc")+0;

Context.LogMessage("Perc: "+perc);

rs.Close();
oDb.Close();
}

// Set result Code
if (perc > 90) {
Context.SetResult( 1, "The average utilisation during the last 0.5 hours was greater than 90%");
} else {
Context.SetResult( 0, "Utilisation Ok");
}
Post #48032
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Dave, Mark Singh, kevin r gillis, Jason Benton, Brandon Felger, Ben Henderson, Tripp Allen, Will Sansbury, Jason Williams, Hush, FTPplanet.com, Hugh Garber, George Dailey, WUP-PM, mmulryan@ipswitch.com, mswimm

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 8:31am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.109. 10 queries. Compression Enabled.