{"id":1175,"date":"2013-02-11T10:00:09","date_gmt":"2013-02-11T15:00:09","guid":{"rendered":"http:\/\/enterpriseadmins.org\/blog\/?p=1175"},"modified":"2013-02-10T11:03:32","modified_gmt":"2013-02-10T16:03:32","slug":"general-vsphere-cluster-countsaverages","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/general-vsphere-cluster-countsaverages\/","title":{"rendered":"General vSphere Cluster counts\/averages"},"content":{"rendered":"<p>A year or so ago, I had added some generic sections to Alan Renouf&#8217;s vCheck 5 script, which I was using to report on several environments that I managed.  A few months ago, Alan released a new version of <a href=\"http:\/\/www.virtu-al.net\/vcheck-pluginsheaders\/vcheck\/\">vCheck 6<\/a>.  I decided to re-write a couple of these checks into the new format.  The new version of these checks are much more efficient than my previous versions, so I thought I would share them here.<\/p>\n<p>Both checks make use of a $clusters variable, which can be created using the following line of code:<\/p>\n<pre>\r\n$clusters = Get-Cluster\r\n<\/pre>\n<p>This check will report on the average number of vCPUs per virtual machine and the average number of vCPUs per physical core.<\/p>\n<pre><code class=\"language-powershell\">\r\n$CpuClusterRatio = @()\r\n$Clusters | select Name, ID | %{\r\n\t$thisClusterHost = Get-View -ViewType HostSystem -SearchRoot $_.id -property \"Hardware.CpuInfo.NumCpuCores\" | Select @{Name=\"NumCPU\";Expression={$_.Hardware.CpuInfo.NumCpuCores}} |  Measure-Object -Property NumCPU -sum\r\n\t$thisClusterVM = Get-View -ViewType VirtualMachine -SearchRoot $_.id -property \"Summary.Config\" | Select @{Name=\"NumCPU\";Expression={$_.Summary.Config.NumCPU}} |  Measure-Object -Property NumCPU -sum\r\n\t\r\n\tif ($thisClusterHost.Sum -gt 0) { $thisvCpuPerCore = ([math]::round(( $thisClusterVM.Sum \/ $thisClusterHost.Sum ), 2)) } else { $thisvCpuPerCore = 0 }\r\n\tif ($thisClusterVM.Count -gt 0) { $thisvCpuPerVM = ([math]::round(( $thisClusterVM.Sum \/ $thisClusterVM.Count ), 2)) } else { $thisvCpuPerVM = 0 }\r\n\t\r\n\t$CpuClusterRatio += New-Object psobject -Property @{\r\n\t\tName = $_.Name\r\n\t\tNumHosts = $thisClusterHost.Count\r\n\t\tCores = $thisClusterHost.Sum\r\n\t\tGuests = $thisClusterVM.Count\r\n\t\t\"vCPU Count\" = $thisClusterVM.Sum\r\n\t\t\"vCPU per VM\" = $thisvCpuPerVM\r\n\t\t\"vCPU per Core\" = $thisvCpuPerCore\r\n\t}\r\n}\r\n\r\n$CpuClusterRatio | select Name, NumHosts, Cores, Guests, \"vCPU Count\", \"vCPU per VM\", \"vCPU per Core\" | sort Name\r\n<\/code><\/pre>\n<p>This check will report on the average amount of RAM per virtual machine and the percentage of physical RAM allocated to all virtual machines.<\/p>\n<pre><code class=\"language-powershell\">\r\n$RamClusterRatio = @()\r\n$Clusters | select Name, ID | %{\r\n\t$thisClusterHost = Get-View -ViewType HostSystem -SearchRoot $_.id -property \"Hardware.MemorySize\" | Select @{Name=\"RamSize\";Expression={$_.Hardware.MemorySize\/1GB}} |  Measure-Object -Property RamSize -sum\r\n\t$thisClusterVM = Get-View -ViewType VirtualMachine -SearchRoot $_.id -property \"Summary.Config\" | Select @{Name=\"RamSize\";Expression={$_.Summary.Config.MemorySizeMB \/ 1024}} |  Measure-Object -Property RamSize -sum\r\n\t\r\n\tif ($thisClusterVM.count -gt 0) { $avgRamPerVM = ([math]::round(( $thisClusterVM.Sum \/ $thisClusterVM.Count ), 2)) } else { $avgRamPerVM = 0 }\r\n\tif ($thisClusterHost.sum -gt 0) { $allocatedRam = ([math]::round(( $thisClusterVM.Sum \/ $thisClusterHost.Sum ) * 100, 2)) } else { $allocatedRam = 0 }\r\n\t\r\n\t$RamClusterRatio += New-Object psobject -Property @{\r\n\t\tName = $_.Name\r\n\t\tNumHosts = $thisClusterHost.Count\r\n\t\t\"Cluster RAM (GB)\" = [Math]::Round($thisClusterHost.Sum,0)\r\n\t\tGuests = $thisClusterVM.Count\r\n\t\t\"Guest RAM (GB)\" = [Math]::Round($thisClusterVM.Sum,2)\r\n\t\t\"Avg RAM per VM\" = $avgRamPerVM\r\n\t\t\"Allocated RAM %\" = $allocatedRam\r\n\t}\r\n}\r\n\r\n$RamClusterRatio | select Name, NumHosts, \"Cluster RAM (GB)\", Guests, \"Guest RAM (GB)\", \"Avg RAM per VM\", \"Allocated RAM %\" | sort Name\r\n<\/code><\/pre>\n<p>I hope someone can find a use for either of these scripts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A year or so ago, I had added some generic sections to Alan Renouf&#8217;s vCheck 5 script, which I was using to report on several environments that I managed. A few months ago, Alan released a new version of vCheck &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/general-vsphere-cluster-countsaverages\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-1175","post","type-post","status-publish","format-standard","hentry","category-scripting","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=1175"}],"version-history":[{"count":3,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1175\/revisions"}],"predecessor-version":[{"id":1178,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1175\/revisions\/1178"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=1175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=1175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=1175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}