Gathering virtual machine IOPS statistics by datastore

9 09 2010

Our friendly storage admin sometimes calls me up or sends alert my way from the array when the virtual environment is generating too many IOPS on a particular parity group. From his side, this could be happening on any of a number of LUNs that have been presented to our hosts, and he has no way of telling me what virtual machines could be causing the trouble.

Through the PowerCLI, I’ve scripted a way to check performance across the environment for the heavy hitters and report that info back. The script takes in an array of datastores, a vCenter Server FQDN, and a number of statistical samples to grab. It tracks down the physical hosts of the virtual machines that reside on those datastores and reports back the IOPS done (read & write) for each of those VMs over the interval specified.  The credentials it asks for are a local account on the ESX/ESXi hosts, NOT for vCenter.

Here’s the link for the full source code (feel free to use/steal/augment etc.):

http://dl.dropbox.com/u/8378981/GatherIOPS.ps1

About these ads

Actions

Information

51 responses

24 09 2010
dromeo

Curtis, does this script require ESX 4.x? I need to do what this script does on 3.5

24 09 2010
Curtis

It was written and tested on ESXi 4U1 and vCenter Server 4U1; sorry, but I don’t have a 3.5 environment to test it in. I would think that the actual stats calls will work in the older versions of ESX/ESXi, but I can’t say for sure.

If you do test it out, please let me know the results – time willing, I will gladly make changes (if possible) to get it backwards compatible.

29 09 2010
Jeff

The script does seem to work ok on 3.5 & 4.0. The script does like to throw a bunch of errors at me but it still reports back the desired data. This is the first time I’ve used powershell for anything so I’ll see if I can figure out how to stop it’s complaining.

Thanks for sharing this I has helped me immensely.

30 09 2010
Curtis

You’re welcome Jeff, I’m glad it was helpful. :)

If you figure out what is sending errors I would like to know so that I can improve the script in a future version.

25 10 2010
Jared

I am excited to see your scripts on measuring IOPS and thin storage.
I am getting errors and interesting data. The IOP’s total count is double our SAN capacity when I ran it on all our luns. I am wondering if I missed something in the calculations.

25 10 2010
Curtis

Hi Jared, can you post the input you are using – that might help me figure out where my math is going wrong.

13 12 2010
faheem

i am trying run this script but i am getting the following errors

Connect-VIServer : Cannot validate argument on parameter ‘Server’. The argument is null or empty. Supply an argument th
at is not null or empty and then try the command again.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:44 char:17
+ Connect-VIServer <<<< $server -NotDefault -WarningAction SilentlyContinue | Out-Null
+ CategoryInfo : InvalidData: (:) [Connect-VIServer], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.Commands.ConnectVIServer

Get-Datastore : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is
not null or empty and then try the command again.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:86 char:37
+ $myDatastore = Get-Datastore -Name <<<< $datastore -server $server
+ CategoryInfo : InvalidData: (:) [Get-Datastore], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.Commands.GetDatastore

Get-VM : Cannot validate argument on parameter 'Datastore'. The argument is null or empty. Supply an argument that is n
ot null or empty and then try the command again.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:87 char:29
+ $myVMs = Get-VM -Datastore <<<< $myDatastore -server $server | Where {$_.PowerState -eq "PoweredOn"}
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.Commands.GetVM

Connect-VIServer : Cannot validate argument on parameter 'Server'. The argument is null or empty. Supply an argument th
at is not null or empty and then try the command again.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:58 char:26
+ connect-viserver -server <<<< $vmhost -credential $credentials -NotDefault -WarningAction SilentlyContinue | Out
-Null
+ CategoryInfo : InvalidData: (:) [Connect-VIServer], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.Commands.ConnectVIServer

