Turbo
Turbo

Reputation: 2551

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?

Upvotes: 30

Views: 16077

Answers (7)

Luis Gouveia
Luis Gouveia

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:

  • Azure Function Resource
  • Azure Function Method

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

Eric P
Eric P

Reputation: 2977

Steps to do it:

  1. Go to the function app in portal
  2. Go to the Diagnose and solve problems tab on the lefthand blade
  3. In Search for common problems or tools, enter "HTTP Functions Scaling"
  4. Scroll down to Number of workers allocated to the Function App

enter image description here

Credit goes to: https://github.com/Azure/Azure-Functions/issues/2323

Upvotes: 2

OssJames
OssJames

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

CredibleAshok
CredibleAshok

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. enter image description here

Upvotes: 0

kiranpradeep
kiranpradeep

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 

enter image description here

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

Sam Barber
Sam Barber

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

ChaitanyaNaykodi-MSFT
ChaitanyaNaykodi-MSFT

Reputation: 196

After selecting any metric from the given options we can add another filter. As shown below.

Add Filter

Then we can add the "Instance" property and choose all the instances currently running for the function app. As shown below.

select the instances

Upvotes: 8

Related Questions