Last active
March 6, 2016 10:03
-
-
Save vMarkusK/fa33875653affb107062 to your computer and use it in GitHub Desktop.
vCheck Plugin to report vSphere VM disks related to Datastores and Max IOPs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Start of Settings | |
# Bronze Limit | |
[int]$B_Limit = "250" | |
# Silber Limit | |
[int]$S_Limit = "1000" | |
# Gold Limit | |
[int]$G_Limit = "-1" | |
# VM IOPS Limits, do not report on any VMs who are defined here | |
$VMTDoNotInclude = "VM01*|VM01*" | |
# End of Settings | |
$VMs = $VM | Where {$_.Name -notmatch $VMTDoNotInclude} | where {$_.PowerState -eq "PoweredOn" -and ($_ | Get-HardDisk).count -gt 0} | |
$metrics = "virtualDisk.numberReadAveraged.average","virtualDisk.numberWriteAveraged.average" | |
$start = (Get-Date).AddMinutes(-10080) | |
$stats = Get-Stat -Stat $metrics -Entity $vms -Start $start | |
$hdTab = @{} | |
foreach($hd in (Get-Harddisk -VM $vms)){ | |
$controllerKey = $hd.Extensiondata.ControllerKey | |
$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('[') | |
} | |
$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]] | |
} | |
} | |
$report = @() | |
foreach ($Vm in $Vms) { | |
$VmHdds = Get-HardDisk -VM $Vm | select Name, ExtensionData, Filename, CapacityKB | |
foreach ($VmHdd in $VmHdds) { | |
$row = "" | select VmName, ScsiID, Datastore, Tier, CapacityGB, CurrentIOLimit, PlannedIOLimit, IOLimitCorrect, MaxIOPS, HitPlannedIOLimit | |
$row.VmName = $Vm.Name | |
$row.ScsiID = $([string]$VmHdd.extensiondata.controllerkey).substring(3,1) +":"+ $([string]$VmHdd.extensiondata.unitnumber) | |
$row.Datastore = $($VmHdd.Filename.TrimStart("[")).split("]")[0] | |
$row.Tier = $row.Datastore.Split("-")[3] | |
switch ($row.Tier) { | |
"S" {$row.PlannedIOLimit = $S_Limit} | |
"B" {$row.PlannedIOLimit = $B_Limit} | |
"G" {$row.PlannedIOLimit = $G_Limit} | |
default {$row.PlannedIOLimit = "Invalid DS name or tier identifier"} | |
} | |
$row.CapacityGB = [Math]::round(($VmHdd.capacitykb / 1024 / 1024),2) | |
$row.CurrentIOlimit = $VmHdd.ExtensionData.StorageIOAllocation.limit | |
if ($row.CurrentIOLimit -eq -1 -and $row.PlannedIOLimit -ne -1) {$row.IOLimitCorrect = "No IO Limit Set"} | |
elseif ($row.CurrentIOLimit -gt $row.PlannedIOLimit) {$row.IOLimitCorrect = "Too High"} | |
elseif ($row.CurrentIOLimit -lt $row.PlannedIOLimit) {$row.IOLimitCorrect = "Too Low"} | |
else {$row.IOLimitCorrect = "Just Right"} | |
$row.MaxIOPS = ($reportPerf | where {$_.VM -eq $row.VmName -and $_.Disk -eq "scsi" + $row.ScsiID}).IOPSMax | |
if ($row.MaxIOPS -ge $row.PlannedIOLimit -and $row.PlannedIOLimit -ne "-1" ) {$row.HitPlannedIOLimit = "YES"} | |
else {$row.HitPlannedIOLimit = "NO"} | |
$report += $row | |
} | |
} | |
$VMsHit = @() | |
$VMsHit = ($Report | where {$_.HitPlannedIOLimit -eq "YES"}).VmName | |
$reportHIT = @() | |
foreach ($VMHit in $VMsHit) { | |
$reportHIT += $report | where {$_.VmName -like $VMHit} | |
} | |
$reportHIT | |
$Title = "VM IOPs Limit Analytics and Config" | |
$Header = "VM IOPs Limit Hits: $(@($VMsHit).Count)" | |
$Comments = "The following VMs have issues with the planned IO Limit." | |
$Display = "Table" | |
$Author = "Markus Kraus" | |
$PluginVersion = 1.1 | |
$PluginCategory = "vSphere" | |
$TableFormat = @{"HitPlannedIOLimit" = @(@{ "-eq 'YES'" = "Row,class|warning"; }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment