We have recently been working through a product where knowing and reporting on VM Max Read/Write IOPS was critical. We needed a way to be able to provide reporting on our clients VPSs and vCloud Organisation VMs.
vCOPs is a seriously great monitoring and analytics tool, but it has got a flaw in it’s reporting in that you can’t search, export or manipulate metrics relating to VM IOPS in a useful way. VeeamOne gives you a Top 10 list of IOPS, CloudPhysics has a great card showing DataStore/VM performance…but again, not exportable or granular enough for what we needed.
If you search on Google for IOPS Reporting you will find a number of guys who have created excellent PowerCLI Scripts. Problem I found was that most worked in some cases, but not for what we required. One particular post I came across this Post on the VMware Community Forums gave a quick and dirty script to gather IOPS stats for all VMs. This lead me to the Alpacapowered Blog. So initial credit for the following goes to MKguy…I merely hacked around it to provide us with additional functionality.
Before You Start:
Depending on your Logging Level in vCenter (I have run this against vCenter 5.1 with PowerCLI 5.5) you may not be collecting the stats required to get Read/Write IOPS. To check this run the following in PowerCLI connected to your vCenter
1 |
Get-VM "vmanme" | Get-StatType | ? {$_ -match "datastore.number(Read|Write)Averaged.average" } |
1 2 |
datastore.numberReadAveraged.average datastore.numberWriteAveraged.average |
If you don’t get the output it means your logging level is set to a lower level than is required. Read through this Post to have vCenter logging the required metrics on a granular level. Once thats been done, give vCenter about 30 minutes to collect its 5 minute samples. If you ever want to check individually how many samples you have for a particular VM you can run the following command. It will also show you the Min/Max Count plus the average.
1 |
Get-VM "vmname" | Get-Stat -stat "datastore.numberWriteAveraged.average" | select -expandproperty Value | measure -average -max -minimum -sum |
1 2 3 4 5 |
Count : 107 Average : 27.3364485981308 Sum : 2925 Maximum : 274 Minimum : 13 |
The Script:
I’ve created two versions of the script (one for Single VMs and on for vCloud Org VMs) and as you can see below, I added in a couple niceties to make this more user friendly and easy to trigger for our internal support staff. Idea is that anyone with the right access to vCenter can double-click on the .ps1 script, and with the right details produce a report for either a single VM or a vCloud Organisation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
Add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue $daysback = -30 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 "" $vm_data = read-host "Enter the Org Number -" write-host "" write-host "Gathering IOPS Stats" write-host "" $vms = Get-Folder | where {$_.Name -like "*$vm_data*" } | get-vm | where {$_.PowerState -eq "PoweredOn" } write-host ( "{0,-70}`t{1,8}`t{2,8}`t{3,8}`t{4,8}" -f "VM", "W IOPS avg", "R IOPS avg", "W IOPS max", "R IOPS max" ) ` ; $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); write-host ( "{0,-70}`t{1,8:N2}`t{2,8:N2}`t{3,8:N2}`t{4,8:N2}" -f $_.Name, $wval.average, $rval.average, $wval.maximum, $rval.maximum ) } write-host "" write-host "You can copy the output by selecting the text and copying to NotePad++ or similar: write-host "" read-host "Hit Enter to Exit" |
Script Notes:
Line 1: Adds the PowerCLI Snap-In to be able to call ESXi Commandlets from PowerShell on click of the .ps1
Line 3: Without notes from MKguy, i’m assuming this is telling us to use the last 30 days of stats if they exist.
Line 7: I discovered the -menu flag for Connect-VIServer which lists a 10 list of your most recently connects vCenter or ESXi servers…from there you enter a number to connect (ease of use for helpdesk)
Line 16: Does uses the Get-Folder command to allow us to get all the VMs in a vCloud Org…you can obviously enter in your own preferred search flags here.
Lines 17-22 are the ones I picked up form the Community post which basically takes the command we used above to check for samples metrics and feeds it into a read/write variable which is then displayed in a series of columns as shown below.
Script Output:
Brilliant! IOPS Per vCloud Org VM using PowerCLI and advanced get-stat metrics. vCOPs struggled… cc @nickmarshall9 pic.twitter.com/09Yugk0Hex
— Anthony Spiteri (@anthonyspiteri) February 26, 2014
Executing the .ps1 will open a PowerShell window, Ask you to enter in the vCenter/Host and finally the VM name or vCloud Org Description. If you have a folder with a number of VMs, the script can take a little time going through the math and spit out the values.
From there you can do a select and copy to export the values out for manipulation…I haven’t done a csv export option due to time constraints, however if anyone want to add that to the end of the script, please do and let me know 🙂
Hope this script is useful for some!