SOLVED

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

Copper 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
best response confirmed by Niraj875 (Copper 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

 

1 best response

Accepted Solutions
best response confirmed by Niraj875 (Copper 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

 

View solution in original post