-
Basic VMware Cluster Capacity Check with PowerCLI
Posted on January 18th, 2012 8 commentsI recently needed to provide a high level capacity overview per VMware cluster looking at some metrics of interest that were being used as a guide to the capacity state of a cluster. Note: these are by no means definitive or the ones you should be using in your environment, but for these purposes they met the requirements. The metrics I looked at per cluster were the ratio of vCPUs to pCPUs, the amount of Effective, Allocated and average Active Memory and the amount of Free Diskspace.
A couple of things to note:
1.The section below on datastore freespace filters out the local datastore which contains the name of the host.
$VMHost = $Cluster | Get-VMHost | Select-Object -Last 1 $HostName = ($VMHost.name -split ".", 0, "simplematch")[0] $ClusterFreeDiskspaceGB = ($VMHost | Get-Datastore | Where-Object {$_.Name -notmatch $HostName} | Measure-Object -Property FreeSpaceGB -Sum).Sum2. I’ve recently changed the way I create custom objects to output reports with. For a long time I have used the cheat way of Select-Object , partly because of performance and partly because you can’t control the order of properties in New-Object. These are being addressed in PowerShell v3 (see here and here) so I thought it was about time to make the switch. This means for the time being that when working with the output you need to pipe it to Select-Object to control the order of the output, e.g.
Get-Cluster | Get-ClusterCapacityCheck | Select-Object Cluster,ClusterCPUCores,ClusterAllocatedvCPUs,ClustervCPUpCPURatio,ClusterEffectiveMemoryGB,
ClusterAllocatedMemoryGB,ClusterActiveMemoryPercentage,ClusterFreeDiskspaceGB
function Get-ClusterCapacityCheck { <# .SYNOPSIS Retrieves basic capacity info for VMware clusters .DESCRIPTION Retrieves basic capacity info for VMware clusters .PARAMETER ClusterName Name of the computer to test the services for .EXAMPLE PS C:\> Get-ClusterCapacityCheck -ClusterName Cluster01 .EXAMPLE PS C:\> Get-Cluster | Get-ClusterCapacityCheck .NOTES Author: Jonathan Medd Date: 18/01/2012 #> [CmdletBinding()] param( [Parameter(Position=0,Mandatory=$true,HelpMessage="Name of the cluster to test", ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$true)] [System.String] $ClusterName ) begin { $Finish = (Get-Date -Hour 0 -Minute 0 -Second 0) $Start = $Finish.AddDays(-1).AddSeconds(1) New-VIProperty -Name FreeSpaceGB -ObjectType Datastore -Value { param($ds) [Math]::Round($ds.FreeSpaceMb/1KB,0) } -Force } process { $Cluster = Get-Cluster $ClusterName $ClusterCPUCores = $Cluster.ExtensionData.Summary.NumCpuCores $ClusterEffectiveMemoryGB = [math]::round(($Cluster.ExtensionData.Summary.EffectiveMemory / 1KB),0) $ClusterVMs = $Cluster | Get-VM $ClusterAllocatedvCPUs = ($ClusterVMs | Measure-Object -Property NumCPu -Sum).Sum $ClusterAllocatedMemoryGB = [math]::round(($ClusterVMs | Measure-Object -Property MemoryMB -Sum).Sum / 1KB) $ClustervCPUpCPURatio = [math]::round($ClusterAllocatedvCPUs / $ClusterCPUCores,2) $ClusterActiveMemoryPercentage = [math]::round(($Cluster | Get-Stat -Stat mem.usage.average -Start $Start -Finish $Finish | Measure-Object -Property Value -Average).Average,0) $VMHost = $Cluster | Get-VMHost | Select-Object -Last 1 $ClusterFreeDiskspaceGB = ($VMHost | Get-Datastore | Where-Object {$_.Extensiondata.Summary.MultipleHostAccess -eq $True} | Measure-Object -Property FreeSpaceGB -Sum).Sum New-Object -TypeName PSObject -Property @{ Cluster = $Cluster.Name ClusterCPUCores = $ClusterCPUCores ClusterAllocatedvCPUs = $ClusterAllocatedvCPUs ClustervCPUpCPURatio = $ClustervCPUpCPURatio ClusterEffectiveMemoryGB = $ClusterEffectiveMemoryGB ClusterAllocatedMemoryGB = $ClusterAllocatedMemoryGB ClusterActiveMemoryPercentage = $ClusterActiveMemoryPercentage ClusterFreeDiskspaceGB = $ClusterFreeDiskspaceGB } } }5 responses to “Basic VMware Cluster Capacity Check with PowerCLI”

-
Nice Script Jonathan! I am looking forward to trying it out in our environment. I would like to point out that I have trouble with the hostname being included on local datastores in parts of our environment. While I created a function to update those (I should post this out sometime) it has not been run everywhere yet. As such, I use the following for identifying local datastores:
Get-Datastore | Where {$_.Extensiondata.Summary.MultipleHostAccess -eq $False}
So far I have not run into any issues with this.
-
Hi Jonathan,
Great function – it returns some very useful information. I have added this one to my PS profile. You have also inspired me to go back and write a function of my own that would be useful in my day-to-day tasks at the office.
I often write scripts that report on useful information, but I don’t often do full functions that can utilise the pipeline or accept parameters. I think this will be good practise for me.
Cheers,
Sean -
NP. I probably got it from Luc at some point
-
It would be cool if it had CPU MHz Capacity and usage as well. The other metrics are really good to know.
3 Trackbacks / Pingbacks
-
PowerCLI – Fetch Interesting stats or configuration for a list of VMs | Shogan.tech January 19th, 2012 at 20:05
[...] that said, I recently read a great blog post by Jonathan Medd (Basic VMware Cluster Compatibility Check), and after reading it I thought it would be a great idea to create a set of functions that provide [...]
-
[...] Medd – Basic VMware Cluster Capacity Check with PowerCLI I recently needed to provide a high level capacity overview per VMware cluster looking at some [...]
-
Top 5 Blog Posts Of The Week 1/20/12 « vDestination: you're virtually there January 20th, 2012 at 17:33
[...] Medd – Basic VMware Cluster Capacity Check with PowerCLI I recently needed to provide a high level capacity overview per VMware cluster looking at some [...]
Leave a reply
-










Josh Atwell January 18th, 2012 at 18:09