Hi Everyone,
I just want to pull the performance report for the Critical VM's from the lists of VM's. Example CPU/Memory/Disk (Peak and Average %) and OS details.
Thanks
v
Before we dive into code, retrieving peak (maximum) metrics, it depends which Statistic Level you have defined on your VCSA for each Historical Interval.
For more details see my PowerCLI & VSphere Statistics – Part 1 – The Basics post.
Note that high Statistic Levels cause considerable growth in the VCSA DB.
So the 1st question is how far you want to back.
And the 2nd question is which Statistic Level have you defined on the Historical Interval from which you want to report on.
Also note that the further back in time you, the less the data is fit to find peaks in resource usage.
This is due to the aggregation that is done on the statistical data.
For example, Historical Interval 4 (1 metric per day) only gives you 1 metric value per day.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Whatever settings you have, the basic layout of such a script would always be along these lines.
$stat = 'cpu.usage.average','mem.usage.average','disk.usage.average'
$sStat = @{
Entity = Get-VM -Name $vmNames
IntervalSecs = 20
MaxSamples = 1
Stat = $stat
Instance = ''
}
Get-Stat @sStat |
Group-Object -Property {$_.Entity.Name} |
ForEach-Object -Process {
New-Object PSObject -Property ([ordered]@{
VM = $_.Name
OS = $_.Group[0].Entity.Guest.OSFullname
CpuAvgPerc = [math]::Round(($_.Group | where{$_.MetricId -eq 'cpu.usage.average'} |
Measure-Object -Property Value -Average).Average,2)
MemAvgPerc = [math]::Round(($_.Group | where{$_.MetricId -eq 'mem.usage.average'} |
Measure-Object -Property Value -Average).Average,2)
DiskAvgKBps = [math]::Round(($_.Group | where{$_.MetricId -eq 'disk.usage.average'} |
Measure-Object -Property Value -Average).Average,2)
})
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I missed out to mention that i'm looking to pull the report for 1 week performance report.
Historical Interval 4 (1 metric per day) only gives you 1 metric value per day.
thanks
v
You didn't answer my question about the Statistic Level.
If that is not set to 4, the Maximum values are not kept, only the Average.
The Past Week interval has metrics for 30-minute intervals, or 48 for a day.
Do you want all of these?
Or an average per day?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It's my mistake. Yes, i'm looking for an average per day. Right now, i'm looking average usage. It would be nice if we set to 4 then i will pull another separate report. so that i can compare both the data. Thank you once again.
Thanks
v
This should produce the day averages over the past 7 days.
$stat = 'cpu.usage.average', 'mem.usage.average', 'disk.usage.average'
$sStat = @{
Entity = Get-VM -Name $vmNames
Start = (Get-Date).AddDays(-7)
Stat = $stat
Instance = ''
}
Get-Stat @sStat |
Group-Object -Property { $_.Entity.Name } |
ForEach-Object -Process {
$vmName = $_.Name
$_.Group | Group-Object -Property { $_.Timestamp.Day } |
ForEach-Object -Process {
New-Object PSObject -Property ([ordered]@{
VM = $vmName
Day = $_.Group[0].Timestamp.ToShortDateString()
OS = $_.Group[0].Entity.Guest.OSFullname
CpuAvgPerc = [math]::Round(($_.Group | Where-Object { $_.MetricId -eq 'cpu.usage.average' } |
Measure-Object -Property Value -Average).Average, 2)
MemAvgPerc = [math]::Round(($_.Group | Where-Object { $_.MetricId -eq 'mem.usage.average' } |
Measure-Object -Property Value -Average).Average, 2)
DiskAvgKBps = [math]::Round(($_.Group | Where-Object { $_.MetricId -eq 'disk.usage.average' } |
Measure-Object -Property Value -Average).Average, 2)
})
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I did try for 2 servers and it showed me for 1 server
VM | OS | CpuAvgPerc | MemAvgPerc | DiskAvgKBps |
VM1 | Microsoft Windows Server 2012 (64-bit) | 0.95 | 17.99 | 0 |
PS D:\vmk> .\performance-report.ps1
Get-Stat : 1/8/2020 2:33:27 PM Get-Stat The metric counter "cpu.usage.average" doesn't exist for entity
"H201DF11".
At D:\vmk\performance-report.ps1:21 char:1
+ Get-Stat @sStat |
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (cpu.usage.average:String) [Get-Stat], VimException
+ FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics_MetricDoesntExist,VMware.VimAutomation.
ViCore.Cmdlets.Commands.GetViStats
Get-Stat : 1/8/2020 2:33:27 PM Get-Stat The metric counter "mem.usage.average" doesn't exist for entity
"C201MF51".
At D:\vmk\performance-report.ps1:21 char:1
+ Get-Stat @sStat |
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (mem.usage.average:String) [Get-Stat], VimException
+ FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics_MetricDoesntExist,VMware.VimAutomation.
ViCore.Cmdlets.Commands.GetViStats
Get-Stat : 1/8/2020 2:33:27 PM Get-Stat The metric counter "disk.usage.average" doesn't exist for entity
"C201MF51".
At D:\vmk\performance-report.ps1:21 char:1
+ Get-Stat @sStat |
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (disk.usage.average:String) [Get-Stat], VimException
+ FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics_MetricDoesntExist,VMware.VimAutomation.
ViCore.Cmdlets.Commands.GetViStats
Get-Stat : 1/8/2020 2:33:27 PM Get-Stat The metric counter "disk.usage.average" doesn't exist for entity
"VM10034".
At D:\vmk\performance-report.ps1:21 char:1
+ Get-Stat @sStat |
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (disk.usage.average:String) [Get-Stat], VimException
+ FullyQualifiedErrorId : Client20_RuntimeDataServiceImpl_CheckUserMetrics_MetricDoesntExist,VMware.VimAutomation.
ViCore.Cmdlets.Commands.GetViStats
Thanks
v
That might be how you entered the names in your .txt file.
Do you have 1 VM name per line in the .txt file?
What does the following return?
From the error messages it looks as if you don't maintain any statistical data.
It could also be the VMs don't exist long enough to have statistical data for the last week.
Try with VM(s) that have been running for at least a week
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference