可以通过设置应用服务计划的自动扩展规则来实现在发生Http 500错误时自动扩展。
以下是一个示例代码,展示如何根据Http 500错误自动扩展应用程序服务计划:
{
"name": "auto-scale-rule",
"location": "",
"properties": {
"metricTrigger": {
"metricName": "\\ApplicationInsight\\Server Exceptions\\Exception Rate per Instance",
"metricNamespace": "",
"operator": "GreaterThan",
"threshold": 1,
"timeAggregation": "Average",
"statistic": "Count"
},
"scaleAction": {
"direction": "Increase",
"type": "ChangeCount",
"value": "1",
"cooldown": "PT5M"
},
"timeGrain": "PT1M",
"timeWindow": "PT5M",
"enabled": true
}
}
上述代码中,我们创建了一个名为“auto-scale-rule”的自动扩展规则。该规则定期检查服务器异常率这个指标。如果此指标的值超过了1,则应用程序服务计划会自动扩展,以增加实例的数量。此自动扩展规则还包含了一个冷却期,该期间内应用程序服务计划不会继续扩展。