Search code examples
azureazure-web-app-serviceazure-alerts

Azure App-Service alerts on auto-scaled instance count with condition


Context : app-service in Azure with enabled auto-scale 2 to 8 instances. Usually workload fluctuates between 2..4 instances, and only on rare occasions scaling maxes out to 8 instances - for such cases I want to set up an alert. Let's say, I am interested in all scaling operation above 4 instance count.

Problem : cannot find an alert "scope + condition signal" combination where instance count of auto-scale would be possible to select. Does such data is accessible at all?

And "no" - I do not want to use OOB "Scale out - Notify" functionality, because this feature sends out emails about all scaling operations. Since I am not interested 2..4 instances and only >4 instances, conditioning must be possible.


Solution

  • You can create the alert mechanism for the autoscale operation in web app by projecting the autoscale operation logs to log analytic workspace & followed by creating custom alert.

    Here are the steps you need to follow:

    1. Go to Scale-out (App service plan) option in the portal under that Navigate to Diagnostic settings.

    enter image description here

    1. Create Diagnostic settings for the autoscale operations & project those logs to log analytics workspace.

    enter image description here

    1. Based on the requirement shared above, use the below query to pull scale out operation of a web app with instance count is greater.
    AutoscaleScaleActionsLog | where OperationName == 'InstanceScaleAction' and ResultType  == "Succeeded" 
        | where  NewInstanceCount >4 and ScaleDirection  == 'Increase'
    
    1. Use the New alert rule option in the log analytics space to create a custom alert & using the above query as signal as shown in below picture.

    enter image description here

    Here is the sample image of the alert rule that was created using the above query

    enter image description here

    The above alert query run for every thirty minutes , if there any autoscale operation got recorded it will trigger an email to mentioned recipients.

    1. click on save , enable the alert rule

    Here is the sample email output triggered by alert rule

    enter image description here