Multiple VMs performance report in single excel

Our native vSphere client does not allow us to collect performance report of multiple entities in one shot. I wrote the below script which can grab performance report of multiple VMs in a single csv file. We can use the data in csv, draw charts, get a clear view and comparison of resource utilization / performance of multiple VMs.


##################################################################
# Script for collecting performance report of multiple VMs #
##################################################################
$vCenter = Read-Host "Enter the vCenter name wherein the target cluster resides"
$list = Read-Host "Enter path to text file that contains list of VMs to which performance report need to be grabbed"
$sdate = Get-Date (Read-Host "Enter start date of the report(mm/dd/yyyy)")
$fdate = Get-Date (Read-Host "Enter finish date of the report(mm/dd/yyyy)")
$nsamples = Read-Host "How many samples you want to be retrieved in specified interval"
$VMs = Get-Content $list
$stats = @()
Connect-VIServer $vCenter
foreach($VM in $VMs)
{
Write-Host "Collecting data for" $VM "…"
$stats += Get-Stat -Entity $VM -Common -MaxSamples $nsamples -Start $sdate -Finish $fdate
}
$stats | Export-Csv -Path .\PerfResult.csv -Force -NoTypeInformation
Invoke-Item .\PerfResult.csv
Disconnect-VIServer $vCenter -Confirm:$false

You need to supply the data in format according to date setting in local system in which script is being executed (mm/dd/yyyy in my case).

The –Common switch in Get-Stat commandlet retrieves the below metrics by default.
cpu.usage.average
cpu.usagemhz.average
mem.usage.average
disk.usage.average
net.usage.average
sys.uptime.latest
However more mertics can be retrieved using -Stat switch by supplying input in format – “counter group”.”counter name”.”rollup type”, Eg : cpu.usage.min.

The below is the nice pivot chart I got, showing the average CPU usage of two VMs over time (stacked graph).

VM Performance (Stacked graph)

Thanks for reading !

2 thoughts on “Multiple VMs performance report in single excel

Leave a comment