Reputation: 2551
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.
Is there a way to get the number of instances of the app across time?
Upvotes: 30
Views: 16077
Reputation: 8925
Very nice queries by both Sam Barber and OssJames, but I'm not sure they realize their queries will return the total number of instances for all Azure Functions attached to their Application Insights instance. For people that, like me, have a single App Insights instance monitoring many Azure Functions, that won't work.
I improved OssJames query to filter per:
Here it is:
traces
| where cloud_RoleName == "AzureFunctionResourceName"
| where operation_Name == "AzureFunctionExposedMethodName"
| make-series dcount(cloud_RoleInstance) on timestamp from ago(48hour) to now() step 30sec
| render timechart
Upvotes: 0
Reputation: 2977
Steps to do it:
Credit goes to: https://github.com/Azure/Azure-Functions/issues/2323
Upvotes: 2
Reputation: 41
traces
| make-series dcount(cloud_RoleInstance) on timestamp from ago(48hour) to now() step 30sec
| render timechart
I combined Sam Barber
's answer along with kiranpradeep
's reply to get this query, which shows 0 instances correctly.
Upvotes: 4
Reputation: 73
I just found it very easy using the portal. You can switch the view for local and UTC time as well. It tells you that how many instances were running at a particular time for your functiton app. Try this out.
Upvotes: 0
Reputation: 11201
As a preview feature, now we can have scale controller emit logs with reasoning to help understand why and how the application have scaled at various points. You will have to add a function configuration as SCALE_CONTROLLER_LOGGING_ENABLED=AppInsights:Verbose
. Then you can query your scale controller logs to know reason and instance count as in this microsoft
docs.
I modified the kusto query in the linked document to have a function scaling graph for past 24 hours
traces
| where customDimensions.Category == "ScaleControllerLogs"
| where customDimensions.Action == "ScaleResult"
| where customDimensions.AppName == "my-function-app-name"
| extend currentInstanceCount = toint(customDimensions.CurrentInstanceCount)
| make-series rawInstanceCounts = max(currentInstanceCount) default=-1 on timestamp in range(ago(24h), now(), 5m)
| extend instanceCountsForwardFilled = series_fill_forward(rawInstanceCounts, -1)
| project timestamp, instanceCountsForwardFilled
| render timechart
You may also emit scale controller logs to Blob Storage. In the above example, I chose AppInsights for quick queries. Also to avoid app insights pricing impact, consider disabling the config parameter once you understood the scaling behaviour.
Upvotes: 8
Reputation: 568
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!
Upvotes: 30
Reputation: 196
After selecting any metric from the given options we can add another filter. As shown below.
Then we can add the "Instance" property and choose all the instances currently running for the function app. As shown below.
Upvotes: 8