An Alert When the Disk Utilization Reaches a Certain Point

To the Ipswitch web site

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



An Alert When the Disk Utilization Reaches a Certain PointExpand / Collapse
Author
Message
Posted 8/5/2008 7:48:12 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 8/12/2008 11:56:49 AM
Posts: 5, Visits: 3
Hi - can we get alerts sent to us when a server's disk utilization reaches a certain point? Say 90%.

Thank you,

sartz

Post #45961
Posted 8/6/2008 6:53:57 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 2 days ago @ 7:05:03 AM
Posts: 15, Visits: 21
Hi,

You didn't mention what OS you were monitoring, but I assume Windows. I created an ActiveMonitor myself for Windows servers that queries the WMI counter LogicalDisk \ % Free Space and checks for a range of values between 10 - 100. When it drops below 10% free an alert is generated.

The only downside with this is that you need to create a new Active Monitor for each drive, as the above counter will only monitor one instance and each drive (letter) has it's own instance. I suspect there may be better ways of doing it, but this works fine for me.

Hope this helps.

Cheers,
Steve
Post #45971
Posted 8/6/2008 9:02:17 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 8/6/2008 10:40:35 AM
Posts: 3, Visits: 9
I just implemented this one I found here. It works great and allows you to define thresholds setting an attribute on the device.  The only thing missing is that the alert text doesn't include the disk information. This works in v12.

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' This script is a merge of 2 scripts. Credits go to :
' - XXXXX's , which use the performance monitors values to test the disk space, and most code for this script.
' - YYYYYY's, which retrieve the thresholds from a specified attribute
' I added the feature that, if the given attribute is not set, you can use a default value for all disks.
' Also, specifying a threshold of 0 disables the check on that disk.  You must always specify the unit (%, G or M), even when disabling the check.
' Format for the thresholds are something like this : 'C:\=10%;D:\=5G;E:\=650M;G:\=0%'
' THE DRIVE NAME IN THE ATTRIBUTE MUST BE THE SAME AS THE ONE RETURNED BY THE DISK PERF MONITOR. (e.g. for Windows : C:\, D:\, and so on...)
' You can see see the name of each drive by using the Test button and scanning the result.
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' Name of the attribute which will contain the specific thresholds
THRESHOLDS_ATTRIBUTE = "Disk_Space_Thresholds"

' Name of the attribute which will contain the result of the check. Automatically created.
RESULT_ATTRIBUTE = "Disk_Space_Results"

' If the threshold attribute is not found, should the monitor report as DOWN ?
' If set to False, it will use the default value for all disks.
DOWN_NO_ATTRIBUTE = true

' If there are no recent performance entries for at least one device, should the monitor report as DOWN ?  - NOT IMPLEMENTED
DOWN_ON_AGED_VALUES = true

' MAX_AGE value specify the maximum age for entries, in seconds - NOT IMPLEMENTED
MAX_ENTRIES_AGE = 3600

' Default value to be used, in percentage. We monitor the FREE SPACE, which must not go below the threshold.
' 1- when the attribute doesn't specify the threshold for a given disk
' 2- for all disks if there is no attribute AND DOWN_NO_ATTRIBUTE = True
' If set to 0, not specified disks will not be checked.
DEFAULT_THRESHOLD = 10

' Unit of default threshold - THIS IS NOT A DEFAULT UNIT FOR SPECIFIED THRESHOLDS
' "%" = percentage
' "G" = gigabyte
' "M" = megabyte
DEFAULT_THRESHOLD_UNIT = "%"

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


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

' Retrieve DB object

Set oDb = Context.GetDB

If IsNull(oDb) Then
 Context.SetResult 1, "Could not create DB object"
