Check you Vmware load

Ever wanted to check the average load of your ESXi servers. Check out this PowerShell PowerCLI script to get average CPU and memory load for your different clusters.

Will give you an output file like this:

HostName ClusterName MemMax MemAvg MemMin CPUMax CPUAvg CPUMin
srv-vm-0001.sirius.local DRS1-Test 72.11 1.96 1.73 29.96 0.25 0
srv-vm-0002.sirius.local DRS1-Test 77.05 60.29 1.14 67.5 11.852 0

# Add in the VI Toolkit goodness
if ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null ){Add-PSsnapin VMware.VimAutomation.Core}

$VCs =@(“vc_server_1″,”vc_server_2”)
$date=Get-Date -format “yyMMd”
$file = “c:\temp\vmware_load_$date.csv”

Function GetVmwareLoad
{
$report = @()
foreach ($VC in $VCs)
{

Connect-VIServer $VC | Out-Null

$allhosts = @()
foreach ($Cluster in Get-Cluster)
{
foreach($vmHost in ($cluster | Get-VMHost))
{
$hoststat = “” | Select HostName, ClusterName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
$hoststat.HostName = $vmHost.name
$hoststat.ClusterName = $Cluster.Name

$statcpu = Get-Stat -Entity ($vmHost)-start (get-date).AddDays(-30) -Finish (Get-Date)-MaxSamples 10000 -stat cpu.usage.average
$statmem = Get-Stat -Entity ($vmHost)-start (get-date).AddDays(-30) -Finish (Get-Date)-MaxSamples 10000 -stat mem.usage.average

$cpu = $statcpu | Measure-Object -Property value -Average -Maximum -Minimum
$mem = $statmem | Measure-Object -Property value -Average -Maximum -Minimum

$hoststat.CPUMax = $cpu.Maximum
$hoststat.CPUAvg = $cpu.Average
$hoststat.CPUMin = $cpu.Minimum
$hoststat.MemMax = $mem.Maximum
$hoststat.MemAvg = $mem.Average
$hoststat.MemMin = $mem.Minimum
$allhosts += $hoststat
}

}
$report += $allhosts |Select HostName, ClusterName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
}
$report
}

########## Main Program ###########

$output=GetVmwareLoad
$output| export-Csv $file -notypeinformation -Delimiter “;”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s