Reputation: 3242
I have a few scale sets in Azure (VMSS) and want to display the instance count for each of them in a line chart, probably a bit like this:
Unfortunately, there is no metric in Azure Monitor that contains the current (+ historic) number of instances.
I have tried to use REST API and Graph API queries; that works, but only gives me a snapshot of the current number of instances in the moment of the query. I would like to have a historical overview as well.
My thought was, if I find a way to regularly store the results of the API queries in a custom metric, I have all the information available and can create nice charts from it.
It is certainly possible to create an Azure Function that sends metrics, but it seems like overkill.
Any ideas?
Upvotes: 2
Views: 1207
Reputation: 3242
This metric is really missing in Azure Monitor. Suggested workaround:
The Azure Monitor Agent needs to be installed on all machines within the scale set. The agent would then by default send heartbeats to Azure Monitor, about once per minute. Each of the heartbeats would create a log entry in Azure Monitor.
With the right query it is then possible to derive the number of VMSS instances from the heartbeats:
InsightsMetrics
| where Origin == "vm.azm.ms/map"
| where Namespace == "Computer"
| where Name == "Heartbeat"
| summarize heartbeat_count = count() by bin(TimeGenerated, 5m), Computer
| extend alive=iff(heartbeat_count > 2, 1.0, 0.0) //computer considered "down" if it has 2 or fewer heartbeats in 5 min interval
| where alive == true
| project TimeGenerated, alive, Computer
| summarize alive_count = count() by bin(TimeGenerated, 5m), alive
| project TimeGenerated, alive_count
| order by TimeGenerated asc
| render timechart
This can to be queried via the Monitoring > Logs section in the VMSS and can then be pinned to any dashboard.
All credits go to the friendly Microsoft Support (Thank you!).
Upvotes: 1