Else

 ' Fetch deviceID
 nDeviceID = Context.GetProperty ("DeviceID")

 ' Get the attribute which contains the specific value.
 sqlGetDS = "select sValue from DeviceAttribute where (nDeviceID = " & nDeviceID & ") and (sName = '" & THRESHOLDS_ATTRIBUTE & "')"
 Set oRs1 = oDb.Execute(sqlGetDS)

 ' We report a DOWN if no attribute and script is configured as such.
 If DOWN_NO_ATTRIBUTE and oRs1.EOF Then
  Context.SetResult 1, "This monitor needs a attribute named " & THRESHOLDS_ATTRIBUTE & " to work."
 Else
  drvMonitors = null
  If Not oRs1.EOF Then
   oRs1.moveFirst
   drvMonitors = split(oRs1("sValue"),";")
  End If
  
  ' SQL request. We ask SQL to compute the value we want itself : it return the remaining percentage, megabytes and gigabytes on each disk.
  sSql = "SELECT     SDI.sDescription, SD.dPollTime, D.sDisplayName, (1 - SD.nUsed_Avg / SD.nSize) * 100 AS perc, (SD.nSize - SD.nUsed_Avg) / 1073741824 AS giga, (SD.nSize - SD.nUsed_Avg) / 1048576 AS mega FROM Device AS D INNER  JOIN PivotStatisticalMonitorTypeToDevice AS PSM ON PSM.nDeviceID = D.nDeviceID INNER  JOIN StatisticalDiskIdentification AS SDI ON SDI.nPivotStatisticalMonitorTypeToDeviceID = PSM.nPivotStatisticalMonitorTypeToDeviceID INNER  JOIN StatisticalDisk AS SD ON SD.nStatisticalDiskIdentificationID = SDI.nStatisticalDiskIdentificationID WHERE D.nDeviceID = '" & nDeviceID & "' AND SD.dPollTime = (SELECT top 1 SD.dPollTime FROM Device AS D INNER  JOIN PivotStatisticalMonitorTypeToDevice AS PSM ON PSM.nDeviceID = D.nDeviceID INNER  JOIN StatisticalDiskIdentification AS SDI ON SDI.nPivotStatisticalMonitorTypeToDeviceID = PSM.nPivotStatisticalMonitorTypeToDeviceID INNER  JOIN StatisticalDisk AS SD ON SD.nStatisticalDiskIdentificationID = SDI.nStatisticalDiskIdentificationID WHERE D.nDeviceID = '" & nDeviceID & "' ORDER BY SD.dPollTime DESC) ORDER BY SDI.sDescription"

  Set oRs2 = oDb.Execute(sSql)
  oRs2.moveFirst

  While Not oRs2.EOF
  
   ' First we check if the last polled value is a recent one, if that check is enabled
   ' TODO
   
   displayName = oRs2("sDisplayName")
   description = ucase(oRs2("sDescription"))
   
   'Default value
   drvMonitorLimit = DEFAULT_THRESHOLD
   drvMonitorUnit = DEFAULT_THRESHOLD_UNIT
   
   ' We retrieve the threshold from the attribute, if it exists.
   If Not IsNull(drvMonitors) Then
    For each drvMonitor in drvMonitors
     'Is it a matching threshold ?
     tokens = split(drvMonitor, "=")
     If tokens(0) = description Then
      ' We then retrieve the threshold value AND the unit. The unit MUST be specified.
      ' Correct format is "100M", "10%", "4G" for example.
      drvMonitorUnit = ucase(Right(tokens(1),1))
      drvMonitorLimit = int(Left(tokens(1),len(tokens(1))-1))
      Exit For
     End If
    Next
   End If

   Select Case drvMonitorUnit
    Case "%"
     value = int(oRs2("perc"))
    Case "G"
     value = int(oRs2("giga"))
    Case "M"
     value = int(oRs2("mega"))
    Case Else
     ' Invalid unit, we will report a Down.
     value = -1
   End Select
   
   ' If unit is invalid, it' a down.
   If value = -1 Then
    bAlarm = true
    oChecksResult = oChecksResult & "Disk " & description & " : threshold unit is invalid (" & drvMonitorUnit & "). You MUST specify %, G or M as a threshold unit (example : C=10%;D=5G;E=650M)" & vbCrLf
   Else
    ' If unit is valid, but threshold is zero, we don't check.
    If drvMonitorLimit = 0 Then
     oChecksResult = oChecksResult & "Disk " & description & " : " & Round(value) & drvMonitorUnit & _
         " remaining space - not checked because threshold is zero." & vbCrLf
    Else
     ' Else we check.
     If value < drvMonitorLimit Then
      bAlarm = true
      oChecksResult = oChecksResult & "Disk " & description & " : " & Round(value) & drvMonitorUnit & _
          " remaining space is below threshold (" & drvMonitorLimit & drvMonitorUnit & ") - DOWN !!" & vbCrLf
     Else
      oChecksResult = oChecksResult & "Disk " & description & " : " & Round(value) & drvMonitorUnit & _
          " remaining space is above threshold (" & drvMonitorLimit & drvMonitorUnit & ") - UP" & vbCrLf
     End If
    End If
   End If
   oRs2.moveNext
  Wend

  ' Store the result in an attribute. Allows to access details even on a Device-configured action by using the  %Device.Attribute.* variable.
  
  ' Formatting it to a SQL compatible format.
  if (Right(oChecksResult,1) = vbCrLf) Then
   oChecksResultSQL = Replace(Left(oChecksResult,len(oChecksResult)-1), vbCrLf, "' + CHAR(10) + N'")
  Else
   oChecksResultSQL = Replace(oChecksResult, vbCrLf, "' + CHAR(10) + N'")
  End If
  
  ' Checking if  the attribute already exists. If not we create one, if yes we simply update it.
  sqlCheck = "SELECT nDeviceAttributeID FROM DeviceAttribute WHERE (nDeviceID = " & nDeviceID & ") AND (sName = N'" & RESULT_ATTRIBUTE & "')"
  Set oRs1 = oDb.Execute(sqlCheck)
  
  ' Storing it in DB as needed.
  If oRs1.EOF Then
   sqlStoreResult = "INSERT INTO DeviceAttribute (nDeviceID, sName, sValue) VALUES (" & _
        nDeviceID & ", N'" & RESULT_ATTRIBUTE & "', N'" & oChecksResultSQL & "')"
  Else
   sqlStoreResult = "UPDATE DeviceAttribute SET sValue = N'" & oChecksResultSQL & _
       "' WHERE (nDeviceID = " & nDeviceID & ") AND (sName = N'" & RESULT_ATTRIBUTE & "')"
  End If
  oDb.Execute(sqlStoreResult)
  
  
  ' Set the result of the monitor.
  If bAlarm Then
   oChecksResult = oChecksResult & vbCrLf & "Monitor is DOWN"
   Context.SetResult 1, oChecksResult
  Else
   oChecksResult = oChecksResult & vbCrLf & "Monitor is UP"
   Context.SetResult 0, oChecksResult
  End If
 End If
End If

' Cleanup code
Set oDb = Nothing
Set oRs2 = Nothing
Set oRs1 = Nothing



-- Nick
Post #45981
Posted 8/6/2008 1:01:12 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 8/12/2008 11:56:49 AM
Posts: 5, Visits: 3
Thanks very much for your help. I'll try to figure this out. If I can't I'll call them.

sartz

Post #46002
Posted 8/6/2008 1:02:27 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 8/12/2008 11:56:49 AM
Posts: 5, Visits: 3
Thanks very much for your help. I don't have much experience in writing scripts. Its all too advanced for me. I'll probably end up calling them.

Thanks again for your effort,

sartz

Post #46003
« 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, Hush, FTPplanet.com, Hugh Garber, George Dailey, WUP-PM, mmulryan@ipswitch.com, mswimm

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 7:31pm

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.078. 7 queries. Compression Enabled.