Forum Discussion
Azure Virtual Machine runtime calculation
Hi John,
The exact query depends on your specific table structure, which I don't have (I see you provided the field names but I need access to the actual table to create a working example).
I've created an example query based on the Heartbeat table, you can adjust it to meet your custom logs:
Heartbeat | where TimeGenerated > ago(7d) | summarize heartbeats_per_hour=count() by bin(TimeGenerated, 1h), Computer | extend state_per_hour=iff(heartbeats_per_hour>0, true, false) | summarize total_running_hours=countif(state_per_hour==true) by Computer | where total_running_hours > 8
you can also run it on our demo environment.
basically, this query finds computers that have been running for more than 8 hours (total) over the last 7 days. I am not sure why 40 hours would be more complicated, can you explain what you meant?
HTH,
Noa
Noa,
Thanks for this I'll adjust it for my table.
The 40 hour requirement is a lifetime calculation of the VM runtime. The customer I'm working with is providing a SaaS app "evaluation" to a customer which they only want to allow them to use it NO more than 40 hours total. It's likely that they'd reach this in a week, but it's also likely they'd reach it in 40 days if they only use the VMs for an hour a day...Log analytics keeps data for 31 days? so if I calculated off of the data retained there could be a scenario where the usage is 31 hours and never reaches 40.
john
- Noa KuperbergMay 14, 2018
Microsoft
Hey John,
Retention is up to you. To configure, "Usage and estimated costs" on the Log Analytics workspace menu, and in it "Data volume management":
- John WildesMay 14, 2018Brass Contributor
Thanks Noa! Did not know that functionality was added to the portal...greatly appreciated!
- Noa KuperbergMay 15, 2018
Microsoft
Great! you can read on changing retention here and make sure you can easily manage your costs without concerns.