' ASP.NET Applications Performancer Counters
' Author: Neil Franken
' email: neil_franken@yahoo.com
' Description:
' This script collects some performance counters related to a specific ASP Application.
'
' 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.
' BEFORE RUNNING THIS SCRIPT:
' 1) Change the following token <<ASPNETAPPLICATION>> to the name of the ASP.NET Application you wish to profile.
' 2) Change the str Name to something like applicationname_asp i.e. google_asp, sharepoint_asp etc.
' 3) If you use the graph definition please change the name from aspapplications to the name you give the file.
' 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: 18/06/2010
'
strAlarmState = "green"
strTestName = "aspapplication" '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
' 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 Application Check Starts Here
strOutput = strOutput & vbCrLf & "ASP.NET Application Information:" & vbCrLf
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'------------------------------------------------------------------------------------
' YOU NEED TO MODIFY THIS SECTION TO MAKE IT WORK |
'------------------------------------------------------------------------------------
' Change the token <<ASPNETAPPLICATION>> to the application name you want to monitor
' To Check what name your application runs under you can use the peformance monitor
' to add a ASP.NET application performance counter. The applications running on the
' server will be listed under instance names.
'------------------------------------------------------------------------------------
Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_ASPNET_ASPNETApplications Where name ='<<ASPNETAPPLICATION>>'",,48)
'------------------------------------------------------------------------------------
' END OF SECTION YOU NEED TO MODIFY |
'------------------------------------------------------------------------------------
For Each objItem In colItems
ErrorPerSec=objItem.ErrorsTotalPerSec
ReqExecuting= objItem.RequestsExecuting
ReqFailed=objItem.RequestsFailed
ReqNotAuthorized=objItem.RequestsNotAuthorized
ReqNotFound=objItem.RequestsNotFound
ReqPerSeq=objItem.RequestsPerSec
ReqTimedOut=objItem.RequestsTimedOut
Exit For
Next
strOutput = strOutput & CheckValue(ErrorPerSec,"ErrorsPerSecond",100, 300)
strOutput = strOutput & CheckValue(ReqExecuting,"RequestExecuting",100, 300)
strOutput = strOutput & CheckValue(ReqFailed,"RequestFailed",100, 300)
strOutput = strOutput & CheckValue(ReqNotAuthorized,"RequestNotAuthorized",100, 300)
strOutput = strOutput & CheckValue(ReqNotFound,"RequestNotFound",25, 75)
strOutput = strOutput & CheckValue(ReqPerSeq,"RequestPerSecond",300, 600)
strOutput = strOutput & CheckValue(ReqTimedOut,"RequestTimedOut",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