Merge pull request #44 from mycloudrevolution/Get-VMmaxIOPS_v1.1
Get-VMmaxIOPS v1.1
This commit is contained in:
@@ -1,11 +1,30 @@
|
|||||||
function Get-VMmaxIOPS {
|
function Get-VMmaxIOPS {
|
||||||
<#
|
<#
|
||||||
|
.NOTES
|
||||||
.SYNOPSIS
|
===========================================================================
|
||||||
Report VM Disk IOPS of VMs
|
Created by: Markus Kraus
|
||||||
|
Twitter: @VMarkus_K
|
||||||
|
Private Blog: mycloudrevolution.com
|
||||||
|
===========================================================================
|
||||||
|
Changelog:
|
||||||
|
2016.10 ver 1.0 Base Release
|
||||||
|
2016.11 ver 1.1 Added vSphere 6.5 Support, New Counters, More Error Handling
|
||||||
|
===========================================================================
|
||||||
|
External Code Sources:
|
||||||
|
http://www.lucd.info/2011/04/22/get-the-maximum-iops/
|
||||||
|
https://communities.vmware.com/thread/485386
|
||||||
|
===========================================================================
|
||||||
|
Tested Against Environment:
|
||||||
|
vSphere Version: 5.5 U2, 6.5
|
||||||
|
PowerCLI Version: PowerCLI 6.3 R1, 6.5 R1
|
||||||
|
PowerShell Version: 4.0, 5.0
|
||||||
|
OS Version: Windows 8.1, Windows Server 2012 R2
|
||||||
|
===========================================================================
|
||||||
|
Keywords vSphere, ESXi, VM, Storage
|
||||||
|
===========================================================================
|
||||||
|
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This Function will Create a VM Disk IOPS Report
|
This Function will Create a VM Disk IOPS Report
|
||||||
|
|
||||||
.Example
|
.Example
|
||||||
Get-VM TST* | Get-VMmaxIOPS -Minutes 60 | FT -Autosize
|
Get-VM TST* | Get-VMmaxIOPS -Minutes 60 | FT -Autosize
|
||||||
@@ -20,15 +39,6 @@ function Get-VMmaxIOPS {
|
|||||||
.PARAMETER Minutes
|
.PARAMETER Minutes
|
||||||
Specify the Minutes to report (10080 is one Week)
|
Specify the Minutes to report (10080 is one Week)
|
||||||
|
|
||||||
.Notes
|
|
||||||
NAME: Get-VMmaxIOPS.ps1
|
|
||||||
LASTEDIT: 08/23/2016
|
|
||||||
VERSION: 1.1
|
|
||||||
KEYWORDS: VMware, vSphere, ESXi, IOPS
|
|
||||||
|
|
||||||
.Link
|
|
||||||
http://mycloudrevolution.com/
|
|
||||||
|
|
||||||
#Requires PS -Version 4.0
|
#Requires PS -Version 4.0
|
||||||
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
|
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
|
||||||
#>
|
#>
|
||||||
@@ -36,50 +46,69 @@ function Get-VMmaxIOPS {
|
|||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true, ValueFromPipeline=$True, Position=0)]
|
[Parameter(Mandatory=$true, ValueFromPipeline=$True, Position=0)]
|
||||||
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]
|
[ValidateNotNullorEmpty()]
|
||||||
$VMs,
|
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]] $VMs,
|
||||||
[Parameter(Mandatory=$false, Position=1)]
|
[Parameter(Mandatory=$false, Position=1, HelpMessage = "Specify the Minutes to report (10080 is one Week)")]
|
||||||
|
[ValidateNotNullorEmpty()]
|
||||||
[int] $Minutes = 30
|
[int] $Minutes = 30
|
||||||
)
|
)
|
||||||
|
Begin {
|
||||||
|
# none
|
||||||
|
}
|
||||||
Process {
|
Process {
|
||||||
|
if ($_.PowerState -eq "PoweredOn") {
|
||||||
|
#region: Global Definitions
|
||||||
|
[int]$TimeRange = "-" + $Minutes
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region: Global Definitions
|
#region: Creating VM Stats
|
||||||
[int]$TimeRange = "-" + $Minutes
|
Write-Verbose "$(Get-Date -Format G) Create VM Stats..."
|
||||||
#endregion
|
$VMMetrics = "virtualdisk.numberwriteaveraged.average","virtualdisk.numberreadaveraged.average"
|
||||||
|
$Start = (Get-Date).AddMinutes($TimeRange)
|
||||||
|
$stats = Get-Stat -Realtime -Stat $VMMetrics -Entity $VMs -Start $Start -Verbose:$False
|
||||||
|
Write-Verbose "$(Get-Date -Format G) Create VM Stats completed"
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region: Creating Metrics
|
#region: Creating HD-Tab
|
||||||
Write-Debug "Starting to Create Metrics..."
|
Write-Verbose "$(Get-Date -Format G) Create HD Tab..."
|
||||||
$metrics = "virtualDisk.numberReadAveraged.average","virtualDisk.numberWriteAveraged.average"
|
$hdTab = @{}
|
||||||
$start = (Get-Date).AddMinutes($TimeRange)
|
foreach($hd in (Get-Harddisk -VM $VMs)){
|
||||||
$stats = Get-Stat -Stat $metrics -Entity $VMs -Start $start
|
$controllerKey = $hd.Extensiondata.ControllerKey
|
||||||
#endregion
|
$controller = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $controllerKey}
|
||||||
|
$hdTab[$hd.Parent.Name + "/scsi" + $controller.BusNumber + ":" + $hd.Extensiondata.UnitNumber] = $hd.FileName.Split(']')[0].TrimStart('[')
|
||||||
|
}
|
||||||
|
Write-Verbose "$(Get-Date -Format G) Create HD Tab completed"
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region: Creating HD-Tab
|
#region: Creating Reports
|
||||||
Write-Debug "Starting to Create HD-Tab..."
|
Write-Verbose "$(Get-Date -Format G) Create Report..."
|
||||||
$hdTab = @{}
|
$reportPerf = @()
|
||||||
foreach($hd in (Get-Harddisk -VM $VMs)){
|
$reportPerf = $stats | Group-Object -Property {$_.Entity.Name},Instance | %{
|
||||||
$controllerKey = $hd.Extensiondata.ControllerKey
|
New-Object PSObject -Property @{
|
||||||
$controller = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $controllerKey}
|
VM = $_.Values[0]
|
||||||
$hdTab[$hd.Parent.Name + "/scsi" + $controller.BusNumber + ":" + $hd.Extensiondata.UnitNumber] = $hd.FileName.Split(']')[0].TrimStart('[')
|
Disk = $_.Values[1]
|
||||||
}
|
IOPSWriteAvg = [math]::round( ($_.Group | `
|
||||||
#endregion
|
where{$_.MetricId -eq "virtualdisk.numberwriteaveraged.average"} | `
|
||||||
|
Measure-Object -Property Value -Average).Average,2)
|
||||||
|
IOPSReadAvg = [math]::round( ($_.Group | `
|
||||||
|
where{$_.MetricId -eq "virtualdisk.numberreadaveraged.average"} | `
|
||||||
|
Measure-Object -Property Value -Average).Average,2)
|
||||||
|
Datastore = $hdTab[$_.Values[0] + "/"+ $_.Values[1]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Verbose "$(Get-Date -Format G) Create Report completed"
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region: Creating Reports
|
|
||||||
Write-Debug "Starting to Process IOPS Report..."
|
|
||||||
$reportPerf = @()
|
|
||||||
$reportPerf = $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
|
|
||||||
Datastore = $hdTab[$_.Values[0] + "/"+ $_.Values[1]]
|
|
||||||
}
|
}
|
||||||
|
Else {
|
||||||
|
Write-Error "VM $($_.Name) is Powered Off! Processing Skipped"
|
||||||
|
}
|
||||||
|
$reportPerf | Select-Object VM, Disk, Datastore, IOPSWriteAvg, IOPSReadAvg
|
||||||
}
|
}
|
||||||
$reportPerf | Select-Object VM, Disk, Datastore, IOPSMax
|
|
||||||
#endregion
|
End {
|
||||||
|
# none
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user