VMware Cloud Community
cybercoaster
Contributor
Contributor

Gather cpu.usage.average - formatting output

I am attempting to gather the cpu.usage.average for all of our ESX servers. I do want all the time lines it dumps to produce a good report.

If I execute the following code, it dumps out the one server in a table with date time and % however the dates are only Jan 2011 - Apr 2010

Get-Stat -Entity (Get-VMHost myservername.local) -Stat cpu.usage.average

so far so good.

I then made the code below to get it all our servers. However I need it to list the host name on each line. I would also like to dump this to a .csv - should be simple but I am a noob and going through a lot of docs/web sites. This way can sort it in Excel by hostname.

$vhosts = (get-vmhost)

foreach ($vhost in $vhosts)[

Get-Stat -Entity (Get-VMHost $vhost) -Stat cpu.usage.average

}

I assume these values are for a 24 hr period from all cores/sockets

TIA

0 Kudos
1 Reply
mattboren
Expert
Expert

Hello, cybercoaster-

I updated your code just a bit to get the requested info.  Try:

## get all VMHosts
Get-VMHost | %{
   
$hostTmp = $_
   
## get their stats for the given type, and grab some info
    Get-Stat -Entity $hostTmp -Stat cpu.usage.average | select @{n="VMHost"; e={$hostTmp.Name}},
    MetricId, Timestamp, @{n
="ValueAndUnit"; e={"$($_.Value)$($_.Unit)"}}, Instance
} |
Export-Csv -NoTypeInformation c:\temp\statsInfo.csv

The Export-Csv on the last line exports it to the given .csv file.  And, this seems to default to getting stats for the last one (1) hour.  How does that do for you?

0 Kudos