skip to Main Content

I have a app service in Azure that has been scaled out to 5 instances. I can list the instances via the following az cli command

   az webapp list-instances

But how can i tell which instance has frozen or is not responding and restart it ?

2

Answers


  1. With frozen/not responding I assume you speak about a web server that is not responding to HTTP requests (if you meant something else with frozen/not responding, please clarify in your answer above).

    In this case Azure App Services can handle the restart itself when you configure a health check.

    1. Open the App Service app in the azure portal
    2. Under Monitoring, select Health check.
    3. Select Enable and provide a valid URL path on your application, then save

    The URL you provided should return status 200 as long as the app is responsive.

    Here is the Microsoft documentation: https://learn.microsoft.com/en-us/azure/app-service/monitor-instances-health-check?tabs=dotnet

    UPDATE: A few comments on your questions, @Sarah:

    • When you configure a health check, you provide the local path that Azure "pings to check for unhealthy instances" and a "time an unhealth instance remains in the load balancer until it gets removed" . Check the link to the documentation above
    • You configure the path for the health check. So if the full URL of your health check route was testapp.azurewebsites.net/health, you configure /health
    • Regarding authorization: If you implement authorization in your application code, the /health route should work without authentication. If you configure Authorization in the Azure Web app (e.g. in the Azure Portal again), Azure knows how to route the health check without authorization
    • Checking the health of each instance from the public internet? Then you must work around the App Service load balancer – not sure how to do that…
    Login or Signup to reply.
  2. Here is some powershell to call the REST API to fetch a list of instances, and call a health probe on each one:

    ## 1. define environment
    $subscriptionId = "redacted";
    $resourceGroup = "redacted";
    $webAppName = "redacted";
    
    $staging = $false
    
    # 2. get a list of instances:
    
    $token = Get-AzAccessToken;
    $RequestHeader = @{
        Authorization  = "Bearer $($token.Token)";
        'Content-Type' = "application/json";
    }
    if ($staging) {
        $instancesUrl = "https://management.azure.com/subscriptions/$($subscriptionId)/resourcegroups/$($resourceGroup)/providers/Microsoft.Web/sites/$($webAppName)/slots/staging/instances?api-version=2022-03-01";
    } else {
        $instancesUrl = "https://management.azure.com/subscriptions/$($subscriptionId)/resourcegroups/$($resourceGroup)/providers/Microsoft.Web/sites/$($webAppName)/instances?api-version=2022-03-01";
    }
    
    Invoke-RestMethod -Headers $RequestHeader -Uri $instancesUrl | Select-Object -ExpandProperty value | Select-Object -ExpandProperty properties;
    
    # 2. do a health-check on each instance:
    
    $instances = Invoke-RestMethod -Headers $RequestHeader -Uri $instancesUrl | Select-Object -ExpandProperty value | Select-Object -ExpandProperty properties;
    
    $webAppDomain = "$($webAppName).azurewebsites.net";
    $webAppUrl = "https://$($webAppDomain)/healthprobe.html";
    
    foreach ($instance in $instances)
    {
        $instanceId = $instance.Name
        "Going to check healthprobe URL on instance $($instanceId)";
        $s = New-Object Microsoft.PowerShell.Commands.WebRequestSession
        $c = New-Object System.Net.Cookie('ARRAffinity',$instanceId,'/',$webAppDomain)
        $s.Cookies.Add($c)
        Invoke-WebRequest -UseBasicParsing -Method Get -Uri $webAppUrl -WebSession $s
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search