If anyone can help me I will greatly appreciate it.
Here is my pain explained:
RAM Usage
=========
One week maximum:11.3%
Everyday for one week maximum:15% (Rounded Value)
!Not so big difference and I can live with it but in some case like CPU usage, the difference is drastic especially for Mhz usage check.
CPU Usage
=========
One week maximum: 543 Mhz
Everyday for one week maximum:1558 Mhz
That means my reports in this case are 3 times less accurate and I cannot live with that.
Thanks allot and looking forward from hearing from anyone.
Can you run the CPU metric with the additional parameter -Instance '', in other words, a blank instance (the aggregate value).
When you have a VM with multiple vCPU, there will be a value for each vCPU plus an aggregate value.
You can have for example:
CPU0 : 1200
CPU1 : 600
CPU aggregate: 900
If you just go for the maximum over all instances you'll end up with 1200.
While in fact you are looking for 900.
You'll find more on that concept in my PowerCLI & VSphere Statistics – Part 1 – The Basics post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
In my case there is no specific "Instance" and I do have for this server 4x vCPUs
Ok, that is then due to the aggregation jobs and the Statistics Levels you defined.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you Luc; so what are my options?
What statistics level should one enable so that <past week values> vs <everyday for past week values> would match?
Can you try obtaining the maxima in the following way?
I assume you're collecting for an ESXi node, but for a VM would work just as well.
When I run the following, I always get the same value for both methods.
$esx = Get-VMHost -Name $esxName
$sStat = @{
Entity = $esx
Start = (Get-Date).AddDays(-7)
Stat = 'mem.usage.average'
}
$statsMem = Get-Stat @sStat
$statsMem | Measure-Object -Property Value -Maximum
$statsMem | Sort-Object -Property {$_.Value} -Descending | select -First 1
$sStat = @{
Entity = $esx
Start = (Get-Date).AddDays(-7)
Stat = 'cpu.usagemhz.average'
}
$statsCPU = Get-Stat @sStat
$statsCPU | Measure-Object -Property Value -Maximum
$statsCPU | Sort-Object -Property {$_.Value} -Descending | select -First 1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried your way but it is exactly same like I got in the beginig ; and the value mismatch is hudge as well.
This is my initial way and value:
PS C:\> Get-Stat -Entity ($srvName) -start (get-date).AddDays(-7) -Finish (get-date) -stat "cpu.usagemhz.average" | Measure-Object -Property value -Maximum | Select -ExpandProperty Maximum
516
This is as you suggested and the results:
PS C:\> $sStat = @{
>> Entity = $srvname
>> Start = (Get-Date).AddDays(-7)
>> Stat = 'cpu.usagemhz.average'
>> }
PS C:\> $statsCPU = Get-Stat @sStat
PS C:\> $statsCPU | Measure-Object -Property Value -Maximum
Count : 334
Average :
Sum :
Maximum : 516
Minimum :
Property : Value
PS C:\> $statsCPU | Sort-Object -Property {$_.Value} -Descending | select -First 1
MetricId Timestamp Value Unit Instance
-------- --------- ----- ---- --------
cpu.usagemhz.average 2/21/2020 10:30:00 PM 516 MHz
And now the real results:
PS C:\>
>> $statD7 = Get-Stat -Entity ($srvName) -start (get-date).AddDays(-7) -Finish (get-date).AddDays(-6) -stat "cpu.usagemhz.average"
>> $statD6 = Get-Stat -Entity ($srvName) -start (get-date).AddDays(-6) -Finish (get-date).AddDays(-5) -stat "cpu.usagemhz.average"
>> $statD5 = Get-Stat -Entity ($srvName) -start (get-date).AddDays(-5) -Finish (get-date).AddDays(-4) -stat "cpu.usagemhz.average"
>> $statD4 = Get-Stat -Entity ($srvName) -start (get-date).AddDays(-4) -Finish (get-date).AddDays(-3) -stat "cpu.usagemhz.average"
>> $statD3 = Get-Stat -Entity ($srvName) -start (get-date).AddDays(-3) -Finish (get-date).AddDays(-2) -stat "cpu.usagemhz.average"
>> $statD2 = Get-Stat -Entity ($srvName) -start (get-date).AddDays(-2) -Finish (get-date).AddDays(-1) -stat "cpu.usagemhz.average"
>> $statD1 = Get-Stat -Entity ($srvName) -start (get-date).AddDays(-1) -Finish (get-date) -stat "cpu.usagemhz.average"
PS C:\> $vCPUUsedMhz = &{foreach ($item in Get-Variable statD*){$item.value | ?{$_.MetricID -eq "cpu.usagemhz.average"} | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum}} |Sort-Object -Descending| select -First 1
PS C:\Users\vlad.madaras\Documents\Scripts\Storage\VMDisks> $vCPUUsedMhz
1709
Which of these StatD* variables has the 1709 value?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here is the brakedown of all 7 stats:
PS C:\> $statD1 | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum
1709
PS C:\> $statD2 | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum
449
PS C:\> $statD3 | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum
465
PS C:\> $statD4 | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum
516
PS C:\> $statD5 | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum
450
PS C:\> $statD6 | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum
450
PS C:\> $statD7 | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum
455
That explains the difference.
Seen the time range specified you get the data from different Historical Intervals.
The Last Day is an interval where values are returned for 300 second sample intervals, while for the interval between 1 and 2 days ago (the Last Week interval), the sample interval is 1800 seconds.
This is the result of the data aggregation that happens on the vCenter.
You should in fact use the start date of 7 days ago and a finish date of now.
Then the sample interval will be for all returned metrics 1800 seconds.
$sStat = @{
Entity = $esx
Stat = 'cpu.usage.average'
Start = (Get-Date).AddDays(-7)
Finish = Get-Date
MaxSamples = [int]::MaxValue
}
$stats = Get-Stat @sStat
$stats[0].Interval
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried that before and I got same faulty results.
PS C:\> $srvname = Get-VM mas01-0000.xyz.prod
PS C:\> $sStat = @{
>> Entity = $srvName
>> Stat = 'cpu.usagemhz.average'
>> Start = (Get-Date).AddDays(-7)
>> Finish = Get-Date
>> MaxSamples = [int]::MaxValue
>> }
PS C:\> $stats = Get-Stat @sStat
PS C:\> $stats | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum
516
-----------------------
And not to say that I am crazy or anything; synce we know that previous day value was allot higher; here is same exercise as above with -1 Days.
PS C:\> $sStat = @{
>> Entity = $srvName
>> Stat = 'cpu.usagemhz.average'
>> Start = (Get-Date).AddDays(-1)
>> Finish = Get-Date
>> MaxSamples = [int]::MaxValue
>> }
PS C:\> $stats = Get-Stat @sStat
PS C:\> $stats | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum
1709
And just to be sure; I checked if same situation applies for another country for another vCenter version.
PS C:\> $srvname = Get-VM mas01-xzyspl.zzz.prod
PS C:\> $sStat = @{
>> Entity = $srvName
>> Stat = 'cpu.usagemhz.average'
>> Start = (Get-Date).AddDays(-1)
>> Finish = Get-Date
>> MaxSamples = [int]::MaxValue
>> }
PS C:\> $stats = Get-Stat @sStat
PS C:\> $stats | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum
591
PS C:\> $sStat = @{
>> Entity = $srvName
>> Stat = 'cpu.usagemhz.average'
>> Start = (Get-Date).AddDays(-7)
>> Finish = Get-Date
>> MaxSamples = [int]::MaxValue
>> }
PS C:\> $stats = Get-Stat @sStat
PS C:\> $stats | Measure-Object -Property Value -Maximum | Select -ExpandProperty Maximum
506
So to conclude:
- one day back: 591 Mhz
- seven days back: 506 Mhz (lower)
Is it possible that the rollup per day is so severe that will average highest values in this way?
Beacuse if that is the case; any statistics that I get in one shot back in time with (Get-Date).AddDays(-7) or any timeframe than 24h back, is useless to gather peak system usage values!
That is inherent for aggregation of values.
It will take away the lows and highs and smooth out the graph.
Calculating maxima and minima over a longer period is by definition useless imho
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So I am back to my original question.
What can I do and how to do it?
Except my already discovered solution.(which takes 10 second/server to get data via powercli)
I'm afraid you want to get more out of this data than is in it.
You can extract the Realtime data every hour from each ESXi node and store it yourself.
Then calculate your Maximum from that external data.
Or calculate the Maximum every hour, store the result in an external file.
And then find the maximum from that external data every week.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference