Find your VM with Top IOPS
How do you indentify VMs that generates the most IOPS? With the vSphere Client?
No, we do it in PowerCLI 😉
I found a very good script from LucD and created a function around.
function Get-VMMaxIO
{
<#
.SYNOPSIS
Get your VMs with max. IOPS
.DESCRIPTION
Get your VMs with max. IOPS (read & write Avg.)
You could work with the parameters vHost,Cluster or DataCenter to determine the ESXi Hosts. (default = all Hosts)
With the parameter minutes, you could change the period of time (default = 1)
With the parameter top, you could change the number of VMs listed (default = 10)
.EXAMPLE
Get-VMMaxIO
Get-VMMaxIO -vHost myHost01
Get-VMMaxIO -Cluster myClusterA
Get-VMMaxIO -DataCenter myDataCenterA
Get-VMMaxIO -vHost * -minutes 10 -top 15
.Sample Output
PS C:\Users\myUser> Get-VMMaxIO -Cluster * -minutes 1 -top 5
VM Datastore IOPSMax
-- --------- -------
myVM01 MyDataStore01 18,75
myVM02 MyDataStore02 6,85
myVM03 MyDataStore01 5,8
myVM09 MyDataStore04 3,4
myVM15 MyDataStore04 3,2
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory=$false, Position=0)]
[System.String]
$vHost = "",
[Parameter(Mandatory=$false, Position=1)]
[System.String]
$Cluster = "",
[Parameter(Mandatory=$false, Position=2)]
[System.String]
$DataCenter = "",
[Parameter(Mandatory=$false, Position=3)]
[System.String]
$top = '10',
[Parameter(Mandatory=$false, Position=4)]
[System.String]
$minutes = '5'
)
#Check which Variable is filled
if([string]::IsNullOrEmpty($vHost)) {
#Write-Host "Given string is NULL or EMPTY"
} else {
#Write-Host "Set vobject"
$vobject = (Get-VMHost $vHost) | Sort-Object -Property Name
}
if([string]::IsNullOrEmpty($Cluster)) {
#Write-Host "Given string is NULL or EMPTY"
} else {
#Write-Host "Set vobject"
$vobject = (Get-Cluster $Cluster| Get-VMHost) | Sort-Object -Property Name
}
if([string]::IsNullOrEmpty($DataCenter)) {
#Write-Host "Given string is NULL or EMPTY"
} else {
#Write-Host "Set vobject"
$vobject = (Get-DataCenter $DataCenter| Get-VMHost) | Sort-Object -Property Parent,Name
}
$metrics = 'disk.numberwrite.summation','disk.numberread.summation'
$start = (Get-Date).AddMinutes(-$minutes)
$report = @()
$vms = ($vobject |Get-VM) | where {$_.PowerState -eq 'PoweredOn'}
$stats = Get-Stat -Realtime -Stat $metrics -Entity $vms -Start $start
$interval = $stats[0].IntervalSecs
$lunTab = @{}
foreach($ds in (Get-Datastore -VM $vms | where {$_.Type -eq 'VMFS'})){
$ds.ExtensionData.Info.Vmfs.Extent | %{
$lunTab[$_.DiskName] = $ds.Name
}
}
$report = $stats | Group-Object -Property {$_.Entity.Name},Instance | %{
New-Object PSObject -Property @{
VM = $_.Values[0]
Disk = $_.Values[1]
IOPSMax = ($_.Group | `
Group-Object -Property Timestamp | `
%{$_.Group[0].Value + $_.Group[1].Value} | `
Measure-Object -Maximum).Maximum / $interval
Datastore = $lunTab[$_.Values[1]]
}
}
$report | Sort-Object IOPSMax -Descending | select VM, Datastore, IOPSMax -First $top
}