ActiveXperts Network Monitor - Home page
Download ActiveXperts Network Monitor 7.1  (7327 KB - .exe file)
Scripts to monitor Hardware Performance
Baseline Performance Monitoring Determining System Uptime Monitoring Available Disk Space Monitoring Available Memory Monitoring Changes in Service Status Monitoring Changes in Computer Power Status Monitoring Computer Availability Monitoring Disk Bytes Per Second Monitoring Disk Drive Free Space Monitoring Processor Use
Uses cooked performance counters and the SWbemRefresher object to monitor three performance counters on a computer, and save that data to a text file.
Const ForAppending = 8
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.Swbemrefresher")
Set objMemory = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSet
Set objDiskSpace = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfDisk_LogicalDisk").objectSet
Set objQueueLength = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfNet_ServerWorkQueues").objectSet
objRefresher.Refresh
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile _
("c:\scripts\performance.csv", ForAppending, True)
For I = 1 to 10
For each intAvailableBytes in objMemory
objLogFile.Write(intAvailableBytes.AvailableMBytes) & ","
Next
For each intQueueLength in objDiskSpace
objLogFile.Write(intQueueLength.CurrentDiskQueueLength) & ","
Next
For each intServerQueueLength in objQueueLength
objLogFile.Write(intServerQueueLength.QueueLength) & ","
Next
objLogFile.Write VbCrLf
Wscript.Sleep 10000
objRefresher.Refresh
Next
objLogFile.Close
Calculates system uptime; that is, the number of hours a computer has been running since its last restart.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now)
Wscript.Echo dtmSystemUptime
Next
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
& " " & Mid (dtmBootup, 9, 2) & ":" & _
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
13, 2))
End Function
Issues an alert if free disk space for any hard drive on a computer falls below 100 megabytes.
Const LOCAL_HARD_DISK = 3
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredDisks = objWMIService.ExecNotificationQuery _
("Select * from __instancemodificationevent within 30 where " _
& "TargetInstance isa 'Win32_LogicalDisk'")
i = 0
Do While i = 0
Set objDiskChange = colMonitoredDisks.NextEvent
If objDiskChange.TargetInstance.DriveType = LOCAL_HARD_DISK Then
If objDiskChange.TargetInstance.Size < 100000000 Then
Wscript.Echo "Hard disk space is below 100000000 bytes."
End If
End If
Loop
Issues an alert if available memory on a computer falls below 4 megabytes.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set objMemory = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSet
objRefresher.Refresh
Do
For each intAvailableBytes in objMemory
If intAvailableBytes.AvailableMBytes < 4 Then
Wscript.Echo "Available memory has fallen below 4 megabytes."
End If
Next
objRefresher.Refresh
Loop
Temporary event consumer that issues an alert any time a service changes status (for example, an active service that is paused or stopped).
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService. _
ExecNotificationQuery("Select * from __instancemodificationevent " _
& "within 30 where TargetInstance isa 'Win32_Service'")
i = 0
Do While i = 0
Set objService = colServices.NextEvent
If objService.TargetInstance.State <> _
objService.PreviousInstance.State Then
Wscript.Echo objService.TargetInstance.Name _
& " is " & objService.TargetInstance.State _
& ". The service previously was " & _
objService.PreviousInstance.State & "."
End If
Loop
Issues an alert if a computer changes power state (for example, enters or leaves suspend mode).
Set colMonitoredEvents = GetObject("winmgmts:")._
ExecNotificationQuery("Select * from Win32_PowerManagementEvent")
Do
Set strLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo strLatestEvent.EventType
Loop
Uses the Win32_PingStatus class to verify that a computer is accessible over the network.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPingedComputers = objWMIService.ExecQuery _
("Select * from Win32_PingStatus Where Address = '192.168.1.37'")
For each objComputer in colPingedComputers
If objComputer.StatusCode = 0 Then
Wscript.Echo "Remote computer responded."
Else
Wscript.Echo "Remote computer did not respond."
End If
Next
Uses cooked performance counters to monitor disk bytes per second on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colDiskDrives = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfDisk_LogicalDisk").objectSet
objRefresher.Refresh
For i = 1 to 500
For Each objDiskDrive in colDiskDrives
Wscript.Echo "Drive name: " & objDiskDrive.Name
Wscript.Echo "Disk bytes per second: " & objDiskDrive.DiskBytesPerSec
Wscript.Sleep 2000
objRefresher.Refresh
Next
Next
Uses cooked performance counters to retrieve free disk space on a computer.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDiskDrives = objWMIService.ExecQuery _
("Select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk where " _
& "Name <> '_Total'")
For Each objDiskDrive in colDiskDrives
Wscript.Echo "Drive Name: " & objDiskDrive.Name
Wscript.Echo "Free Space: " & objDiskDrive.FreeMegabytes
Next
Uses cooked performance counters to monitor processor use on a computer. Triggers an alert if processor use exceeds 90 percent on 10 successive measurements (measured at 6-second intervals).
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.Swbemrefresher")
Set objProcessor = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfOS_Processor").objectSet
intThresholdViolations = 0
objRefresher.Refresh
Do
For each intProcessorUse in objProcessor
If intProcessorUse.PercentProcessorTime > 90 Then
intThresholdViolations = intThresholdViolations + 1
If intThresholdViolations = 10 Then
intThresholdViolations = 0
Wscript.Echo "Processor usage threshold exceeded."
End If
Else
intThresholdViolations = 0
End If
Next
Wscript.Sleep 6000
objRefresher.Refresh
Loop
|