SOLVED

Get count of instances where CPU Utilization is higher than 90% using PS

%3CLINGO-SUB%20id%3D%22lingo-sub-1270677%22%20slang%3D%22en-US%22%3EGet%20count%20of%20instances%20where%20CPU%20Utilization%20was%20higher%20than%2090%25%20using%20PS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1270677%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20trying%20to%20implement%20a%20functionality%20to%20check%20how%20many%20times%20within%20a%20span%20of%203%20minutes%2C%20the%20CPU%20utilization%20was%20higher%20than%2090%25.%20I'm%20sampling%20180%20values%20of%20CPU%20utilization%20in%203%20minutes%2C%201%20per%20second%20using%20the%20following%20command%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%24cpuUtil%20%3D%20(get-counter%20-Counter%20%22%5CProcessor(_Total)%5C%25%20Processor%20Time%22%20-SampleInterval%201%20-MaxSamples%20180%20%7C%20select%20-ExpandProperty%20countersamples%20%7C%20select%20-ExpandProperty%20cookedvalue%20%7C%20Measure-Object%20-Average).average%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20above%20command%20gives%20me%20the%20average.%20How%20can%20I%20get%20a%20count%20of%20occurrences%20from%20this%20where%20sample%20value%20is%20greater%20than%2090%25%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThanks%20in%20advance.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1270677%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Ecpu%20utilization%20powershell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1274002%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20count%20of%20instances%20where%20CPU%20Utilization%20is%20higher%20than%2090%25%20using%20PS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1274002%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F597585%22%20target%3D%22_blank%22%3E%40Niraj875%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eby%20filtering%20the%20values%20like%20this%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%24cpuUtil%20%3D%20(get-counter%20-Counter%20%22%5CProcessor(_Total)%5C%25%20Processor%20Time%22%20-SampleInterval%201%20-MaxSamples%20180%20%7C%20select%20-ExpandProperty%20countersamples%20%7C%20select%20-ExpandProperty%20cookedvalue%20%7CWhere-Object%20-FilterScript%20%7B%20%24_%20-gt%2090%20%7D%20%7C%20Measure-Object).Count%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1284658%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20count%20of%20instances%20where%20CPU%20Utilization%20is%20higher%20than%2090%25%20using%20PS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1284658%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F194946%22%20target%3D%22_blank%22%3E%40Joachim%20Pichl%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hello,

 

I'm trying to implement a functionality to check how many times within a span of 3 minutes, the CPU utilization was higher than 90%. I'm sampling 180 values of CPU utilization in 3 minutes, 1 per second using the following command:

 

$cpuUtil = (get-counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 180 | select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average

 

The above command gives me the average. How can I get a count of occurrences from this where sample value is greater than 90%?

 

Thanks in advance.

2 Replies
Highlighted
Best Response confirmed by Niraj875 (New Contributor)
Solution

Hello @Niraj875 

by filtering the values like this:

$cpuUtil = (get-counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 180 | select -ExpandProperty countersamples | select -ExpandProperty cookedvalue |Where-Object -FilterScript { $_ -gt 90 } | Measure-Object).Count

 

Highlighted