Get-Datastore : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is
not null or empty and then try the command again.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:61 char:34
+ $myDatastoreID = ((Get-Datastore <<<< $ds -server $vmhost) | Get-View).info.vmfs.extent[0].diskname
+ CategoryInfo : InvalidData: (:) [Get-Datastore], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.Commands.GetDatastore

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not nu
ll or empty and then try the command again.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:64 char:40
+ $rawVMStats = get-stat -entity (get-vm <<<< $vm -server $vmhost) -stat $stat -maxSamples $samples
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.Commands.GetVM

You cannot call a method on a null-valued expression.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:68 char:28
+ if ($stat.instance.Equals <<<< ($myDatastoreID)) {
+ CategoryInfo : InvalidOperation: (Equals:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Attempted to divide by zero.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:78 char:27
+ return [int] ($totalIOPS/ <<<< $samples/20)
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException

Connect-VIServer : Cannot validate argument on parameter 'Server'. The argument is null or empty. Supply an argument th
at is not null or empty and then try the command again.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:58 char:26
+ connect-viserver -server <<<< $vmhost -credential $credentials -NotDefault -WarningAction SilentlyContinue | Out
-Null
+ CategoryInfo : InvalidData: (:) [Connect-VIServer], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.Commands.ConnectVIServer

Get-Datastore : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is
not null or empty and then try the command again.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:61 char:34
+ $myDatastoreID = ((Get-Datastore <<<< $ds -server $vmhost) | Get-View).info.vmfs.extent[0].diskname
+ CategoryInfo : InvalidData: (:) [Get-Datastore], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.Commands.GetDatastore

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not nu
ll or empty and then try the command again.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:64 char:40
+ $rawVMStats = get-stat -entity (get-vm <<<< $vm -server $vmhost) -stat $stat -maxSamples $samples
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.Commands.GetVM

You cannot call a method on a null-valued expression.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:68 char:28
+ if ($stat.instance.Equals <<<< ($myDatastoreID)) {
+ CategoryInfo : InvalidOperation: (Equals:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Attempted to divide by zero.
At C:\Documents and Settings\c-fqureshi\Desktop\Datastore IOPS.ps1:78 char:27
+ return [int] ($totalIOPS/ <<<< $samples/20)
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException

13 12 2010
Curtis

Hi Faheem, hopefully I can help you out. Can you post (or send privately) the parameters you are using when you run the script?

13 12 2010
faheem

when i am running the script it is asking me for the username and password and i am giving ESX host local user, username and password,
and i am not doing any changes in script.
if i need to change some where in script let me know.
i dont have your email address to send privately.

19 01 2011
Chas

under the example where @(“DS01″), is that the friendly name of the datastore that needs to be filled in or the name of the array?

19 01 2011
Chas

nevermind. it’s the friendly name. is there a way to chain multiple datastores so you can report against all VMs in one shot?

19 01 2011
Curtis

Yes, this can adjusted for multiple datastores by just adding more into the array that is fed to the datastore parameter:

GatherIOPS.ps1 -server myvcenterserver.mydns.com -datastores @("DS01", "DS02", "DS03", ... etc.) -numsamples 90

19 01 2011
Chas

So would it be possible to capture IO information against an RDM if it can’t be named? WWN maybe?

19 01 2011
Curtis

It should be possible to use the device ID to identify each storage device and report IOPS that way… I should have some time in a couple of days to look into that as a potential addition to the script.

20 01 2011
Chas

awesome

8 02 2011
Jared

I found where I was going wrong for the most part. the one piece is $numsamples = 90, the rest is now hard coded to our luns, servers etc.

we had a lot of disk que latency and I believe your numbers are close. I was able to work out the rest an use this to scan our grid 3 times a day. Great stuf!! The SAN vendor verified that the disk que may be why it shows high…

18 02 2011
Chas

now that i think about it, is it even possible to get IOPs on RDMs since vcenter is kind of blind to them?

18 02 2011
Curtis

Sorry, I played with this and haven’t gotten it working yet. Been busy with my day job, but am hoping to get back to this problem at some point since we have customers looking to make more use of RDMs.

14 04 2011
Chas

there may be an easier way to do this, but for those interested:
add this to then end of the script to generate a unique filename in case you want to schedule this:

# set variable datetime to use for filename

$datetime = get-date -uformat “%m%d%Y-%H.%M”

# set variable IOPFilename that will combine date/time stamp to filename

$IOPFilename = “IOPSReport”+$datetime+”.csv”

$IOPSReport
$IOPSReport | Export-CSV $IOPFilename -NoType

14 04 2011
Chas

has anyone else had their report generate a VM multiple times?

19 04 2011
Eugene

Would that be because the VM is on multiple datastores?

20 04 2011
Chas

Nope. all are single disk on one datastore. It’ll list it once with IOPs and once without.

20 06 2011
Fabio

I get 0 for every value of IOPS (even if the script correctly detects VM names).. Running ESX 4.1 and VC 4.1

Any hint?

Thank you!!

3 07 2011
Curtis

Hi Fabio,

Sorry for the delay, I’ve been out of the country and off the grid for a couple of weeks. I would be happy to help you get the script working – can you post here the parameters you are using to call the script? Also, are any errors being thrown at the console when the script is run?

– Curtis

6 07 2011
Tobias

Hi There – I am having the same issue as Fabio. “I get 0 for every value of IOPS (even if the script correctly detects VM names).. Running ESX 4.1 and VC 4.1″

I am running – .\GatherIOPS.ps1 -server vmmin-hvcsvr01.lm.lmig.com -datastores @(“Linux_T4_NAS_MDIN01″) -numsamples 90

Console Errors – Cannot index into a null array.
At D:\Working Folders\Scripts\GatherIOPS.ps1:61 char:85
+ $myDatastoreID = ((Get-Datastore $ds -server $vmhost) | Get-View).info.vm
fs.extent[ <<<< 0].diskname
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray

Get-Stat : 7/6/2011 7:52:13 PM Get-Stat The metric counter "disk.numb
erwrite.summation" doesn't exist for entity "vxmid-hsfra001".
At D:\Working Folders\Scripts\GatherIOPS.ps1:64 char:24
+ $rawVMStats = get-stat <<<< -entity (get-vm $vm -server $vmhost) -sta
t $stat -maxSamples $samples
+ CategoryInfo : ResourceUnavailable: (disk.numberwrite.summation
:String) [Get-Stat], VimException
+ FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics
_MetricDoesntExist,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats

You cannot call a method on a null-valued expression.
At D:\Working Folders\Scripts\GatherIOPS.ps1:68 char:28
+ if ($stat.instance.Equals <<<< ($myDatastoreID)) {
+ CategoryInfo : InvalidOperation: (Equals:String) [], RuntimeExc
eption
+ FullyQualifiedErrorId : InvokeMethodOnNull

Cannot index into a null array.
At D:\Working Folders\Scripts\GatherIOPS.ps1:61 char:85
+ $myDatastoreID = ((Get-Datastore $ds -server $vmhost) | Get-View).info.vm
fs.extent[ <<<< 0].diskname
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray

Get-Stat : 7/6/2011 7:52:15 PM Get-Stat The metric counter "disk.numb
erread.summation" doesn't exist for entity "vxmid-hsfra001".
At D:\Working Folders\Scripts\GatherIOPS.ps1:64 char:24
+ $rawVMStats = get-stat <<<< -entity (get-vm $vm -server $vmhost) -sta
t $stat -maxSamples $samples
+ CategoryInfo : ResourceUnavailable: (disk.numberread.summation:
String) [Get-Stat], VimException
+ FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics
_MetricDoesntExist,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats

Any Help would be appreciated.

Thanks,
Tobias

7 07 2011
Curtis

Hi Tobias,

Those errors seem to indicate a problem with the collection of performance statistics on your ESX/ESXi hosts. If you log into the host(s) directly with the vSphere client, can you see the following disk performance counters for the VMs on the datastore “Linux_T4_NAS_MDIN01″?:

disk.numberRead.summation (Read requests)
disk.numberWrite.summation (Write requests)

Also, if you select these counters, do you get back data? I’ll try duplicating the issue in my test environment.

– Curtis

4 08 2011
Kris Boutilier

I had the same issue with ‘cannot index into a null array’. Modifying the line:

# identify device id for datastore
$myDatastoreID = ((Get-Datastore $ds -server $vmhost) | Get-View).Info.Vmfs.Extent[0].diskname

to read:
# identify device id for datastore
Foreach ($Extent in ( get-datastore $ds -server $vmhost | get-view | %{ $_.Info.Vmfs.Extent })){
$myDatastoreID = $($Extent.DiskName)
}

made it function for me. This clearly isn’t optimal code but I don’t really know Powershell.

I notice if I issue “Get-Datastore * -server esx1″ in my environment manually it returns two rows for every lun visible to the server – they are all multipath fibrechannel.

Also, the script can be made trivially more communicative by adding a:

write-host -NoNewline “.”

to the top of GetAvgStat() so you know it’s doing something.

16 11 2011
withanHdammit

Thanks Curtis, great script! Works fine with ESXi 5.0/vCenter 5

16 11 2011
withanHdammit

Updated script to include Datasource name in the output.
Change this:

# Gather current IO snapshot for each VM
$dataArray = @()
foreach ($vm in $myVMs) {
$data = “” | Select “VM”, “Interval (minutes)”, “Avg Write IOPS”, “Avg Read IOPS”
$data.”VM” = $vm.name
$data.”Interval (minutes)” = ($numsamples*20)/60
$data.”Avg Write IOPS” = GetAvgStat -vmhost $vm.host.name -vm $vm.name -ds $datastore -samples $numsamples -stat disk.numberWrite.summation
$data.”Avg Read IOPS” = GetAvgStat -vmhost $vm.host.name -vm $vm.name -ds $datastore -samples $numsamples -stat disk.numberRead.summation
$dataArray += $data

to this:

# Gather current IO snapshot for each VM
$dataArray = @()
foreach ($vm in $myVMs) {
$data = “” | Select “VM”, “Datastore”, “Interval (minutes)”, “Avg Write IOPS”, “Avg Read IOPS”
$data.”VM” = $vm.name
$data.”Datastore” = $myDatastore.name
$data.”Interval (minutes)” = ($numsamples*20)/60
$data.”Avg Write IOPS” = GetAvgStat -vmhost $vm.host.name -vm $vm.name -ds $datastore -samples $numsamples -stat disk.numberWrite.summation
$data.”Avg Read IOPS” = GetAvgStat -vmhost $vm.host.name -vm $vm.name -ds $datastore -samples $numsamples -stat disk.numberRead.summation
$dataArray += $data

This changes it to a list output instead of a table output, not sure why, but the CSV export is still fine. I’ll add code as well to email the csv output if you’re scheduling it.

18 11 2011
Curtis

Thanks for the feedback and addition!

20 11 2011
withanHdammit

Add this to the bottom of the script to automatically email the report:
You’ll need to adjust the smtpserver, from address and to address to reflect your environment.


$file = "IOPSReport.csv"
$smtpServer = "mailserver.mydomain.com"
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($file)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "vCenter@mydomain.com"
$msg.To.Add("youremail@mydomain.com")
$msg.Subject = "IOPS Report"
$msg.Body = "IOPS Report"
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()

5 12 2011
kmaster

Hi Curtis,

Could you please let me know why is that this script is working for only VMFS but not for NFS type datastores…………?

Thanks

25 11 2011
kmaster

Hi Curtis,

I was able to run the script on Vmfs type datastores but getting errors with nfs type datastores.How to resolve this..?

Thanks

28 01 2012
Luke

Any way to get this to run on every datastore you have?

2 04 2013
Omarr

I have updated the script to allow the option of using ‘all’ for the datastore switch will then run the script against all of the datastores in the in target vCenter

<################################################################################
# GatherIOPS v1.2
# by Curtis Salinas
# Modified by O'marr Miller
# http://virtualcurtis.wordpress.com
# October 2010
# April 2013
################################################################################
#
# Given an array of datastore names, a vCenter Server FQDN,
# and a number of samples, this script will return a table
# of the read and write IOPS done by every virtual machine
# on those datastores over the sample interval. This data
# is output to the PowerShell screen and to a csv file
# called "IOPSReport_.csv”.
#
# Example:
# Gather_IOPS.ps1 -server myvcenterserver.mydns.com -datastores @(“DS01″) -numsamples 90
# Gather_IOPS.ps1 -server myvcenterserver.mydns.com -datastores @(“all”) -numsamples 90
# Returns:
# VM Datastore Interval (minutes) Avg Write IOPS Avg Read IOPS
# — ——— —————— ————– ————-
# VM01 DS01 30 9.97194444444444 0.466111111111111
# VM01 DS01 30 3.03222222222222 0.483888888888889
# VM01 DS01 30 8.7625 0.104444444444444
# VM01 DS01 30 6.73638888888889 0.211111111111111
# VM01 DS01 30 15.5652777777778 0.303055555555556
#
#>###############################################################################

param($datastores, $server, $numsamples)

$username = read-host -prompt “Please enter local user account for host access”
read-host -prompt “Please enter password for host account” -assecurestring | convertfrom-securestring | out-file cred.txt
$password = get-content cred.txt | convertto-securestring
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$password

# add VMware PS snapin
if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {
Add-PSSnapin VMware.VimAutomation.Core
}

# connect vCenter server session
Connect-VIServer $server -NotDefault -WarningAction SilentlyContinue | Out-Null

# function to get iops for a vm on a particular host
function GetAvgStat($vmhost,$vm,$ds,$samples,$stat){
# number of samples = x time
# 180 = 60min
# 90 = 30min
# 45 = 15min
# 15 = 5min
# 3 = 1min
# 1 = 20sec (.33 min)

# connect to host
connect-viserver -server $vmhost -credential $credentials -NotDefault -WarningAction SilentlyContinue | Out-Null

# identify device id for datastore
$myDatastoreID = ((Get-Datastore $ds -server $vmhost) | Get-View).info.vmfs.extent[0].diskname

# gather iops generated by vm
$rawVMStats = get-stat -entity (get-vm $vm -server $vmhost) -stat $stat -maxSamples $samples
$results = @()

foreach ($stat in $rawVMStats) {
if ($stat.instance.Equals($myDatastoreID)) {
$results += $stat.Value
}
}

$totalIOPS = 0
foreach ($res in $results) {
$totalIOPS += $res
}

return [int] ($totalIOPS/$samples/20)
}

$IOPSReport = @()
If ($datastores -match “all”)
{
$datastorelist = Get-Datastore
} ELSE {
$datastorelist = $datastores
}

foreach ($datastore in $datastorelist)
{
#$IOPSReport = “”
# Grab datastore and find VMs on that datastore
$myDatastore = Get-Datastore -Name $datastore -server $server
$myVMs = Get-VM -Datastore $myDatastore -server $server | Where {$_.PowerState -eq “PoweredOn”} | Sort Name

# Gather current IO snapshot for each VM
$dataArray = @()
foreach ($vm in $myVMs)
{
$data = “” | Select “VM”,”Datastore”,”Interval (minutes)”, “Avg Write IOPS”, “Avg Read IOPS”
$data.”VM” = $vm.name
$data.”Datastore” = $datastore
$data.”Interval (minutes)” = ($numsamples*20)/60
$data.”Avg Write IOPS” = GetAvgStat -vmhost $vm.host.name -vm $vm.name -ds $datastore -samples $numsamples -stat disk.numberWrite.summation
$data.”Avg Read IOPS” = GetAvgStat -vmhost $vm.host.name -vm $vm.name -ds $datastore -samples $numsamples -stat disk.numberRead.summation
$dataArray += $data
}
# Do something with the array of data
$IOPSReport += $dataArray
$IOPSReport
}
$date = Get-Date -UFormat “%Y-%m-%d-%H%M”
$report = “IOPSReport_”+ $date +”.csv”
$IOPSReport | Export-CSV .\$report -Force -NoType
Invoke-Item $report

11 06 2012
Dimitris

Would be nice to see this working for NFS datastores…

29 11 2012
dapyr3x

I can’t seem to get this to work due to it not having this “Add-PSSnapin VMware.VimAutomation.Core” where should I be running this?

23 01 2013
EMSI

Worst written script I ever seen. Loop in loop with loops in loops. Geez.

For every datastore find all virtual machines and connect to the host of that vm the datastore is on (I have 20+ dattastores and 100+ vms so it’s like 2000 times connect to a host! where I have only 15 hosts…) and then (already 2000 iterations) loop trough all the stats, find if it matches the datastore this iteration is about and remember the results and then iterate over it to sum up values.

And now repeat all above steps twice: for read and write IOPs.
Takes ages to computer. It’s worst than lame!

The loops should be unwinded: connect to every host once, then sum up the stats for every datastore iterating (if needed) on every vm.

22 02 2013
Chris

You should probably write your own then and stop complaining.

18 04 2013
dzak64

Did EMSI re-write the script yet?

11 06 2013
Waelder

Quick and Dirty rewrite, picking up the not so kind comment EMSI.
modified for NFS Storage
removed filter for Datastores

param( $server, $numsamples)

$credentials = Get-Credential

# add VMware PS snapin
if (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {
Add-PSSnapin VMware.VimAutomation.Core
}

# connect vCenter server session
Write-Progress -Activity “Getting Environment” -Status “connecting to vCenter” -CurrentOperation $server -PercentComplete 0
Connect-VIServer $server -NotDefault -WarningAction SilentlyContinue
Write-Progress -Activity “Getting Environment” -Status “get all esxi hosts” -CurrentOperation $server -PercentComplete 1
$vmhosts = Get-VMHost -Server $Server
Write-Progress -Activity “Getting Environment” -Status “get all vms per host” -CurrentOperation $server -PercentComplete 1
$VMs = Get-VM -Server $Server | Where {$_.PowerState -eq “PoweredOn”} |group -Property vmHost
Write-Progress -Activity “Getting Environment” -Status “Environment setup finished” -CurrentOperation $server -PercentComplete 3

# function to get iops for a vm on a particular host
function GetAvgStat($vmhost,$vm,$samples,$stat){
# number of samples = x time
# 180 = 60min
# 90 = 30min
# 45 = 15min
# 15 = 5min
# 3 = 1min
# 1 = 20sec (.33 min)

# gather iops generated by vm
$rawVMStats = get-stat -entity (get-vm $vm -server $vmhost) -stat $stat -maxSamples $samples
$totalIOPS = 0
foreach ($stat in $rawVMStats) {
$totalIOPS += $stat.Value
}

return [int] ($totalIOPS/$samples/20)
}

$IOPSReport = @()
$step = round($vm.count /100)
$Progress = 0

foreach ($esxhost in $VMs) {
#Loop through vms per Host
$Progress += $step
$esxconn = connect-viserver -server $esxhost.name -credential $credentials -NotDefault -WarningAction SilentlyContinue
Write-Progress -Activity “Retrieving Data” -Status “Processing Esx Hosts” -CurrentOperation $esxhost.name -PercentComplete $Progress
# Gather current IO snapshot for each VM
$dataArray = @()
foreach ($vm in $esxhost.group) {
Write-Progress -Activity “Retrieving Performance DataProcessing VM $($vm.name)” -Status “Processing VMs” -CurrentOperation “$($vm.name) on $($esxhost.name) $($esxhost.Count) Guests on Host ” -PercentComplete $Progress
$data = “” | Select “VM”, “Interval (minutes)”, “Avg Write IOPS”, “Avg Read IOPS”
$data.”VM” = $vm.name
$data.”Interval (minutes)” = ($numsamples*20)/60
#$data.”Avg Write IOPS” = GetAvgStat -vmhost $vm.host.name -vm $vm.name -ds $datastore -samples $numsamples -stat disk.numberWrite.summation
#$data.”Avg Read IOPS” = GetAvgStat -vmhost $vm.host.name -vm $vm.name -ds $datastore -samples $numsamples -stat disk.numberRead.summation
$data.”Avg Write IOPS” = GetAvgStat -vmhost $esxconn -vm $vm.name -samples $numsamples -stat virtualdisk.numberwriteaveraged.average
$data.”Avg Read IOPS” = GetAvgStat -vmhost $esxconn -vm $vm.name -samples $numsamples -stat virtualdisk.numberreadaveraged.average
$dataArray += $data
}

# Do something with the array of data
$IOPSReport += $dataArray

}

$IOPSReport
$IOPSReport | Export-CSV IOPSReport.csv -NoType

11 06 2013
Waelder

oh a bug, replace
return [int] ($totalIOPS/$samples/20)
with
return [int] ($totalIOPS/$samples)
if you use .average values

22 07 2013
http://bloopd.co

I think that everything posted was actually very reasonable.
However, what about this? suppose you added a little information?
I am not suggesting your information isn’t solid., however what if you added something that grabbed people’s attention?

I mean Gathering virtual machine IOPS statistics by datastore |
Notes from a Sysadmin is kinda boring. You should look at Yahoo’s home page and see how they create post titles to grab viewers to click. You might add a related video or a picture or two to get people interested about everything’ve written.
In my opinion, it could bring your website a little livelier.

29 07 2013
pit przez internet 2014

Hi there, You have done an incredible job. I will certainly digg it
and personally suggest to my friends. I’m sure they will be benefited from this website.

31 07 2013
program pit 2014

My programmer is trying to persuade me to move to
.net from PHP. I have always disliked the idea because of the expenses.
But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for
about a year and am worried about switching to another platform.
I have heard excellent things about blogengine.net.
Is there a way I can import all my wordpress posts into it?

Any kind of help would be really appreciated!

31 07 2013
Faap.me

Excellent goods from you, man. I’ve remember your stuff previous to and you are simply too great. I really like what you have bought right here, really like what you’re stating and the way by
which you are saying it. You are making it entertaining
and you still care for to keep it wise. I cant wait to read far more from you.
This is really a terrific web site.

3 08 2013
e-deklaracje 2014 gov

of course like your website however you have to test
the spelling on several of your posts. Many
of them are rife with spelling issues and I find it very bothersome
to tell the truth nevertheless I’ll definitely come back again.

7 08 2013
pit d objaśnienia

Hey there just wanted to give you a quick heads up and let you know a few of the
images aren’t loading correctly. I’m not sure why but I think its a linking issue.
I’ve tried it in two different browsers and both show the same results.

8 08 2013
http://Tinyqr.co/2vhwv

you are actually a good webmaster. The web site loading velocity is incredible.
It seems that you are doing any unique trick.
Furthermore, The contents are masterwork. you’ve done a magnificent task on this topic!|

19 09 2013
tom

Cannot get either script to work on 5.0 U2 — keeps saying I am not connected to a server despite putting in correct credentials AND running the script ON the vCenter server…!!
Thank you, Tom

29 07 2014
http://www.google.ca/

I know this site provides quality based posts and other material, is there any other web site which presents
such things in quality?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: