-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-IOPS.ps1
59 lines (50 loc) · 1.6 KB
/
Get-IOPS.ps1
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function Get-IOPS
{
[CmdletBinding()]
param
(
[Parameter( Mandatory = $True)]
$Session,
[Parameter( Mandatory = $True)]
[int] $Samples,
[Parameter( Mandatory = $True)]
[string] $DatastoreName,
[Parameter( Mandatory = $True)]
[string] $Metric
)
begin
{
Import-Module VMware.VimAutomation.Core -WarningAction SilentlyContinue | Out-Null
}
process
{
$VIServer = $Session.Name
Write-Verbose "$VIServer -- connecting to VIServer"
Connect-VIServer -Server $VIServer -Session $Session.SessionId | Out-Null
$Datastore = Get-Datastore -Name $DatastoreName -Server $VIServer
$DatastoreId = ($Datastore | Get-View).info.vmfs.extent[0].diskname
$VMHost = Get-VMHost -Name $VIServer -Server $VIServer
$RawStats = Get-Stat -Entity $VMHost -Stat $Metric -MaxSamples $Samples -Realtime
#return $RawStats
## Collect the read or write values
$Results = @()
foreach ($Stat in $RawStats)
{
## Check to see if the $Stat comes from the correct DS,
## then add the value to our collection.
if ($Stat.instance.Equals($DatastoreId))
{
$Results += $Stat.Value
}
}
## Add all the values together
$TotalIOPS = 0
foreach ($Result in $Results)
{
$TotalIOPS += $Result
}
## Calculate the average IOPS
[int]$AverageIOPS = ($TotalIOPS / $Samples / 20)
Write-Output $AverageIOPS
}
}