vSphere: Get performance data of a VM by PowerCli

Hi,

with powercli performance data could be exported for automatically created reports.

The command let for such task is Get-Stat

Some examples.

To get the whole list for a VM use

PS D:\> Get-Stat -Entity (Get-vm "MyVM")

This retrieves a list with performance data. By default a value is stored every 20 second.

Filtering is also possible. This gets a list for the last 24 hours.

PS D:\> Get-Stat -Entity (Get-vm "MyVM") -Start ((get-date).AddDays(-1))

Data for a specific time range

PS D:\> Get-Stat -Entity (Get-vm "MyVM") -Start ((get-date).AddDays(-2)) -Finish ((get-date).AddDays(-1)) 

Retrieve only specific metric(s)

cpu.usage.average
cpu.usagemhz.average
disk.usage.average
mem.usage.average
net.usage.average
sys.uptime.latest

CPU time in percent

PS D:\> Get-Stat -Entity (Get-vm "MyVM")  -Stat "cpu.usage.average"

CPU time in percent and Mhz

PS D:\> Get-Stat -Entity (Get-vm "MyVM")  -Stat @("cpu.usage.average","cpu.usagemhz.average")

cpu.usage.average can also have multiple instances, for example for CPU0, CPU1…
It’s possible to get performance data for a specific class, for example CPU times

PS D:\> Get-Stat -Entity (Get-vm "MyVM") -CPU

Available classes

-Cpu
-Disk
-Memory
-Network

The default interval of 20 sec can also be motified. This gets values in 5 minute intervals:

PS D:\> Get-Stat -Entity (Get-vm "MyVM") -IntervalMins 5

The Realtime switch retrieves the data of the last hour

PS D:\> Get-Stat -Entity (Get-vm "MyVM") -Realtime

Export the data to a csv for an import in excel

PS D:\> Get-Stat -Entity (Get-vm "MyVM") -Realtime |Select-Object Entity,Timestamp,Value|Export-Csv -Delimiter ";" -LiteralPath D:\Temp\perfdata.txt

Michael

2 thoughts on “vSphere: Get performance data of a VM by PowerCli”

  1. Running this command [PS D:\> Get-Stat -Entity (Get-vm “MyVM”) -Start ((get-date).AddDays(-1))], but screen still only shows output in 20-second intervals for past hour. Any thoughts why?

Leave a Reply Cancel reply