Hi all
Is possible to create script which returns Percentage (or number) of VMs with CPU Ready higher then 5% for specific cluster ?
Thanks
Like this?
$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
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...)
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
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
Something like this?
$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
$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?
In that case, the Where-clause condition has to be changed.
Latency is already expressed in percent.
$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
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 ?
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
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
Like this?
$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