Search code examples
powershellwmiwql

PowerShell WQL from different sources performance


Have the following WQL Queries, which work well.

$avg = Get-WmiObject win32_processor -computername $computername | 
               Measure-Object -property LoadPercentage -Average | 
               Foreach {$_.Average}

$tcat = Get-WmiObject Win32_PerfFormattedData_PerfProc_Process -computername $computername |
               Where-Object {$_.Name -like "*tomcat*"} |
               Sort-Object PercentProcessorTime -Descending |
               select -First 1

$mem = Get-WmiObject win32_operatingsystem -ComputerName $computername |
               Foreach {"{0:N2}" -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize)}

been logging the results of these to a SQL database for over a week.

Server list

The first one has "overall" CPU usage of 70% and a process CPU of 98%. Does this mean 98% percent of the 70% usage or 98% of the system CPU?

It is a bit confusing to me.


Solution

  • Your Process_CPU column is populated by data from the "Percent Processor Time" field of WMI. What "Percent Processor Time" measures is the amount of time that the processor spends on a non-idle thread (technically it counts the amount of time that the thread is idle, then subtracts that as a percentage from 100).

    Since you're measuring Tomcat, I imagine you're measuring this on a webserver. This is saying that 98% of the time, Tomcat is running in a non-idle capacity (meaning it's doing something like processing a request or serving the website).

    To more specifically answer your question, rather than your PROCESS_CPU column measuring 98% of 70%, it's measuring a >0% usage 98% of the time.