Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

Script for Performance Stats - CPU/Memory (Max/Min/Avg)

$
0
0

 

We have monthly performance statistics to gather. A new requirement is for hourly CPU/Memory (Max/Min/Avg).Here's what we've come with so far:

 

$allhosts = @()
$allvms = @()
$hosts = Get-VMHost
$vms = Get-Vm
# connect-viserver


foreach($vmHost in $hosts){
$stats = Get-Stat -Entity $vmHost -Start (get-date).AddDays(-7) -Stat "cpu.usage.average","mem.usage.average"
$groups = $stats | Group-Object -Property {$_.Timestamp.DayOfYear,$_.Timestamp.Hour}
$groups | % {
$cpuMeasure = $_.Group | where{$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""} | `
Measure-Object -Property Value -Average -Maximum -Minimum
$memMeasure = $_.Group | where{$_.MetricId -eq "mem.usage.average"} | `
Measure-Object -Property Value -Average -Maximum -Minimum
$row = "" | Select HostName,Timestamp,CpuAvg,CpuMin,CpuMax,MemAvg,MemMin,MemMax
$row.HostName = $_.Group[0].Entity.Name
$row.Timestamp = $_.Group[0].Timestamp.Date.AddHours($_.Group[0].Timestamp.Hour)
$row.CpuAvg = ::Round($cpuMeasure.Average, 2)
$row.CpuMin = ::Round($cpuMeasure.Minimum, 2)
$row.CpuMax = ::Round($cpuMeasure.Maximum, 2)
$row.MemAvg = ::Round($memMeasure.Average, 2)
$row.MemMin = ::Round($memMeasure.Minimum, 2)
$row.MemMax = ::Round($memMeasure.Maximum, 2)
$allhosts += $row
}
}
$File = "C:\temp\VCScripts\Reports\Test\vmHosts_wk.csv"
$allhosts | Sort-Object -Property Timestamp | Export-Csv $File -noTypeInformation -useculture
foreach($vm in $vms){
$stats = Get-Stat -Entity $vm -Start (get-date).AddDays(-7) -Stat "cpu.usage.average","mem.usage.average"
$groups = $stats | Group-Object -Property {$_.Timestamp.DayOfYear,$_.Timestamp.Hour}
$groups | % {
$cpuMeasure = $_.Group | where{$_.MetricId -eq "cpu.usage.average" -and $_.Instance -eq ""} | `
Measure-Object -Property Value -Average -Maximum -Minimum
$memMeasure = $_.Group | where{$_.MetricId -eq "mem.usage.average"} | `
Measure-Object -Property Value -Average -Maximum -Minimum
$row = "" | Select HostName,Timestamp,CpuAvg,CpuMin,CpuMax,MemAvg,MemMin,MemMax
$row.HostName = $_.Group[0].Entity.Name
$row.Timestamp = $_.Group[0].Timestamp.Date.AddHours($_.Group[0].Timestamp.Hour)
$row.CpuAvg = ::Round($cpuMeasure.Average, 2)
$row.CpuMin = ::Round($cpuMeasure.Minimum, 2)
$row.CpuMax = ::Round($cpuMeasure.Maximum, 2)
$row.MemAvg = ::Round($memMeasure.Average, 2)
$row.MemMin = ::Round($memMeasure.Minimum, 2)
$row.MemMax = ::Round($memMeasure.Maximum, 2)
$allvms += $row
}
}
$File2 = "C:\temp\VCScripts\Reports\Test\vms_wk.csv"
$allvms | Sort-Object -Property Timestamp | Export-Csv $File2 -noTypeInformation -useculture

 

The problem is I'm getting the same line output for Avg/Min/Max. Any ideas?

 

 

VMware's 30 minute sampling should suffice, but given VC only holds the data for a week, I was planning to run the script every week to capture the data, then combine with the others for the montly report.

 

 


Viewing all articles
Browse latest Browse all 179681

Trending Articles