Azure App Service provides a set of proactive tools that help you monitor and maintain the health of your application. These tools include "Auto-Heal", "Proactive CPU Monitoring", and "Crash Monitoring". In this document, we will guide you through the process of enabling them using PowerShell scripts, so you can easily automate them in your deployment pipeline.
Since each tool has its own configuration settings, we will discuss them individually to provide you with a clear understanding of how to enable and configure them for your app.
Auto-Heal is a feature in Azure App Service that automatically detects and resolves certain application failures. When Auto-Heal is triggered, it can take actions such as restarting the app, recycling the app pool, or sending an email notification.
Auto-Heal will save the config data in ARM definition.
config
section, you will see the detailed autoHealRules definition
[]
-> @()
,{"key":"value","key2":"value2"}
-> @{key="value"; key2="value2"}
$subscriptionId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # Your App's SubscriptionId
$webapp = "<WebAppName>" # Your App's Name
$rg = "<ResourceGroupName>" # Your App's Resource Group
$autohealRules = @{
triggers=@{
privateBytesInKB=888888;
requests=@{count=1000;timeInterval="00:02:39"}
statusCodesRange=@(@{
statusCodes= "400-502";
path="";
count=200;
timeInterval="00:01:00"
})
};
actions=@{actionType="Recycle";minProcessExecutionTime="00:01:39"};
}
$PropertiesObject = @{
autoHealEnabled = $true;
autoHealRules = $autohealRules
}
Set-AzResource -Properties $PropertiesObject -ResourceGroupName $rg -ResourceType Microsoft.Web/sites/config -ResourceName "$webapp/web" -ApiVersion 2018-02-01 -Force
$subscriptionId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # Your App's SubscriptionId
$webapp = "<WebAppName>" # Your App's Name
$rg = "<ResourceGroupName>" # Your App's Resource Group
$autohealRules = @{
triggers=@{
privateBytesInKB=0;
statusCodesRange=@(@{
statusCodes= "500-502";
path="";
count=200;
timeInterval="00:01:00"
})
};
actions=@{
actionType="CustomAction";
customAction=@{
exe="d:\home\data\DaaS\bin\DaasConsole.exe";
parameters="-CollectKillAnalyze ""Memory Dump"""
}
minProcessExecutionTime="00:01:39"
};
}
$PropertiesObject = @{
autoHealEnabled = $true;
autoHealRules = $autohealRules
}
Set-AzResource -Properties $PropertiesObject -ResourceGroupName $rg -ResourceType Microsoft.Web/sites/config -ResourceName "$webapp/web" -ApiVersion 2018-02-01 -Force
Proactive CPU Monitoring is a feature in Azure App Service that helps you monitor and optimize CPU usage for your app. When Proactive CPU Monitoring detects high CPU usage, it can take actions such as scaling in your app or sending an email notification.
Proactive CPU Monitoring will set the settings under extensions/daas/
, so you could use the API to set the configuration.
$subscriptionId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # Your App's SubscriptionId
$webapp = "<WebAppName>" # Your App's Name
$rg = "<ResourceGroupName>" # Your App's Resource Group
$path = "/subscriptions/$subscriptionId/resourceGroups/$rg/providers/Microsoft.Web/sites/$webapp/extensions/daas/api/cpumonitoring?api-Version=2015-08-01"
$monitoringSettings = @{
Mode="CollectAndKill";
MonitorDuration=15;
ThresholdSeconds=60;
CpuThreshold=90;
MonitorScmProcesses=$true;
MaxActions=10;
MaximumNumberOfHours=480;
}
$payload = $monitoringSettings | ConvertTo-Json
Invoke-AzRestMethod -Path $path -Method "POST" -Payload $payload
Once you set the config, you could navigate to UI and verify the settings.
Crash Monitoring is a feature in Azure App Service that helps you detect and diagnose application crashes. When Crash Monitoring is enabled, it logs detailed error information and failed requests, which you can use to investigate and troubleshoot app issues.
Crash Monitoring will save the data to App Settings.
# Get app configuration
$app = "<WebAppName>"
$rg = "<ResourceGroupName>"
$webapp=Get-AzWebApp -ResourceGroupName $rg -Name $app
# Copy app settings to a new Hashtable
$appSettings = @{}
ForEach ($item in $webapp.SiteConfig.AppSettings) {
$appSettings[$item.Name] = $item.Value
}
# Add or edit one or more app settings
$appSettings['WEBSITE_CRASHMONITORING_ENABLED'] = 'True'
$appSettings['WEBSITE_CRASHMONITORING_SETTINGS'] = '{"StartTimeUtc":"2023-05-16T00:36:00.000Z","MaxHours":360,"MaxDumpCount":2,"ExceptionFilter":"-f E053534F -f C00000FD.STACK_OVERFLOW"}'
$appSettings['WEBSITE_CRASHMONITORING_USE_DEBUGDIAG']='True'
$appSettings['WEBSITE_DAAS_STORAGE_CONNECTIONSTRING']='DefaultEndpointsProtocol=https;AccountName=windowtwpr7p;AccountKey=xxxxxxxxxxxxxxxxx;EndpointSuffix=core.windows.net'
# Save changes
Set-AzWebApp -ResourceGroupName $rg -Name $app -AppSettings $appSettings
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.