View current instances wuth kql query in Azure Web Apps

Johann 0 Reputation points
2024-04-23T11:54:59.0133333+00:00

Hi there,

I'm trying to view the current intances with a KQL query but not really successful, tired a couple of different KQL query, see below :

requests
| where timestamp >= ago(24h)
| summarize CountOfEvents=count() by bin(timestamp, 1h), cloud_RoleInstance
| render timechart 

Second KQL query :

AutoscaleScaleActionsLog
| project TimeGenerated, ResourceId, CurrentInstanceCount, NewInstanceCount, ScaleDirection, ResultType
| sort by TimeGenerated desc

Third KQL query :

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

All these KQL queries works but not really what I'm looking for. As mentioned I want to display the current running instances, in the Web App, even if it's manually scaled or rule based?

Any help would be appreciated.

Thanks 😀

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,905 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Deepanshu katara 4,980 Reputation points
    2024-04-24T06:09:34.7966667+00:00

    Hi Johan ,

    Please check below query if it helps your requirement

    
    AppServiceAppLogs
    | where Message contains "Starting instance" or Message contains "Stopping instance"
    | project InstanceId = extractjson("$.InstanceID", Message), State = iff(Message contains "Starting instance", "Running", "Stopped")
    | summarize InstanceCount = count() by State
    
    
    

    Ref doc --> https://learn.microsoft.com/en-us/azure/app-service/monitor-app-service

    Kindly check once and accept if it helps


  2. VenkateshDodda-MSFT 18,436 Reputation points Microsoft Employee
    2024-04-24T07:14:48.79+00:00

    @Johann Thank you for posting your question in Microsoft Q&A.

    Based on the information, I understand that you want to know the current number of instances of the app service that is running using KQL query irrespective whether it is scaled out or not. Correct me if my understanding is wrong.

    The above shared queries Traces, Requests table are part of application insights. Ideally application insights are used to understand the application behavior.

    If you want to know more about the environment information like how many instances that app service is running and also about different configuration settings, it would be better to relay on Azure Resource Graph explorer.

    • If you are performing scaling at the app service plan level, then you can the below query which focus on currentnumberofworkers property.

    User's image

    • Alternatively, if you don't have dependency on the KQL query then you can leverage this Azure Management Rest API WebApps List instance Identifiers to pull the number of instances.

    Hope this helps, let me know if you have any further questions on this.