VMware Cloud Community
kaizenwerks
Contributor
Contributor

Specify two time periods (8AM - 5PM) when using get-vmhost

Hi all,

I'm able to get results from performing "Get-Stat -Entity (Get-VMHost) -Stat cpu.usagemhz.average -IntervalMins 1440 -Start (get-date).adddays(-31) -Finish (get-date)"

What I'm interested in, is if it is possible to collect data between two specific times, within a 30 day period? In other words, is it possible to capture data from 8:00am - 5:00 pm, everyday, over a 30 day period? With the syntax above, the data is averages for the entire 24hrs / day.

Thanks.

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

The Get-Stat cmdlet doesn't let you specify time ranges but have a look at my latest post called PowerCLI & vSphere statistics – Part 2 – Come together. I think the 2nd script in there does more or less what you're asking.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

kaizenwerks
Contributor
Contributor

This is awesome LucD and nice site by the way, I'll be referencing it from now on. I went through all of Part 2 but perhaps I'm still missing something. I'm trying to modify the script to run across 3 months at 2 hr increments over working hours. I was able to capture data over 3 months but now it's only getting data at 16:00 each day instead of every 2 hrs. Am I missing something?

Any help would be appreciated!

-


$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,3,00,0) # 05:00 AM (Take into account EST)

$dayEnd = New-Object DateTime(1,1,1,20,00,0) # 07:00 PM

$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $todayMidnight.AddDays(-97) -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

Reply
0 Kudos
LucD
Leadership
Leadership

Since you're going back 3 months the values will come from Historical Interval 4, which means you have only one value per day.

I tried to explain that in Part1 in the Intervals section


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

kaizenwerks
Contributor
Contributor

Ok, I referenced your Part I and understand what you're referring to. So now I'm back to obtaining one month's of data, within business hours, and business days. I'm still trying to understand how the -Start $todayMidnight.AddDays(-25) -Finish $todayMidnight.AddDays(-7) works. I looked at your explanation but didn't find anything on how to tweak these values. I've done a little trial and error and the values below gets me 12 days of stats, although the goal is to get one month. Any thoughts is much appreciated.

-


$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,3,00,0) # 05:00 AM (Take into account EST)

$dayEnd = New-Object DateTime(1,1,1,20,00,0) # 07:00 PM

$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $todayMidnight.AddDays(-25) -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

Reply
0 Kudos
LucD
Leadership
Leadership

I was planning on doing a post on manipulating dates and producing calendar-based monthly reports in the near future, but this is a short extract.

If you want the 30 days, the day before yesterday included, you can do

$stats = Get-Stat -Entity $esxImpl -Stat cpu.usage.average -Start $todayMidnight.AddDays(-32)

Note1: this will return values from Historical Interval 4 since the period you asked start back further than 1 month

Note2: the Historical Interval 4 value for yesterday will not be available. This due to the Week roll up script that run on the VC db server.

Note3: if there is no finish parameter the interval will end at the current time. But another rule says that all the data returned will come from the same Historical Interval. Since Historical Interval 4 stops the day before yesterday, there will be no value for yesterday.

Conclusion: it's currently impossible to get values, from the same historical interval, for a calendar month (except for February) due to the periods of the historical intervals and due to the roll up scripts scheduled on the VC database server.

You can of course run a weekly "collection" job to extract the data and store these. And then run a monthly job,from the stored data, to produce the report you're after.

I admit this is all rather confusing but the bottom line is that the statistical data the VC keeps for you is not your performance database. That you will have to set up yourself by extracting the data in the granularity you desire.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos