Need performance report for VMs with the below values starting from morning 8 AM to 6PM to get the report every 1 hour with below values.
VmName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
There are many sample scripts for this kind of report available in this community.
For example, have a look at Re: need a script to collect the performance report.
It will report the "average" counters for CPU and Memory for each VM.
But it should be trivial to add the minimum and maximum counters.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I dont find the script to get the below values from 8AM to 6PM from monday to sunday with the below values for all VMs
VmName, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
Pls help me with the details
The 2nd script in PowerCLI & vSphere statistics – Part 2 – Come together shows how to filter on time ranges.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thatt script is for the ESXi servers. I am looking for VMs. can you help me pls
esxName =
"my-ESX-hostname"
$esxImpl
=
Get-VMHost
-Name
$esxName
$todayMidnight
= (
Get-Date
-Hour
0
-Minute
0
-Second
0).AddMinutes(-1)
$workingDays
=
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
$dayStart
=
New-Object
DateTime(1,1,1,7,30,0)
# 07:30 AM
$dayEnd
=
New-Object
DateTime(1,1,1,17,30,0)
# 05:30 PM
$stats
=
Get-Stat
-Entity
$esxImpl
-Stat
cpu.usage.average
-Start
$todayMidnight
.AddDays(-14)
-Finish
$todayMidnight
.AddDays(-7)
$report
=
$stats
|
Where-Object
{
$workingDays
-contains
$_
.Timestamp.DayOfWeek
-and
$_
.Timestamp.TimeOfDay
-gt
$dayStart
.TimeOfDay
-and
$_
.Timestamp.TimeOfDay
-lt
$dayEnd
.TimeOfDay
}
$report
|
Export-Csv
"C:\BusinessHours-cpu.csv"
-NoTypeInformation
-UseCulture
Try something like this
$stat = 'cpu.usage.minimum','cpu.usage.average','cpu.usage.maximum',
'mem.usage.minimum','mem.usage.average','mem.usage.maximum'
$finish = Get-Date
$start = $finish.AddDays(-2)
$dayStart = Get-Date -Hour 8 -Minute 0 -Second 0 # 08:00 AM
$dayEnd = Get-Date -Hour 18 -Minute 0 -Second 0 # 18:00 PM
$vm = Get-VM
$stats = Get-Stat -Entity $vm -Stat $stat -Start $start -Finish $finish
$report = $stats | Where-Object {
$_.Timestamp.TimeOfDay -gt $dayStart.TimeOfDay -and $_.Timestamp.TimeOfDay -lt $dayEnd.TimeOfDay
} | Group-Object -Property {$_.Entity.Name,$_.Timestamp.Day,$_.Timestamp.Hour} | %{
New-Object PSObject -Property @{
VM = $_.Values[0][0]
Day = $_.Values[0][1]
Hour = $_.Values[0][2]
CPUMin = $_.Group | where {$_.MetricId -eq 'cpu.usage.minimum'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average
CPUAvg = $_.Group | where {$_.MetricId -eq 'cpu.usage.average'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average
CPUMax = $_.Group | where {$_.MetricId -eq 'cpu.usage.maximum'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average
MemMin = $_.Group | where {$_.MetricId -eq 'mem.usage.minimum'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average
MemAvg = $_.Group | where {$_.MetricId -eq 'mem.usage.average'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average
MemMax = $_.Group | where {$_.MetricId -eq 'mem.usage.maximum'} | Measure-Object -Property Value -Average | Select -ExpandProperty Average
}
}
$report |
Select VM,Day,Hour,CPUMin,CPUAvg,CPUMax,MemMin,MemAvg,MemMax |
Export-Csv "C:\BusinessHours-cpu.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference