VM Execution Time reached

%3CLINGO-SUB%20id%3D%22lingo-sub-2404714%22%20slang%3D%22en-US%22%3EVM%20Execution%20Time%20reached%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2404714%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3EI'm%20working%20on%20a%20query%20to%20create%20an%20alert%20when%20a%20VM%20has%20been%20up%20and%20running%20for%20more%20the%208%20hours.%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20trying%20to%20achieve%20that%20using%20the%20Heartbeat.%20My%20idea%20is%20to%20have%20a%20query%20that%20validates%20that%20the%20heartbeat%20was%20reported%26nbsp%3B%20for%208%20hours%20straight%20.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20started%20working%20on%20the%20below%20query%20that%20gives%20me%20the%20time%20difference%20between%20the%20first%20and%20the%20last%20heartbeat%20on%20the%20last%208%20hours.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20can%20I%20query%20for%20the%20heartbeat%20on%208hours%20straight%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F%2FCalculate%20VM%20total%20time%20available%20on%20the%20past%208H%3CBR%20%2F%3EHeartbeat%3CBR%20%2F%3E%7C%20where%20TimeGenerated%20%26gt%3B%20ago(8h)%3CBR%20%2F%3E%7C%20summarize%20LastHeartbeat%3Dmax(TimeGenerated)%2C%20OldestHeartbeat%3Dmin(TimeGenerated)%20by%20Computer%3CBR%20%2F%3E%2F%2F%20Total%20time%20Available%2FHours%3CBR%20%2F%3E%7C%20extend%20TotalHoursAvailable%20%3D%20(datetime_diff('hour'%2C%20LastHeartbeat%2C%20OldestHeartbeat))%3CBR%20%2F%3E%7C%20where%20TotalHoursAvailable%20%26gt%3B%207%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2408799%22%20slang%3D%22en-US%22%3ERe%3A%20VM%20Execution%20Time%20reached%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2408799%22%20slang%3D%22en-US%22%3ECheck%20whether%20below%20query%20will%20be%20satisfy%20your%20requirement%20and%20also%20suggesting%20you%20to%20set%20the%20Azure%20Alert%20based%20on%20the%20response%20to%20have%20automated%20mail%20alert%20or%20Webhook%20or%20azure%20function%20to%20cut%20ticket%20system.%3CBR%20%2F%3E%3CBR%20%2F%3EHeartbeat%3CBR%20%2F%3E%7C%20summarize%20max(TimeGenerated)%20by%20Computer%3CBR%20%2F%3E%7C%20where%20max_TimeGenerated%20%26gt%3B%20ago(8h)%3C%2FLINGO-BODY%3E
New Contributor

Hello,

I'm working on a query to create an alert when a VM has been up and running for more the 8 hours. 

I'm trying to achieve that using the Heartbeat. My idea is to have a query that validates that the heartbeat was reported  for 8 hours straight .

 

I have started working on the below query that gives me the time difference between the first and the last heartbeat on the last 8 hours. 

 

How can I query for the heartbeat on 8hours straight?

 

//Calculate VM total time available on the past 8H
Heartbeat
| where TimeGenerated > ago(8h)
| summarize LastHeartbeat=max(TimeGenerated), OldestHeartbeat=min(TimeGenerated) by Computer
// Total time Available/Hours
| extend TotalHoursAvailable = (datetime_diff('hour', LastHeartbeat, OldestHeartbeat))
| where TotalHoursAvailable > 7

2 Replies
Check whether below query will be satisfy your requirement and also suggesting you to set the Azure Alert based on the response to have automated mail alert or Webhook or azure function to cut ticket system.

Heartbeat
| summarize max(TimeGenerated) by Computer
| where max_TimeGenerated > ago(8h)

@Seshadrr That query only shows the most recent heartbeat per VM on the last 8 hours. Doesn't mean that it has been reporting heartbeats for 8hours straight.

I'm trying to know if the VM was running 8h straight. It's not expected to be up an running so long. We need to be alerted in the case of the VM is still running after 8h.

 

Thanks.