' ASP.NET Applications Performancer Counters
' Author: Neil Franken
' email: neil_franken@yahoo.com
' Description:
' This script collects some performance counters related to a overall ASP health i.e. the server.
'
' You are welcome to use, modify, mangle and do what you please with this script just please
' keep me in the loop about bugs,updates and or improvements.
'
' IMPORTANT NOTES:
' Before running this script please do the following. Open a command prompt on the SQL server where the script
' runs. Run the following command wmiadap/f.
' Open the services manager screen and restart/start the WMI performance adapter service. This service must be running
' to read the performance counters via the WMI interface.
' KNOWN ISSUE:
' I encountered a problem where the CPU was 64 Bit but the installed OS was 32Bit. This caused the registry read to fail.
' If you have a 32 Bit OS running on a 64 bit system yuo will have to change the script to point to the BBWin\tmp folder
' as the script will attempt to read the value from a registry key that dont exist. Also comment out the ProcessorCheck function.
'
' Version 0.5 Released: 22/06/2010
'
strAlarmState = "green"
strTestName = "aspnethealth" 'this Is the filename i.e. column name in xymon.
strOutput = ""
Const strComputer = "."
Dim objWMIService, colItems, objItem
Dim ErrorPerSec, ReqExecuting, ReqFailed, ReqNotAuthorized, ReqNotFound, ReqPerSeq,ReqTimedOut
Set ws = WScript.CreateObject("WScript.Shell")
ProcessorCheck
If Proc = "x86" Then
' extPath = "c:\"
extPath = ws.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\BBWin\tmppath") 'Registry key that stores the ext script path on 32bit Architecture
' WScript.Echo Proc
Else
' extPath = "c:\"
extPath = ws.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\BBWin\tmppath") 'Registry key that stores the ext script path on 64bit Architecture
' WScript.Echo Proc
End If
extPath = "c:\"
' Usage of the CheckValue,CheckReserveValue Functions:
' CheckValue takes the Performance Counter value,a description which appears on Xymon,the warning value and the Alarm value and does a check for values above the warn and alarm thresholds.
' CheckReverseValue takes the Performance Counter value,a description which appears on Xymon,the warning value and the Alarm value and does a check for values below the warn and alarm thresholds.
'
' ASP.NET Check Starts Here
strOutput = strOutput & vbCrLf & "ASP.NET Application Information:" & vbCrLf
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_ASPNET_ASPNET",,48)
For Each objItem in colItems
AppRestarts =objItem.ApplicationRestarts
AppRunning =objItem.ApplicationsRunning
ReqCurrent =objItem.RequestsCurrent
ReqQueued =objItem.RequestsQueued
Exit For
Next
strOutput = strOutput & CheckValue(AppRestarts,"ApplicationRestarts",1, 5)
strOutput = strOutput & CheckValue(AppRunning,"ApplicationRunning",3, 5)
strOutput = strOutput & CheckValue(ReqQueued,"RequestFailed",50, 150)
strOutput = strOutput & CheckValue(ReqCurrent,"RequestCurrent",100, 300)
' Write the file for BB
WriteFile extPath, strTestName, strAlarmState, strOutput
'===========================================================
' FUNCTIONS and SUBS start here
Sub ProcessorCheck ()
Dim WshShell, WshSysEnv
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Proc = WshSysEnv("PROCESSOR_ARCHITECTURE")
End Sub
' This is used to check the actual value against the warning and alarm.
Function CheckValue(iObjectValue,strObjectDesc,iWarnValue,iAlarmValue)
If iWarnValue > iAlarmValue Then
CheckValue = "&red" & " " & strObjectDesc & ":" & vbTab & "Object is Misconfigured"
If strAlarmState <> "red" Then
strAlarmState = "red"
End If
Else
If CDbl(iObjectValue) > CDbl(iWarnValue) Then
If CDbl(iObjectValue) > CDbl(iAlarmValue) Then
CheckValue = "&red" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbCrLf
SetAlarmStatus "red"
Else
CheckValue = "&yellow" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbCrLf
'CheckValue = "&yellow" & strObjectDesc & vbTab & iObjectValue & vbCrLf
SetAlarmStatus "yellow"
End If
Else
CheckValue = "&green" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbCrLf
'CheckValue = "&green" & strObjectDesc & vbTab & iObjectValue & vbCrLf
End If
End If
End Function
' This is used to check the actual value against the warning and alarm.
' This one the alarm will be a lower value than the warning. (Values Decrease rather than increase)
Function CheckReverseValue(iObjectValue,strObjectDesc,iWarnValue,iAlarmValue)
If CDbl(iWarnValue) < CDbl(iAlarmValue) Then
CheckReverseValue = "&red" & " " & strObjectDesc & ":" & vbTab & "Object is Misconfigured"
If strAlarmState <> "red" Then
strAlarmState = "red"
End If
Else
If CDbl(iObjectValue) < CDbl(iWarnValue) Then
If CDbl(iObjectValue) < CDbl(iAlarmValue) Then
CheckReverseValue = "&red" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbCrLf
SetAlarmStatus "red"
Else
CheckReverseValue = "&yellow" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbCrLf
SetAlarmStatus "yellow"
End If
Else
CheckReverseValue = "&green" & " " & strObjectDesc & ":" & vbTab & iObjectValue & vbCrLf
End If
End If
End Function
' This is called to set the overall alarm status.
Sub SetAlarmStatus(strnewAlarmState)
If strnewAlarmState = "red" Then
strAlarmState = strnewAlarmState
ElseIf strnewAlarmState = "yellow" Then
If strAlarmState <> "red" Then
strAlarmState = strnewAlarmState
End If
End If
End Sub
' This SUB is used for outputting the file to the external's directory in bb
Sub WriteFile(strExtPath, strTestName, strAlarmState, strOutput)
Set fso = CreateObject("Scripting.FileSystemObject")
strOutput = strAlarmState & " " & Date & " " & Time & vbCrLf & vbCrLf & strOutput & vbCrLf
Set f = fso.OpenTextFile(strExtPath & "\" & strTestName , 8 , True)
f.Write strOutput
f.Close
Set fso = Nothing
End Sub