Jan 08 2021
04:05 AM
- last edited on
Apr 08 2022
10:42 AM
by
TechCommunityAP
Jan 08 2021
04:05 AM
- last edited on
Apr 08 2022
10:42 AM
by
TechCommunityAP
Hello,
I am working on query where it should show the monthly availability according to buckets. But it should skip the maintenance days (which is the 4th weekend of the month) and calculate the rest.
I have written the following attempt, but I am struggling with TimeGenerate where it basically should set the value as:
start_month until saturday
and (maintenance)
sunday until end_month.
this maintenance should not be included, so I can see the rest 696 hours of availability.
Thank you.
Jan 11 2021 07:08 AM
Solution
Maybe this?
Heartbeat
// last month
| where TimeGenerated between ( startofmonth(now(),-1).. endofmonth(now(),-1) )
| where Computer contains "JBOX00"
// find 4th week which is week "3"
| extend maintSaturday_ = endofweek(startofmonth(now(),-1),3) -1d, maintSunday_ = endofweek(startofmonth(now(),-1),3) + 1d
// exclude 4th week from data set
| where TimeGenerated !between ( maintSaturday_ .. maintSunday_ )
| summarize heartbeat_per_hour=count() by bin(TimeGenerated, 1h), Computer
| extend available_per_hour=iff(heartbeat_per_hour>0, true, false)
| serialize
| summarize total_available_hours=countif(available_per_hour==true), total_number_of_buckets = max(row_number()) by Computer, bin(TimeGenerated, 1d)
| extend availability_rate=(total_available_hours-48)*100/total_number_of_buckets
| project TimeGenerated, availability_rate
| order by availability_rate desc
| render timechart
Jan 12 2021 02:03 AM - edited Jan 12 2021 02:04 AM
Hello @CliveWatson,
Amazing, Thank you
I adapted to my case and it looks great!
let end_time=(startofmonth(now()) - 1ms);
let start_time=startofmonth(end_time);
Heartbeat
//| where TimeGenerated > start_time and TimeGenerated < end_time
| where TimeGenerated between ( startofmonth(now(),-1).. endofmonth(now(),-1) )
| where Computer contains "TEST"
// find 4th week which is week "3"
| extend maintSaturday_ = endofweek(startofmonth(now(),-1),3) -1d, maintSunday_ = endofweek(startofmonth(now(),-1),3) + 1d
// exclude 4th week from data set
| where TimeGenerated !between ( maintSaturday_ .. maintSunday_ )
| summarize heartbeat_per_hour=count() by bin_at(TimeGenerated, 1h, start_time), Computer
| extend available_per_hour=iff(heartbeat_per_hour>0, true, false)
| summarize total_available_hours=countif(available_per_hour==true) by Computer, bin(TimeGenerated, 1d)
| extend total_number_of_buckets=round((end_time-start_time)/1h)
| extend availability_rate=total_available_hours*100/total_number_of_buckets
| order by availability_rate desc
| render timechart let end_time=(startofmonth(now()) - 1ms);
let start_time=startofmonth(end_time);
Heartbeat
//| where TimeGenerated > start_time and TimeGenerated < end_time
| where TimeGenerated between ( startofmonth(now(),-1).. endofmonth(now(),-1) )
| where Computer contains "TEST"
// find 4th week which is week "3"
| extend maintSaturday_ = endofweek(startofmonth(now(),-1),3) -1d, maintSunday_ = endofweek(startofmonth(now(),-1),3) + 1d
// exclude 4th week from data set
| where TimeGenerated !between ( maintSaturday_ .. maintSunday_ )
| summarize heartbeat_per_hour=count() by bin_at(TimeGenerated, 1h, start_time), Computer
| extend available_per_hour=iff(heartbeat_per_hour>0, true, false)
| summarize total_available_hours=countif(available_per_hour==true) by Computer, bin(TimeGenerated, 1d)
| extend total_number_of_buckets=round((end_time-start_time)/1h)
| extend availability_rate=total_available_hours*100/total_number_of_buckets
| order by availability_rate desc
| render timechart
However, could you maybe just help with one thing, why the start date is not the December 1st in this case, but December 13? And is there a way to sum all days instead of having availability rate/row for each day?
Thanks again!
Jan 12 2021 02:11 AM - edited Jan 12 2021 02:46 AM
Hi @CliveWatson ,
Amazing, I just adapted to my case and it looks perfectly!
let end_time=(startofmonth(now()) - 1ms);
let start_time=startofmonth(end_time);
Heartbeat
//| where TimeGenerated > start_time and TimeGenerated < end_time
| where TimeGenerated between ( startofmonth(now(),-1).. endofmonth(now(),-1) )
| where Computer contains "TEST"
// find 4th week which is week "3"
| extend maintSaturday_ = endofweek(startofmonth(now(),-1),3) -1d, maintSunday_ = endofweek(startofmonth(now(),-1),3) + 1d
// exclude 4th week from data set
| where TimeGenerated !between ( maintSaturday_ .. maintSunday_ )
| summarize heartbeat_per_hour=count() by bin_at(TimeGenerated, 1h, start_time), Computer
| extend available_per_hour=iff(heartbeat_per_hour>0, true, false)
| summarize total_available_hours=countif(available_per_hour==true) by tostring(split(Computer, ".")[0]), bin(TimeGenerated, 1d)
| extend total_number_of_buckets=round((end_time-start_time)/1h)
| extend availability_rate=total_available_hours*100/total_number_of_buckets
| order by availability_rate desc
| render timechart
However, could you please just help with the last thing. Why the chart/table starts with December 13 in this case but not December 1st?
Thank you!
Jan 12 2021 05:40 AM
Good to know. The TimeChart will correctly start at Dec 1st, but if you want it in date order for the results view, change
| order by TimeGenerated asc
//| order by availability_rate desc
Jan 13 2021 07:29 AM
@CliveWatson It is ok now. the problem was related to Data Retention which was set to 30 days. Therefore I didn't see more than 30 days ago and it was showing the value of (today-30days)
I think I just need to wait for next month to collect the full data 🙂
Thank you again.
Jan 13 2021 07:33 AM
Jan 20 2021 05:11 AM
It looks perfect in demo data set 🙂
However when I pin it do dashboard I still see results for the last 30 days, despite the custom date set. Is there a way to bypass this override option?
Jan 20 2021 08:21 AM
30days is the max (as far as I know), a custom range is for values between 0-30days.
Azure Monitor Workbooks don't have this restriction, that may be an alterative for you?
Jan 26 2021 02:40 AM
@CliveWatson To be honest, that looks much better 🙂
Thank you!
Feb 09 2021 03:45 AM
Hello @CliveWatson,
Thanks a lot for help again! May I ask you please to help with 2 more questions.
1. The availability query result doesn't show for some reason machines older than Windows Server 2012. Do you know what could be a reason? Is it related to Logs configuration/settings?
2. We have a redundant cluster server like TESTVM01A and TESTVM01B. Is there a proper way to count these 2 machines in availability query as one?
Thank you.
Feb 09 2021 03:57 AM
The Heartbeat table should get Agent data from Windows Server 2008R2 as well
Overview of the Azure monitoring agents - Azure Monitor | Microsoft Docs
For a cluster I don't think we have an identifier, so you would probably have to use a list in the query to count these, together
i.e
let includeClusterNodes = dynamic(["nodeA","nodeB","nodeC"]);
Feb 17 2021 04:45 AM
Hello @CliveWatson, do you know what could be a reason why 2008 machines do not appear in table?
Aug 08 2023 06:39 AM
@CliveWatson Could I please get some assistance as I have been trying to get the availability report for our Azure VMs uptime by selecting the data range as from 1st of July to 31st July and using the query below as per your advice but not getting the accurate available number of hours. Some of our VMs have been up 100% of time throughout the month but when running this query, the total available hours and availability rate is coming as incorrect :
let start_time=startofday(datetime("2023-07-01 00:00:00 AM"));
let end_time=endofday(datetime("2023-07-31 11:59:59 PM"));
Heartbeat
| where TimeGenerated > start_time and TimeGenerated < end_time
| summarize heartbeat_per_hour=count() by bin_at(TimeGenerated, 1h, start_time), Computer
| extend available_per_hour=iff(heartbeat_per_hour>0, true, false)
| summarize total_available_hours=countif(available_per_hour==true) by Computer
| extend total_number_of_buckets=round((end_time-start_time)/1h)
| extend availability_rate=total_available_hours*100/total_number_of_buckets
We get the output as below, can I please get some advice if we need to change something to get the correct output:
Aug 09 2023 10:10 AM
Try using make-series with default=0 that way you'll see any missing entries - if I was doing this today I'd use this.
Go to Log Analytics and run query
Compared to Summarize which doesnt display the missing results
Go to Log Analytics and run query
Jan 11 2021 07:08 AM
Solution
Maybe this?
Heartbeat
// last month
| where TimeGenerated between ( startofmonth(now(),-1).. endofmonth(now(),-1) )
| where Computer contains "JBOX00"
// find 4th week which is week "3"
| extend maintSaturday_ = endofweek(startofmonth(now(),-1),3) -1d, maintSunday_ = endofweek(startofmonth(now(),-1),3) + 1d
// exclude 4th week from data set
| where TimeGenerated !between ( maintSaturday_ .. maintSunday_ )
| summarize heartbeat_per_hour=count() by bin(TimeGenerated, 1h), Computer
| extend available_per_hour=iff(heartbeat_per_hour>0, true, false)
| serialize
| summarize total_available_hours=countif(available_per_hour==true), total_number_of_buckets = max(row_number()) by Computer, bin(TimeGenerated, 1d)
| extend availability_rate=(total_available_hours-48)*100/total_number_of_buckets
| project TimeGenerated, availability_rate
| order by availability_rate desc
| render timechart