16

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?

Turbo
  • 2,179
  • 18
  • 38

4 Answers4

20

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!

Sam Barber
  • 458
  • 1
  • 6
  • 13
  • Flaws: a) `bin()` does not autofill to 0. So this does not show when instance count reduces to zero. We can use `make_series` instead b) More importanly, on push based triggers like eventhub trigger, the function host does not do any activity to be logged into app insights. So app insights does not know whether host is alive or not. – kiranpradeep Dec 22 '20 at 03:21
7

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

  • Thanks! That's nice. I also tried, "apply splitting" option next to "add filter", and that is a good view as well. Both give you *some* idea about the instances, but none allow us to just tack number of instances over time. – Turbo Aug 04 '19 at 04:44
6

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.

kiranpradeep
  • 10,859
  • 4
  • 50
  • 82
  • Will this still log if APPLICATIONINSIGHTS_CONNECTION_STRING app setting is used instead? Docs reference the old instrumentation key setting. I enabled SCALE_CONTROLLER_LOGGING_ENABLED=AppInsights:Verbose on my app and no logs were products for scale controller and the function definitely scaled according to metrics. – Andrew Moreno Mar 20 '23 at 17:41
0

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

CredibleAshok
  • 73
  • 1
  • 9