Forum Discussion
abhijitchaudhari
Mar 29, 2019Copper Contributor
Use time range value in kusto query to calculate % uptime
Is there a way to access time range selected from azure portal in log/app analytics query to help calculate the % uptime ? I am able to calculate the the downtime in minutes using our custom lo...
Lucas Chies
Apr 04, 2019Copper Contributor
abhijitchaudhari Hello,
I'm using in my subscription this script.
let start_time=startofday(datetime("2019-03-01 00:00:00 AM")); let end_time=endofday(datetime("2019-03-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
With this you can get the total time, in hours, by vms and the avg during the month.
I hope this help you.
Tks
ankitac
Microsoft
Apr 06, 2022I'm trying to use a similar query, taking the TimeGenerated field as input and get the below error.
Error is Query could not be parsed at 'datetime(start_time)'
let start_time = Heartbeat | summarize min(TimeGenerated);
let end_time = Heartbeat | summarize max(TimeGenerated);
Heartbeat
| where TimeGenerated > datetime(start_time) and TimeGenerated < datetime(end_time)