Hi All,
Can anyone here please assist me with the pwoershell script that can shows which ESXi hosts and its VM is overly provisioned in terms of vCPU which affecting the VM performance or with CPU ready % greater than 5 ?
Thanks
What would you take as a criteria to determine if a VM is vCPU overprovisioned ?
Would cpu.usage.average be a candidate ?
Which thresholds would be taken and over which interval ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I recently created a script to retrieve a statistic and report the peak, 99th and 95th percentile (nearest rank) over a sample period and extract to a CSV file.
By default the script will retrieve data over a sample period of 30 days, however you can specify the sample period as a mandatory parameter ($Days).
One thing to consider when specifying the metric, is the statistical level, interval duration and save for period. For Example, if you decide to retrieve the 'cpu.usage.metric' which is a level 1 statistic this will retrieve date at two hour intervals by default.
Param ([Parameter(Mandatory=$true)] [string] $vCenter, [Parameter(Mandatory=$true)][string] $Output,[string] $Days = "30")
Connect-VIServer $vCenter
$VMs = Get-VM
$Results = ForEach ($VM in $VMs)
{
$Metric = (Get-Stat -Entity $VM -Stat 'cpu.usage.average' -Start (Date).AddDays(-$Days) -Finish (Date) ).Value | Sort -Descending
"" | Select @{N="Name";E={$VM}},
@{N="CPU Usage (Peak)";E={ $MetricRow = ($Metric.Count) - ([Math]::Round($Metric.Count * 1))
[Math]::Round(($Metric[$MetricRow]),2)}},
@{N="CPU Usage (p99)"; E={$MetricRow = ($Metric.Count) - ([Math]::Round($Metric.Count * 0.99))
[Math]::Round(($Metric[$MetricRow]),2)}},
@{N="CPU Usage (p95)";E={$MetricRow = ($Metric.Count) - ([Math]::Round($Metric.Count * 0.95))
[Math]::Round(($Metric[$MetricRow]),2)}}
}
$Results | Export-Csv -Path $Output -NoTypeInformation
Hi Luc,
What about the count total of VMs with CPU ready greater than 10% ?
would that be make more sense ?
I got this script from you long time ago:
$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)
}
}
}
but it doesn't list the ESXi servers where the VMs is residing.
Dean,
Thanks for the reply with the script. Somehow I cannot see the CPU Usage (Peak), CPU Usage (p99), CPU Usage (p95) column values, it's all blank ?
I can only see the first column which is the VM name itself.
Do I need to set / enable certain logging level to get the previous 30 days value ?
You should be able to get the ESXi server that hosts a VM like this
$vms = Get-VM
$start = (Get-Date).AddDays(-1)
$metric = "cpu.ready.summation"
Get-Stat -Entity $vms -Stat $metric -Start $start | Group-Object -Property {$_.Entity.Name} | %{
New-Object PSObject -Property @{
VM = $_.Values[0]
ESX = $_.Group[0].Entity.VMHost.Name
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
Luc,
thanks for the assistance, how can I export the result into CSV file ?
Use the trick with the call operator
$vms = Get-VM
$start = (Get-Date).AddDays(-1)
$metric = "cpu.ready.summation"
&{Get-Stat -Entity $vms -Stat $metric -Start $start | Group-Object -Property {$_.Entity.Name} | %{
New-Object PSObject -Property @{
VM = $_.Values[0]
ESX = $_.Group[0].Entity.VMHost.Name
ReadyAvg = &{
$interval = $_.Group[0].IntervalSecs * 1000
$value = $_.Group | Measure-Object -Property Value -Average | Select -ExpandProperty Average
"{0:p}" -f ($value/$interval)
}
}
}} | Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I would expect values to be retrieved as this is a level 1 metric, if you was to invoke the below agaisnt one of the VMs (replacing $VM) do receive output?
Get-Stat -Entity $VM -Stat 'cpu.usage.average' -Start (Date).AddDays(-30) -Finish (Date)
You should receive output similar to the below sample.
Value Timestamp MetricId Unit Description Entity EntityId IntervalSecs Instance
----- --------- -------- ---- ----------- ------ -------- ------------ --------
5.16 24/10/2014 15:0... cpu.usage.average % CPU usage as a ... vm1 VirtualMachine-... 7200
5.22 24/10/2014 13:0... cpu.usage.average % CPU usage as a ... vm1 VirtualMachine-... 7200
4.29 24/10/2014 11:0... cpu.usage.average % CPU usage as a ... vm1 VirtualMachine-... 7200
2.08 24/10/2014 09:0... cpu.usage.average % CPU usage as a ... vm1 VirtualMachine-... 7200