Hi,
Can some one help me with powercli script to get ESXTOP parameter and values in CSV format from all ES'Xi host in vCenter.
Thanks in advance.
Need for below parameters
1) CPU load average
2) %RDY
3) %CSTP
4)%USED
Thanks in advance.
You could use the Get-Stat cmdlet to do that. Below is a script that will make an average of the last 5 records (in 20 seconds intervals) as grabbing only the last record might be misleading I believe.
Although the %USED and average Usage metrics will pretty much give the same thing so you may have to tinker with the averages.
$AverageSize = 5
$Table = foreach ($VM in (Get-VM | where powerstate -eq poweredon)) {
$USAGE = (get-stat -Entity $VM -Stat cpu.usage.average -Realtime| where {!$_.instance}|select -last $AverageSize | Measure-Object -Property value -Average).average
$RDY = (get-stat -Entity $VM -Stat cpu.ready.summation -Realtime| where {!$_.instance}|select -last $AverageSize | Measure-Object -Property value -Average).average/200
$CSTP = (get-stat -Entity $VM -Stat cpu.costop.summation -Realtime| where {!$_.instance}|select -last $AverageSize | Measure-Object -Property value -Average).average/200
$USED = (get-stat -Entity $VM -Stat cpu.used.summation -Realtime| where {!$_.instance}|select -last $AverageSize | Measure-Object -Property value -Average).average/200
[pscustomobject]@{
VM = $VM.name
Usage = "$([math]::round($USAGE,2))%"
"%RDY" = $RDY
"%CSTP" = $CSTP
"%USED" = $USED
}
}
$Table | Export-Csv -Path C:\mycsv.csv -NoTypeInformation
Would something like that work for you? Of course you can always adapt it to your needs.
The Get-Stat cmdlet does not return esxtop data, for that you use the Get-EsxTop cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is it enough to connect the vCenter in powercli to run this script ? Or Do I need to have access and connect to esxi host specifically to get this report?
It is yes. Note that I just editted the script to fix a few things.
Also as @LucD pointed out, this script does not use the actual esxtop on the hosts. If you absolutely need to use it for whatever reason it is a job for Get-EsxTop. I'm not too familiar with this cmdlet but I believe Luc wrote a fair bit of really good scripts with it!
Thanks a lot for script.
Let me check with your script first, if I am not getting desired output I will check with LuCD for how to use Get-EsxTop.