Quantcast
Viewing latest article 21
Browse Latest Browse All 46

Re: need a script to collect the performance report.

The problem is that the statistical data is aggregated.

That means that for the period you are asking, you only have 1 value perday (historical interval 4).

If we go for historical interval 3, we will have 2-hour intervals for the statistics.

And then we can filter business hours this way.

The following will produce a report for the last 7 days.

 

$vms=Get-VMMy-VM
$metric
="cpu.usage.average","mem.usage.average"
$finish
=Get-Date-Hour0-Minute0-Second0
$start
=$finish.AddDays(-7)$workingDays="Monday","Tuesday","Wednesday","Thursday","Friday"
$dayStart
=New-Object DateTime(1,1,1,9,0,0)     # 09:00 AM
$dayEnd
=New-Object DateTime(1,1,1,18,0,0)      # 06:00 PM

$stats
=Get-Stat-Entity$vms-Stat$metric-Start$start-Finish$finish
$stats |Where-Object {    $workingDays-contains$_.Timestamp.DayOfWeek -and
   
$_.Timestamp.TimeOfDay -gt$dayStart.TimeOfDay -and
    $_.Timestamp.TimeOfDay -lt$dayEnd.TimeOfDay } |Group-Object-Property {$_.Entity.Name},{$_.Timestamp} |Select @{N="VM";E={$_.Values[0]}}, @{N="Time";E={$_.Values[1]}}, @{N="CPU";E={($_.Group | where {$_.MetricId -eq"cpu.usage.average"}).Value}}, @{N="Memory";E={($_.Group | where {$_.MetricId -eq"mem.usage.average"}).Value}}|Export-Csv"C:\MY-VM-Perf.csv"-NoTypeInformation–UseCulture

 

And mem.usage.average is in %


Viewing latest article 21
Browse Latest Browse All 46

Trending Articles