Lab Automation with PowerCLI Part 2: Gathering Performance Statistics
Ever wondered how to programatically gather performance statistics from an ESXi server? This article aims to explain:
- How to find a list of statistics that are available for gathering
- How to gather the stats to a file for analysis
Previous Article: Getting started
Next Article: Create and Delete Virtual Machines
Notes:
- Complete list of ESXi 5 Statistics / Counters (adfly)
- Sample Script Download (adfly)
- Powershell v2
- PowerCLI v5
- Part 1 (For information on getting PowerCLI installed & configured)
To get started, you can find out what statistics are available by running this script:
Add-PSSnapin "Vmware.VimAutomation.Core"
#Connect to ESXi host, Gather stats & disconnect
Connect-VIServer -Server 10.10.10.100 -User root -Password S0mePsswrd$
Get-VMHost | Get-StatType
Disconnect-VIServer -Server 10.10.10.100 -Force
Note: If you get an error message, comment out the "Add-PSSnapin" line. It only needs to be run once every time you open Powershell ISE
This script generates a Really Long List. For convenience, you can download the complete list here (adfly ad)
Gathering Disk Read/Write statistics
Ok now that you have a HUGE list of statistics, which ones would you want to gather? We find disk statistics helpful, as that is oftentimes the bottleneck in our environment. The following script can be used to gather disk read & write statistics from a single host. With a little creativity, it could be genericized (new word. :) ) and put in a loop to gather constantly:
#Add-PSSnapin "Vmware.VimAutomation.Core"
#Define Statistics gathering directories
$DiskRepath = "c:\diskreadstats.txt"
$DiskWrPath = "c:\diskwritestats.txt"
#Connect to ESXi host, Gather stats & disconnect
$ESXIHost = "10.10.10.100"
Connect-VIServer -Server $ESXIHost -User root -Password Admin!!
Write-Host "Gathering Disk Read Statistics"
Get-Stat -Entity $ESXIHost -Stat disk.read.average | Out-File -FilePath $DiskRePath -Append
Write-Host "Gathering Disk Write Statistics"
Get-Stat -Entity $ESXIHost -Stat disk.write.average | Out-File -FilePath $DiskWrPath -Append
Disconnect-VIServer -Server $ESXIHost -Force
The output looks something like this:
MetricId Timestamp Value Unit
-------- --------- ----- ----
disk.read.average 12/9/2011 10:00:40 PM 0 KBps
disk.read.average 12/9/2011 10:00:20 PM 340 KBps
With Powershell & PowerCLI you can keep a handle on the performance in your virtualized environment. Gathering statistics / counters in an automated way can help you better diagnose & resolve bottlenecks.
Download the scripts from Today's article: Sample Scripts (adfly)
Previous Article: Getting started
Next Article: Create and Delete Virtual Machines