Using Application Health extension with virtual machine scale sets

Monitoring your application health is an important signal for managing and upgrading your deployment. Azure virtual machine scale sets provide support for rolling upgrades including automatic OS-image upgrades, which rely on health monitoring of the individual instances to upgrade your deployment. You can also use health extension to monitor the application health of each instance in your scale set and perform instance repairs using automatic instance repairs.

This article describes how you can use the Application Health extension to monitor the health of your applications deployed on virtual machine scale sets.

Prerequisites

This article assumes that you are familiar with:

When to use the Application Health extension

The Application Health extension is deployed inside a virtual machine scale set instance and reports on VM health from inside the scale set instance. You can configure the extension to probe on an application endpoint and update the status of the application on that instance. This instance status is checked by Azure to determine whether an instance is eligible for upgrade operations.

As the extension reports health from within a VM, the extension can be used in situations where external probes such as Application Health Probes (that utilize custom Azure Load Balancer probes) can’t be used.

Extension schema

The following JSON shows the schema for the Application Health extension. The extension requires at a minimum either a "tcp", "http" or "https" request with an associated port or request path respectively.

{
  "type": "extensions",
  "name": "HealthExtension",
  "apiVersion": "2018-10-01",
  "location": "<location>",  
  "properties": {
    "publisher": "Microsoft.ManagedServices",
    "type": "<ApplicationHealthLinux or ApplicationHealthWindows>",
    "autoUpgradeMinorVersion": true,
    "typeHandlerVersion": "1.0",
    "settings": {
      "protocol": "<protocol>",
      "port": "<port>",
      "requestPath": "</requestPath>",
      "intervalInSeconds": "5.0",
      "numberOfProbes": "1.0"
    }
  }
}  

Property values

Name Value / Example Data Type
apiVersion 2018-10-01 date
publisher Microsoft.ManagedServices string
type ApplicationHealthLinux (Linux), ApplicationHealthWindows (Windows) string
typeHandlerVersion 1.0 int

Settings

Name Value / Example Data Type
protocol http or https or tcp string
port Optional when protocol is http or https, mandatory when protocol is tcp int
requestPath Mandatory when protocol is http or https, not allowed when protocol is tcp string

Deploy the Application Health extension

There are multiple ways of deploying the Application Health extension to your scale sets as detailed in the examples below.

REST API

The following example adds the Application Health extension (with name myHealthExtension) to the extensionProfile in the scale set model of a Windows-based scale set.

PUT on `/subscriptions/subscription_id/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/myScaleSet/extensions/myHealthExtension?api-version=2018-10-01`
{
  "name": "myHealthExtension",
  "properties": {
    "publisher": "Microsoft.ManagedServices",
    "type": "ApplicationHealthWindows",
    "autoUpgradeMinorVersion": true,
    "typeHandlerVersion": "1.0",
    "settings": {
      "protocol": "<protocol>",
      "port": "<port>",
      "requestPath": "</requestPath>"
    }
  }
}

Use PATCH to edit an already deployed extension.

Azure PowerShell

Use the Add-AzVmssExtension cmdlet to add the Application Health extension to the scale set model definition.

The following example adds the Application Health extension to the extensionProfile in the scale set model of a Windows-based scale set. The example uses the new Az PowerShell module.

# Define the scale set variables
$vmScaleSetName = "myVMScaleSet"
$vmScaleSetResourceGroup = "myVMScaleSetResourceGroup"

# Define the Application Health extension properties
$publicConfig = @{"protocol" = "http"; "port" = 80; "requestPath" = "/healthEndpoint"};
$extensionName = "myHealthExtension"
$extensionType = "ApplicationHealthWindows"
$publisher = "Microsoft.ManagedServices"

# Get the scale set object
$vmScaleSet = Get-AzVmss `
  -ResourceGroupName $vmScaleSetResourceGroup `
  -VMScaleSetName $vmScaleSetName

# Add the Application Health extension to the scale set model
Add-AzVmssExtension -VirtualMachineScaleSet $vmScaleSet `
  -Name $extensionName `
  -Publisher $publisher `
  -Setting $publicConfig `
  -Type $extensionType `
  -TypeHandlerVersion "1.0" `
  -AutoUpgradeMinorVersion $True

# Update the scale set
Update-AzVmss -ResourceGroupName $vmScaleSetResourceGroup `
  -Name $vmScaleSetName `
  -VirtualMachineScaleSet $vmScaleSet

Azure CLI 2.0

Use az vmss extension set to add the Application Health extension to the scale set model definition.

The following example adds the Application Health extension to the scale set model of a Linux-based scale set.

az vmss extension set \
  --name ApplicationHealthLinux \
  --publisher Microsoft.ManagedServices \
  --version 1.0 \
  --resource-group <myVMScaleSetResourceGroup> \
  --vmss-name <myVMScaleSet> \
  --settings ./extension.json

The extension.json file content.

{
  "protocol": "<protocol>",
  "port": "<port>",
  "requestPath": "</requestPath>"
}

Troubleshoot

Extension execution output is logged to files found in the following directories:

C:\WindowsAzure\Logs\Plugins\Microsoft.ManagedServices.ApplicationHealthWindows\<version>\
/var/lib/waagent/Microsoft.ManagedServices.ApplicationHealthLinux-<extension_version>/status
/var/log/azure/applicationhealth-extension

The logs also periodically capture the application health status.

Next steps

Learn how to deploy your application on virtual machine scale sets.