Thursday, July 14, 2016

PowerCLI Use Esxtop to Get Information on the Virtual CPUs of a Virtual Machine

ou can use the Get-EsxTop cmdlet to retrieve real-time data for troubleshooting performance problems.
Verify that you are connected to a server that runs ESX 4.0, vCenter Server 5.0 or later.
1
Get the group to which the virtual machine belongs and save it as a variable.
$group = Get-EsxTop -CounterName SchedGroup | where {$_.VMName -eq $vm.Name}
2
Get the IDs of all virtual CPUs of the virtual machine and store them in an array.
$gr = Get-EsxTop -TopologyInfo -Topology SchedGroup | %{$_.Entries} | where {$_.GroupId -eq $group.GroupID}
$cpuIds = @()
$gr.CpuClient | %{$cpuIds += $_.CPUClientID}
3
Get the CPU statistics for the virtual machine.
$cpuStats = Get-EsxTop -CounterName VCPU | where {$cpuIds -contains $_.VCPUID}
4
Calculate the used and ready for use percentage by using the UsedTimeInUsec and ReadyTimeInUsec stats.
$result = @()
$cpuStats | %{ `
$row = "" | select VCPUID, Used, Ready; `
$row.VCPUID = $_.VCPUID; `
$row.Used = [math]::Round(([double]$_.UsedTimeInUsec/[double]$_.UpTimeInUsec)*100, 2); `
$row.Ready = [math]::Round(([double]$_.ReadyTimeInUsec/[double]$_.UpTimeInUsec)*100, 2);` 
$result += $row
}
5
View the used and ready for use percentage for each virtual CPU of the virtual machine.
$result | Format-TableAutoSize

No comments:

Post a Comment

Thanks for showing interest in tech-jockey.

Content of this blog has been moved to GITHUB

Looking at current trends and to make my content more reachable to people, I am moving all the content of my blog https://tech-jockey.blogsp...