azureazure-application-insightsautoscalingazure-vm-scale-setazure-monitoring

How to get instances count for VMSS in Application Insights?


I have a Virtual Machine Scale Set (VMSS) with autoscaling rules. I can get the performance metrics of a host but there is no graph for instances count.

Metrics

There is a graph on VMSS settings "Scaling" -> "Run history", like this.

Scaling History

But how I can get it from Metrics and place on the dashboard?


Solution

  • By default, having a VMSS does not emit anything to Application Insights (AI) unless you configure an app / platform (like Service Fabric for example) to use AI.

    So, if you do have software running on the VMSS that emits to AI then you could write an AI analytics query to get the instance count like this:

    requests
    | summarize dcount(cloud_RoleInstance) by bin(timestamp, 1h) 
    

    Typically cloud_RoleInstance contains a VM identifier so that is what I used in the query. It does show the distinct count of VMs.

    This only works reliable if the software runs on all VMs in the VMSS and if all VMs emit data to AI at least once an hour. Of course you can adapt the script to your liking / requirements.

    operators used:
    dcount: counts the unique occurences of the specified field
    bin: group results in slots of 1 hour