Obtain VMware VM IOPS Statistics from PowerCLI

VMware

If you need to determine the IOPS that are being used of the storage by the Virtual Machines you can run a PowerCLI script to connect to the vCenter and then collect the IOPS statistics. The script collects the read/write average IOPS and the read/write maximum IOPS for each virtual machine, because of this the script may take an couple of hours to run if there are large number of virtual machines.

1. Install VMware PowerCLI

2. Open a PowerCLI Console

Optional Step: You may want to alter the filenamepath variable to somewhere more suitable.

3. Run the “Connect-VIServer” command to connect to your vCenter server, if you have more than one vCenter, run the command multiple times to connect each vcenter server you wish to get the statistics from.

> Connect-VIServer -Server vcenter1.domain.co.uk -Protocol https
> Connect-VIServer -Server vcenter2.domain.co.uk -Protocol https

4. Now run the script, you may be prompted for a username/password if you were not before.

5. Select from the list the vCenter server you wish to collect the statistics from.

6. Wait for the script to complete, and generate the CSV file.The script can be found below, the script is based on Anthony Spiteri’s script that can be found here: http://anthonyspiteri.net/powercli-iops-metrics-vcloud-org-vps-reporting/ i’ve added to it to allow it to log the results to a CSV file to assist in later analysis.

Add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
$daysback = -30 
$filenamepath = "c:\vmIOPS.csv"
write-host "What vCenter Do you want to Connect To? - You may be prompted for a Username and Password"
write-host ""
Connect-VIServer -menu write-host ""
write-host ""
write-host "Gathering list of (powered on) Virtual Machines....."
write-host ""
$vms = Get-Folder | get-vm | where {$_.PowerState -eq "PoweredOn" }
write-host "Detected " $vms.Count " powered on virtual machines."
write-host ""
write-host "Gathering IOPS statistics for each virtual machine from the last 30 days......"
write-host ""
Add-Content $filenamepath “VM,Write IOPS Average,Read IOPS Average,Write IOPS Max, Read IOPS Max”;
$i=0;
$vms | sort | % {
    $wval = (((Get-Stat $_ -stat "datastore.numberWriteAveraged.average" -Start (Get-Date).adddays($daysback) -Finish (Get-Date) ) | select -expandproperty Value) | measure -average -max);
    $rval = (((Get-Stat $_ -stat "datastore.numberReadAveraged.average" -Start (Get-Date).adddays($daysback) -Finish (Get-Date) ) | select -expandproperty Value) | measure -average -max);
    $thisline = $_.Name + "," + $wval.average + "," + $rval.average + "," + $wval.maximum + "," + $rval.maximum;
    Add-Content c:\dropbox\vm.csv $thisline;
    $i++
    write-host $i $_.Name 
}
write-host "" write-host "Completed!"