{"id":361,"date":"2016-07-25T09:31:03","date_gmt":"2016-07-25T09:31:03","guid":{"rendered":"http:\/\/vblog.hochsticher.de\/?p=361"},"modified":"2016-07-25T17:18:02","modified_gmt":"2016-07-25T17:18:02","slug":"find-your-vm-with-top-iops","status":"publish","type":"post","link":"https:\/\/vblog.hochsticher.de\/?p=361","title":{"rendered":"Find your VM with Top IOPS"},"content":{"rendered":"<p>How do you indentify\u00a0VMs that generates the most IOPS? With the vSphere Client?<\/p>\n<p>No, we do it in PowerCLI \ud83d\ude09<\/p>\n<p><!--more--><\/p>\n<p>I found a very good <a href=\"http:\/\/www.lucd.info\/2011\/04\/22\/get-the-maximum-iops\/\">script<\/a> from <a href=\"http:\/\/www.lucd.info\">LucD<\/a> and created a function around.<\/p>\n<pre class=\"font-size:10 line-height:12 lang:ps decode:true  \">function Get-VMMaxIO\r\n{\r\n  &lt;#\r\n      .SYNOPSIS\r\n      Get your VMs with max. IOPS \r\n      .DESCRIPTION\r\n      Get your VMs with max. IOPS (read &amp; write Avg.)\r\n      You could work with the parameters vHost,Cluster or DataCenter to determine the ESXi Hosts. (default = all Hosts)\r\n      With the parameter minutes, you could change the period of time (default = 1)\r\n      With the parameter top, you could change the number of VMs listed  (default = 10)\r\n      .EXAMPLE\r\n      Get-VMMaxIO\r\n\r\n      Get-VMMaxIO -vHost myHost01\r\n      Get-VMMaxIO -Cluster myClusterA\r\n      Get-VMMaxIO -DataCenter myDataCenterA\r\n\r\n      Get-VMMaxIO -vHost * -minutes 10 -top 15\r\n\r\n      .Sample Output\r\n      PS C:\\Users\\myUser&gt; Get-VMMaxIO -Cluster * -minutes 1 -top 5\r\n\r\n      VM   Datastore         IOPSMax\r\n      --   ---------         -------\r\n      myVM01 MyDataStore01   18,75\r\n      myVM02 MyDataStore02    6,85\r\n      myVM03 MyDataStore01     5,8\r\n      myVM09 MyDataStore04     3,4\r\n      myVM15 MyDataStore04     3,2\r\n      \r\n  #&gt;\r\n  [CmdletBinding()]\r\n  param\r\n  (\r\n   \r\n    [Parameter(Mandatory=$false, Position=0)]\r\n    [System.String]\r\n    $vHost = \"\",\r\n    \r\n    [Parameter(Mandatory=$false, Position=1)]\r\n    [System.String]\r\n    $Cluster = \"\",\r\n    \r\n    [Parameter(Mandatory=$false, Position=2)]\r\n    [System.String]\r\n    $DataCenter = \"\",\r\n  \r\n    [Parameter(Mandatory=$false, Position=3)]\r\n    [System.String]\r\n    $top = '10',\r\n    \r\n    [Parameter(Mandatory=$false, Position=4)]\r\n    [System.String]\r\n    $minutes = '5'\r\n  )\r\n  \r\n  \r\n  #Check which Variable is filled\r\n  if([string]::IsNullOrEmpty($vHost)) {            \r\n    #Write-Host \"Given string is NULL or EMPTY\"\r\n    \r\n  } else {            \r\n    #Write-Host \"Set vobject\" \r\n    $vobject = (Get-VMHost $vHost)  | Sort-Object -Property Name              \r\n  }\r\n  \r\n  if([string]::IsNullOrEmpty($Cluster)) {            \r\n    #Write-Host \"Given string is NULL or EMPTY\"  \r\n  } else {            \r\n    #Write-Host \"Set vobject\" \r\n    $vobject = (Get-Cluster $Cluster| Get-VMHost)  | Sort-Object -Property Name            \r\n  }\r\n  \r\n  if([string]::IsNullOrEmpty($DataCenter)) {            \r\n    #Write-Host \"Given string is NULL or EMPTY\"\r\n    \r\n  } else {            \r\n    #Write-Host \"Set vobject\"\r\n    $vobject = (Get-DataCenter $DataCenter| Get-VMHost)  | Sort-Object -Property Parent,Name              \r\n  }\r\n  \r\n  \r\n  \r\n  \r\n  \r\n  \r\n  $metrics = 'disk.numberwrite.summation','disk.numberread.summation'\r\n  $start = (Get-Date).AddMinutes(-$minutes)\r\n  $report = @()\r\n  \r\n  $vms = ($vobject |Get-VM) | where {$_.PowerState -eq 'PoweredOn'}\r\n  $stats = Get-Stat -Realtime -Stat $metrics -Entity $vms -Start $start\r\n  $interval = $stats[0].IntervalSecs\r\n  \r\n  $lunTab = @{}\r\n  foreach($ds in (Get-Datastore -VM $vms | where {$_.Type -eq 'VMFS'})){\r\n    $ds.ExtensionData.Info.Vmfs.Extent | %{\r\n      $lunTab[$_.DiskName] = $ds.Name\r\n    }\r\n  }\r\n  \r\n  $report = $stats | Group-Object -Property {$_.Entity.Name},Instance | %{\r\n    New-Object PSObject -Property @{\r\n      VM = $_.Values[0]\r\n      Disk = $_.Values[1]\r\n      IOPSMax = ($_.Group | `\r\n        Group-Object -Property Timestamp | `\r\n        %{$_.Group[0].Value + $_.Group[1].Value} | `\r\n      Measure-Object -Maximum).Maximum \/ $interval\r\n      Datastore = $lunTab[$_.Values[1]]\r\n    }\r\n  }\r\n  \r\n  $report | Sort-Object IOPSMax -Descending | select VM, Datastore, IOPSMax -First $top\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How do you indentify\u00a0VMs that generates the most IOPS? With the vSphere Client? No, we do it in PowerCLI \ud83d\ude09<\/p>\n","protected":false},"author":1,"featured_media":363,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[4,5,7],"tags":[],"class_list":["post-361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powercli","category-reports","category-vsphere"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/posts\/361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=361"}],"version-history":[{"count":6,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/posts\/361\/revisions"}],"predecessor-version":[{"id":366,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/posts\/361\/revisions\/366"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=\/wp\/v2\/media\/363"}],"wp:attachment":[{"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vblog.hochsticher.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}