VMware Cloud Community
ChristianWickha
Contributor
Contributor
Jump to solution

Simple summary of Datacentre performance

I hope someone can help me get a few basic stats. We have two Virtual Centres, one in each of our physical datacentres. The VC datacentres then have two clusters each, one for our production systems and one for our development systems.

At the moment, I manually calculate (with vSphere client) a few stats, and then publish them on our Sharepoint site. They look like this;

Datacentre Name

RAM

Total installed (GB), this does not change - often!

Total allocated (i.e. total Sum of all RAM assigned to VMs)

Total consumed (I do it daily at around 10am, just what it's showing in each host through viClient at that time, added up)

CPU GHz

Total installed (GHz), again not changing much

Total allocated (i.e. total Sum of all vCPUs multiplied by the CPU speed in the hosts)

Total consumed (I do it daily at around 10am, just what it's showing in each host at that time, added up)

And I do this as a summary of all clusters per datacentre, and report this for each datacentre.

Is there a way that I could do this with the Powershell/PowerCLI get-stat ?

Thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I'm not sure if I understood your requirements 100% correctly.

The following script displays 2 report, one per ESX(i) server and one per cluster.

$dcName = <your-datacentername>
$report = @()

$todayMidnight = (Get-Date -Hour 0 -Minute 0 -Second 0).AddMinutes(-1)
$start = $todayMidnight.AddDays(-1)
$clusArr = Get-Datacenter $dcName | Get-Cluster
foreach($clus in $clusArr){
	$esxArr = $clus | Get-VMHost
	foreach($esx in $esxArr){
		$statsEsx = Get-Stat -Entity $esx -Start $start -Finish $todayMidnight `
			-Stat mem.usage.average,cpu.usagemhz.average
		$vms = $esx | Get-VM

		$row = "" | Select Cluster, ESX, RAMInstalled, RAMAllocated, RAMUsed, CPUTotal, CPUAllocated, CPUUsed
		$row.Cluster = $clus.Name
		$row.ESX = $esx.Name
		$row.RAMInstalled = ($esx | Measure-Object -Property MemoryTotalMB -Sum).Sum
		$row.RAMAllocated = ($vms | Measure-Object -Property MemoryMB -Sum).Sum
		$row.RAMUsed = ($statsEsx | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property Value -Average).Average
		$row.CPUTotal = ($esx | Measure-Object -Property CpuTotalMhz -Sum).Sum
		$row.CPUAllocated = ($vms | Measure-Object -Property NumCpu -Sum).Sum * $esx.CpuTotalMhz / $esx.NumCPU
		$row.CPUUsed = ($statsEsx | where {$_.MetricId -eq "cpu.usagemhz.average"} | Measure-Object -Property Value -Average).Average
		$report += $row
	}
}
# Report per ESX
Write-Host "Report per server" 
$report

# Summary per cluster
$reportClus = @()
$report | Group-Object -Property Cluster | %{
	$row = "" | Select Cluster, RAMInstalled, RAMAllocated, RAMUsed, CPUTotal, CPUAllocated, CPUUsed
	$row.Cluster = $_.Name
	$row.RAMInstalled = ($_.Group | Measure-Object -Property RAMInstalled -Sum).Sum
	$row.RAMAllocated = ($_.Group | Measure-Object -Property RAMAllocated -Sum).Sum
	$row.RAMUsed = ($_.Group | Measure-Object -Property RAMUsed -Sum).Sum
	$row.CPUTotal = ($_.Group | Measure-Object -Property CPUTotal -Sum).Sum
	$row.CPUAllocated = ($_.Group | Measure-Object -Property CPUAllocated -Sum).Sum
	$row.CPUUsed = ($_.Group | Measure-Object -Property CPUUsed -Sum).Sum
	$reportClus += $row
}
Write-Host "Report per cluster" 
$reportClus

The script can be easily changed to run against all datacenters by adding an outer loop that cycles through all the datacenters.

If you want to save the report(s) to a spreadsheet, you easily do this by changing the line where the report is displayed on screen to something liek this

...
$report | Export-Csv "C:\report.csv" -NoTypeInformation
...

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I'm not sure if I understood your requirements 100% correctly.

The following script displays 2 report, one per ESX(i) server and one per cluster.

$dcName = <your-datacentername>
$report = @()

$todayMidnight = (Get-Date -Hour 0 -Minute 0 -Second 0).AddMinutes(-1)
$start = $todayMidnight.AddDays(-1)
$clusArr = Get-Datacenter $dcName | Get-Cluster
foreach($clus in $clusArr){
	$esxArr = $clus | Get-VMHost
	foreach($esx in $esxArr){
		$statsEsx = Get-Stat -Entity $esx -Start $start -Finish $todayMidnight `
			-Stat mem.usage.average,cpu.usagemhz.average
		$vms = $esx | Get-VM

		$row = "" | Select Cluster, ESX, RAMInstalled, RAMAllocated, RAMUsed, CPUTotal, CPUAllocated, CPUUsed
		$row.Cluster = $clus.Name
		$row.ESX = $esx.Name
		$row.RAMInstalled = ($esx | Measure-Object -Property MemoryTotalMB -Sum).Sum
		$row.RAMAllocated = ($vms | Measure-Object -Property MemoryMB -Sum).Sum
		$row.RAMUsed = ($statsEsx | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property Value -Average).Average
		$row.CPUTotal = ($esx | Measure-Object -Property CpuTotalMhz -Sum).Sum
		$row.CPUAllocated = ($vms | Measure-Object -Property NumCpu -Sum).Sum * $esx.CpuTotalMhz / $esx.NumCPU
		$row.CPUUsed = ($statsEsx | where {$_.MetricId -eq "cpu.usagemhz.average"} | Measure-Object -Property Value -Average).Average
		$report += $row
	}
}
# Report per ESX
Write-Host "Report per server" 
$report

# Summary per cluster
$reportClus = @()
$report | Group-Object -Property Cluster | %{
	$row = "" | Select Cluster, RAMInstalled, RAMAllocated, RAMUsed, CPUTotal, CPUAllocated, CPUUsed
	$row.Cluster = $_.Name
	$row.RAMInstalled = ($_.Group | Measure-Object -Property RAMInstalled -Sum).Sum
	$row.RAMAllocated = ($_.Group | Measure-Object -Property RAMAllocated -Sum).Sum
	$row.RAMUsed = ($_.Group | Measure-Object -Property RAMUsed -Sum).Sum
	$row.CPUTotal = ($_.Group | Measure-Object -Property CPUTotal -Sum).Sum
	$row.CPUAllocated = ($_.Group | Measure-Object -Property CPUAllocated -Sum).Sum
	$row.CPUUsed = ($_.Group | Measure-Object -Property CPUUsed -Sum).Sum
	$reportClus += $row
}
Write-Host "Report per cluster" 
$reportClus

The script can be easily changed to run against all datacenters by adding an outer loop that cycles through all the datacenters.

If you want to save the report(s) to a spreadsheet, you easily do this by changing the line where the report is displayed on screen to something liek this

...
$report | Export-Csv "C:\report.csv" -NoTypeInformation
...

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ChristianWickha
Contributor
Contributor
Jump to solution

That's great!

I had to change one little bit;

$row.RAMUsed = "" -f ($statsEsx | where {$_.MetricId -eq "mem.usage.average"} | Measure-Object -Property Value -Average).Average

This rounds the figure to a single decimal place, as a 12 digit percentage is not really appropriate...

Reply
0 Kudos