Hi,
I want to have a powercli script to capture the avg CPU ready value of my VMs for last 30 days in percentage.
Please help.
Try something like this
$vms = Get-VM
$start = (Get-Date).AddDays(-30 $metric = "cpu.ready.summation"
Get-Stat -Entity $vms -Stat $metric -Start $start | Group-Object -Property {$_.Entity.Name} | %{ New-Object PSObject -Property @{ VM = $_.Values[0] ReadyAvg = [math]::Round(($_.Group | Measure-Object -Property Value -Average | Select -ExpandProperty Average),2) } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Please have a look...
http://www.lucd.info/2011/07/08/powercli-vsphere-statistics-part-5-rollup-types/
Hi LucD,
Thanks a lot for this.
But when I am running the above script for a particular VM, the ready value is showing as 4466.51. Is it in miliseconds? How to get the percentage of this value.
The metric returns, in milliseconds, the amount of time during the interval when the CPU was in a ready state.
To get a percentage, you'll need a small calculation.
$vms = Get-VM
$start = (Get-Date).AddDays(-30) $metric = "cpu.ready.summation" Get-Stat -Entity $vms -Stat $metric -Start $start | Group-Object -Property {$_.Entity.Name} | %{ New-Object PSObject -Property @{ VM = $_.Values[0] ReadyAvg = &{ $interval = $_.Group[0].IntervalSecs * 1000
$value = $_.Group | Measure-Object -Property Value -Average | Select -ExpandProperty Average
"{0:p}" -f ($value/$interval) } } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference