VMware Cloud Community
lemuelleung
Contributor
Contributor

Performance report on one VM

Unfortunately, I am no expert to Powershell, so I need quite a bit of help with this one.

I am trying to get a script or script something that will pull the following information:

Duration: 1 day (24 hours), 1 week, 1 month

Information: Memory usage and CPU usage

Can these be customized to pump out data to the minute and put it into a csv?

Can the script force a prompt to enter which vm needs to be monitored?

Thanks for your help!

0 Kudos
1 Reply
LucD
Leadership
Leadership

The statistical data that is kept in the vCenter DB is aggregated and the sample intervals are fixed.

See my PowerCLI & vSphere statistics – Part 1 – The basics post for more info on intervals and sample periods.

Prompting for input is easy in PowerShell

$answer = Read-Host -Prompt "Enter a value"

Storing data in a CSV is also quite easy with the Export-Csv cmdlet.

A short sample script

$vmName = Read-Host -Prompt "Enter the name of the guest"
$start = (Get-Date).AddHours(-24)
$stats = Get-Stat -Entity (Get-VMHost esx41*) -Start $start -Stat "cpu.usage.average","mem.usage.average"
$report = @()
$stats | Group-Object -Property Timestamp | %{
	$row = "" | Select Name,Time,CPU,Memory
	$row.Name = $vmName
	$row.Time = $_.Name
	$row.CPU = ($_.Group | where{$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""}).Value
	$row.Memory = ($_.Group | where{$_.MetricId -eq "mem.usage.average"}).Value
	$report += $row
}
$report | Export-Csv ("C:\" + $vmName + "-stats.csv") -NoTypeInformation

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos