Search code examples
azureazure-functions

How can I monitor number of instances of a function app when it scales out?


I am looking into "Metrics" tab (Platform Features -> Metrics) in Azure portal for my function app. I can see interesting metrics like CPU time, request count, etc. but there is no metric that would show the number of instances that the app has scaled out to.

enter image description here

Is there a way to get the number of instances of the app across time?


Solution

  • One way is to use an App Insights query. This will give you the number of distinct instances running every 30 seconds for the last 24 hours.

    You can edit the granularity and the time span as you choose but bear in mind that the larger granularity the less accurate the query will be as instances can spin up and wind down at any time.

    let grainTime = 30sec;
    
    traces
    | where timestamp >= ago(24h)
    | summarize ['rate/minute'] = dcount(cloud_RoleInstance) by bin(timestamp, grainTime)
    | render timechart
    

    You can then pin this to your dashboard!