I'm trying to create a test only monitor that will return the top ten processes on a Windows machine based on CPU utilization. I'm also trying to duplicate this for memory, but that should be trivial once the CPU monitor is created.
The basic WMI script monitor won't work because it requires a single process. The goal is to easily find out which processes might be causing a high CPU alert without needing to connect to a VPN and RDP into the machine. I've already created similar monitors for Linux using Perl, but Windows using VBScript has me stumped.
I've been primarily working with VBScript making a WMI call to win32_performatteddata_perfproc_process to retrieve the Name, IDProcess, and PercentProcessorTime fields. The below code has been my most successful so far, but it isn't without its own problems - Namely that values add up to more than 100%.
Option ExplicitDim objWMIService, objRefresherDim strComputer,strListDim colProcesses,objProcessstrComputer = "."Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set objRefresher = CreateObject("WbemScripting.SWbemRefresher")set colProcesses = objRefresher.AddEnum (objWMIService, "Win32_PerfFormattedData_PerfProc_Process").objectSetobjRefresher.RefreshWScript.Sleep(1000)objRefresher.RefreshstrList = "Name Proc"for each objProcess in colProcesses strList = strList & vbCr & objProcess.Name & " " & objProcess.PercentProcessorTimenextWScript.Echo strList
Obviously this isn't yet setup to return proper data to Solarwinds and is just a prototype for pulling the data. Apparently the WMI Object doesn't return the proper data on the first call so the duplicate Refresh are needed and any less than 1 second sleep can cause 0/Null data to be returned for the PercentProcessorTime.
I've searched high and low, including Nagios and Cacti script repositories for something that will work.
I believe that if I could see the actual code used for the WMI Process monitor that I could get this to work. I'm primarily a perl programmer, so any help on this would be appreciated.