简体   繁体   中英

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.

在此处输入图像描述

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

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.

选择实例

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!

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.

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. 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM