Search code examples
powershellvmwarepowershell-3.0powercli

Stats object from Get-Stats does not match the "-Start" parameter: PowerCLI


I am working on a script to pull VM memory ballooning and ready summation statistics. I want to pull 24 hours worth of stats at 5 minute intervals. The command I run is:

$datetime = Get-Date       #Get the datetime it currently is
$date = $datetime.Date     #Get just the date, starting at midnight
$interval = 5
$statType = "mem.vmmemctl.average", "cpu.ready.summation"

$vmStats = get-stat -Entity $vm -start $date.AddDays(-1) -Finish $date -MaxSamples 10000 -stat $statType -IntervalMins $interval

However, the results of this give a set of stats that go up to $date (midnight of today), but only go as far back as a rounded current time of day, yesterday.

For example, if get-date returns 03/14/2018 10:43:42 AM, and $date is set to 03/14/2018 12:00:00 AM the earliest stat returned when a start date of $date.AddDays(-1) is used is 2018-03-13 10:30:00.000.

I do not know what is happening. I have tried casting both $date and $date.AddDays(-1) as [date] and [datetime], and I have also tried hardcoding midnight values as the start and finish date. Nothing seems to change the fact that the earliest stat is based on the time of day that Get-Stat was executed.

This does not happen when 30 minute or 2 hour intervals are used. The issue seems to happen only with 5 minute intervals for stats. What am I doing wrong? Is this the normal behavior of Get-Stat?


Solution

  • The 5-minute granularity you want is only available for the past 24 hours. Stats older than that are rolled up into the 30-minute intervals you observe (and eventually rolled up further).

    Archived stats

    "are aggregations (rollups) of the real-time stats. They are aggregated at different sampling intervals and stored in the database. We follow the MRTG standard.

    Past day: past day stats take the real-time stats and roll them up so that there is 1 data point for every 5 minutes. Thus, there are 12 data points per hour and 288 per day.

    Past week: past week stats take the past day stats and roll them up so that there is 1 data point for every 30 minutes. Thus, there are 48 data points per day and 336 per week.

    Past month: past month stats take the past week stats and roll them up so there is 1 data point per 2 hours. Thus, there are 12 data points per day and 360 per month (30-day month). Past year: past year stats take the past month stats and roll them up so there is 1 data point per day. Thus, there are 365 data points per year."