-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmax-disk-iops-bandwidth-consumed-percent.ps1
59 lines (45 loc) · 2.91 KB
/
max-disk-iops-bandwidth-consumed-percent.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
$report = @()
$vms = Get-AzVM
foreach ($vm in $vms) {
$vmName = $vm.Name
$resourceGroupName = $vm.ResourceGroupName
$region = $vm.Location
$vmSize = $vm.HardwareProfile.VmSize
$osType = $vm.StorageProfile.ImageReference.Sku + " " + $vm.StorageProfile.ImageReference.Offer
$sizeDetails = Get-AzVMSize -Location $vm.Location | where {$_.Name -eq $vm.HardwareProfile.VmSize}
$cores = $sizeDetails.NumberOfCores
$memory = $sizeDetails.MemoryInMB
$diskType = 'OS'
$diskName = $vm.StorageProfile.OsDisk.Name
$lun = $null
$diskSize = (Get-AzDisk -DiskName $diskName).DiskSizeGB
# ------------------------------------------------
# Uncomment the below to show the OS Disks as well
# ------------------------------------------------
# $report += [pscustomobject]@{ vmName = $vmName; resourceGroupName = $resourceGroupName; region = $region; vmSize = $vmSize; osType = $osType; cores = $cores; memory = $memory; diskType = $diskType; diskSizeGB = $diskSize; lun = $lun; diskName = $diskName; maxIOPSPercent = $null; maxBandwidthPercent = $null}
if ($vm.StorageProfile.DataDisks.Count -gt 0) {
foreach ($dd in $vm.StorageProfile.DataDisks) {
$diskType = 'Data'
$diskName = $dd.Name
$lun = $dd.Lun
$diskSize = (Get-AzDisk -DiskName $diskName).DiskSizeGB
$lunFilter = New-AzMetricFilter -Dimension LUN -Operator eq -Value $dd.Lun
$maxIOPSPerDay = Get-AzMetric -ResourceId $vm.Id -MetricName 'Data Disk IOPS Consumed Percentage' -TimeGrain 1.00:00:00 -AggregationType Maximum -StartTime (Get-Date).adddays(-30) -EndTime (Get-Date) -MetricFilter $lunFilter
$maxBandwidthPerDay = Get-AzMetric -ResourceId $vm.Id -MetricName 'Data Disk Bandwidth Consumed Percentage' -TimeGrain 1.00:00:00 -AggregationType Maximum -StartTime (Get-Date).adddays(-30) -EndTime (Get-Date) -MetricFilter $lunFilter
$maxIOPSPercent = 0.0
$maxBandwidthPercent = 0.0
foreach ($iopsVal in $maxIOPSPerDay.Data) {
if ($iopsVal.Maximum -gt $maxIOPSPercent) {
$maxIOPSPercent = $iopsVal.Maximum
}
}
foreach ($bandwidthVal in $maxBandwidthPerDay.Data) {
if ($bandwidthVal.Maximum -gt $maxBandwidthPercent) {
$maxBandwidthPercent = $bandwidthVal.Maximum
}
}
$report += [pscustomobject]@{ vmName = $vmName; resourceGroupName = $resourceGroupName; region = $region; vmSize = $vmSize; osType = $osType; cores = $cores; memory = $memory; diskType = $diskType; diskSizeGB = $diskSize; lun = $lun; diskName = $diskName; maxIOPSPercent = [int]$maxIOPSPercent; maxBandwidthPercent = [int]$maxBandwidthPercent}
}
}
}
$report | Sort-Object -Property VmName, LUN | ft VmName, LUN, DiskType, DiskName, DiskSizeGB, MaxIOPSPercent, MaxBandwidthPercent