VMware Cloud Community
mibiras
Contributor
Contributor
Jump to solution

Percentage of VMs with CPU Ready higher then 5%

Hi all

Is possible to create script which returns Percentage (or number) of VMs with CPU Ready higher then 5% for specific cluster ?

Thanks

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Like this?

$clusterName = 'MyCluster'

$vms = Get-Cluster -Name $clusterName | Get-VM

$vmsHighLatency = Get-Stat -Entity $vms -Stat cpu.latency.average -Realtime -MaxSamples 1 -Instance '' -ErrorAction SilentlyContinue |

where { $_.Value -ge 5 } |

Select @{ N = 'VM'; E = { $_.Entity.Name } }


Write-Host ("{0:p0} VMs with a latency value >= 5%" -f ($vmsHighLatency.Count / $vms.Count))


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

View solution in original post

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this to get the VMs that have at an interval a ready% higher than 5%.

If you want to count them, you should probably say over which interval (1 hour, 1 day...)

Get-Stat -Entity (Get-Cluster -Name MyCluster | Get-VM) -Stat cpu.ready.summation -Start (Get-Date).AddDays(-1) -Instance '' -ErrorAction SilentlyContinue|

where{$_.Value/($_.intervalSecs*10) -ge 5} |

Select @{N='VM';E={$_.Entity.Name}},Timestamp,

   @{N='Ready%';E={"{0:p}" -f ($_.Value/($_.intervalSecs*1000))}}


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

mibiras
Contributor
Contributor
Jump to solution

Thanks LucD,

I need count them just for last sampling interval (5 minutes), what I exactly need is (Number of VMs with CPU ready > 5% / Number of runnig VMs) * 100

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Something like this?

$clusterName = 'MyCluster'

$vms = Get-Cluster -Name $clusterName | Get-VM

$vmsReady = Get-Stat -Entity $vms -Stat cpu.ready.summation -Start (Get-Date).AddMinutes(-5) -Instance '' -ErrorAction SilentlyContinue |

where { $_.Value / ($_.intervalSecs * 10) -ge 1 } |

Select @{ N = 'VM'; E = { $_.Entity.Name } } |

Sort-Object -Unique


Write-Host ("{0:p0} VMs with a ready value >= 5%" -f ($vmsReady.Count / $vms.Count))


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

mibiras
Contributor
Contributor
Jump to solution

$vmsReady.Count is always zero or nothing

And I think better counter for us will be cpu.latency.average, should you also change it in script?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

In that case, the Where-clause condition has to be changed.
Latency is already expressed in percent.

$clusterName = 'MyCluster'

$vms = Get-Cluster -Name $clusterName | Get-VM

$vmsHighLatency = Get-Stat -Entity $vms -Stat cpu.latency.average -Start (Get-Date).AddMinutes(-5) -Instance '' -ErrorAction SilentlyContinue |

where { $_.Value -ge 5 } |

Select @{ N = 'VM'; E = { $_.Entity.Name } } |

Sort-Object -Unique


Write-Host ("{0:p0} VMs with a latency value >= 5%" -f ($vmsHighLatency.Count / $vms.Count))


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

mibiras
Contributor
Contributor
Jump to solution

I think problem should be in

Sort-Object -Unique

I changed script  to:

$vmsReady = Get-Stat -Entity $vms -Stat cpu.latency.average  -Start (Get-Date).AddMinutes(-1) -MaxSamples 1  -Instance '' -ErrorAction SilentlyContinue | where { $_.Value -ge 5 } | Select @{ N = 'VM'; E = { $_.Entity.Name } }

And I think it produces output what I need.

Do you think is to OK ?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, the Unique switch is there to avoid that the same VM is counted multiple times.
For the interval of the last 5 minutes, the Get-Stat will retrieve values at 20-second intervals.

If a VM is above the threshold more than once, it will appear more than once in the $vmsReady variable, and hence the percentage will not be correct.


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

Reply
0 Kudos
mibiras
Contributor
Contributor
Jump to solution

No, the Unique switch is there to avoid that the same VM is counted multiple times.

According this I suggest use switch -MaxSamples 1  in Get-Stat.

I know some samples should not be in same time, but this is OK

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Like this?

$clusterName = 'MyCluster'

$vms = Get-Cluster -Name $clusterName | Get-VM

$vmsHighLatency = Get-Stat -Entity $vms -Stat cpu.latency.average -Realtime -MaxSamples 1 -Instance '' -ErrorAction SilentlyContinue |

where { $_.Value -ge 5 } |

Select @{ N = 'VM'; E = { $_.Entity.Name } }


Write-Host ("{0:p0} VMs with a latency value >= 5%" -f ($vmsHighLatency.Count / $vms.Count))


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

Reply
0 Kudos