VMware Cloud Community
Pilu1978
Enthusiast
Enthusiast
Jump to solution

CPU Stats

Hi,

I use the below script to find the average cpu performance of the esxi hosts in my environment:

$clu = get-cluster Clustername

$esx = $cluster | Get-VMHost | Where {$_.ConnectionState -eq "Connected"}

$statcpu = Get-Stat -Entity ($esx) -start (get-date).AddDays(-7) -Finish (Get-Date) -MaxSamples 10000 -stat cpu.usage.average

$cpu = $statcpu | Measure-Object -Property value -Average -Maximum

Now from the last line of the code when collecting the average values it is also taking the values which is presented as 0 (zero) for any time interval(s).

So just wanted to know if there is any way we can discard the values which is coming as 0 and then take the average of the remaining values.

Please help.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

A where-clause should do the trick

$clu = get-cluster Clustername
$esx = $cluster | Get-VMHost | Where {$_.ConnectionState -eq "Connected"}
$statcpu = Get-Stat -Entity ($esx) -start (get-date).AddDays(-7) -Finish (Get-Date) -MaxSamples 10000 -stat cpu.usage.average
$cpu = $statcpu | where {$_.Value -ne 0} | Measure-Object -Property value -Average -Maximum


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

A where-clause should do the trick

$clu = get-cluster Clustername
$esx = $cluster | Get-VMHost | Where {$_.ConnectionState -eq "Connected"}
$statcpu = Get-Stat -Entity ($esx) -start (get-date).AddDays(-7) -Finish (Get-Date) -MaxSamples 10000 -stat cpu.usage.average
$cpu = $statcpu | where {$_.Value -ne 0} | Measure-Object -Property value -Average -Maximum


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Pilu1978
Enthusiast
Enthusiast
Jump to solution

Perfect. Thanks.

0 Kudos