使用 ARM 模板的应用洞察警报
Application insights alerts using ARM templates
我正在尝试使用 ARM 模板配置应用程序洞察警报。我将以下内容用于服务器响应时间警报;
{
"name": "[variables('responseAlertName')]",
"type": "Microsoft.Insights/alertrules",
"apiVersion": "2014-04-01",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Insights/components', parameters('components_appinsights_name'))]"
],
"tags": {
"[concat('hidden-link:', resourceId('Microsoft.Insights/components', parameters('components_appinsights_name')))]": "Resource"
},
"properties": {
"name": "[variables('responseAlertName')]",
"description": "response time alert",
"isEnabled": true,
"condition": {
"$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.ThresholdRuleCondition, Microsoft.WindowsAzure.Management.Mon.Client",
"odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
"dataSource": {
"$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource, Microsoft.WindowsAzure.Management.Mon.Client",
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
"resourceUri": "[resourceId('microsoft.insights/components', parameters('components_appinsights_name'))]",
"metricName": "request.duration"
},
"threshold": "10",
"windowSize": "PT5M"
},
"actions": [
{
"$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction, Microsoft.WindowsAzure.Management.Mon.Client",
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
"sendToServiceOwners": true,
"customEmails": []
}
]
}
}
但问题是它被添加为门户中的 'Classic' 警报。应如何更改模板以便将警报添加为新警报而不是经典警报?
类型 "Microsoft.Insights/alertrules" 是经典指标,Classic alerts in Azure Monitor to retire in June 2019。
您可以使用新模块metric alert with the type "Microsoft.Insights/metricAlerts". See Metric Alert in the template,您将了解所有可以设置的属性。
有关旧警报和新警报之间区别的详细信息,请参阅Old and New alerting capabilities。
我最终做了以下事情;
{
"name": "[parameters('metricAlerts_web_response_time_alert_name')]",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"apiVersion": "2018-03-01",
"properties": {
"description": "web server response time",
"severity": 3,
"enabled": true,
"scopes": [
"[resourceId('Microsoft.Insights/components', parameters('components_appinsights_name'))]"
],
"evaluationFrequency": "Pt1m",
"windowSize": "Pt15m",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"name": "iard name",
"metricName": "requests/duration",
"dimensions": [],
"operator": "GreaterThan",
"threshold": 80,
"timeAggregation": "Average"
}
]
},
"actions": [
{
"actionGroupId": "[concat('subscriptions/', subscription().subscriptionId, '/resourcegroups/', resourceGroup().name, '/providers/microsoft.insights/actionGroups/', parameters('actionGroups_alerts_name'))]"
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Insights/actionGroups', parameters('actionGroups_alerts_name'))]",
"[resourceId('Microsoft.Insights/components', parameters('components_appinsights_name'))]"
]
},
您可以使用 Migration tool from the Azure portal to migrate all your configured alerts to newer alerts. You may also refer to the sample template mentioned in this 文档,甚至可以从 Azure 门户导出模板来检查表示。以下模板适合我:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"metricalerts_test_new_alerts_test_log_analytics_name": {
"defaultValue": "test-new-alerts-test-log-analytics",
"type": "String"
},
"webtests_test_new_alerts_test_log_analytics_externalid": {
"defaultValue": "/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourceGroups/alertrg/providers/microsoft.insights/webtests/test-new-alerts-test-log-analytics",
"type": "String"
},
"components_test_log_analytics_externalid": {
"defaultValue": "/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourceGroups/alertrg/providers/microsoft.insights/components/test-log-analytics",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "microsoft.insights/metricalerts",
"apiVersion": "2018-03-01",
"name": "[parameters('metricalerts_test_new_alerts_test_log_analytics_name')]",
"location": "global",
"tags": {
"hidden-link:/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourcegroups/alertrg/providers/microsoft.insights/components/test-log-analytics": "Resource",
"hidden-link:/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourcegroups/alertrg/providers/microsoft.insights/webtests/test-new-alerts-test-log-analytics": "Resource"
},
"properties": {
"description": "[concat('Automatically created alert rule for availability test \"', parameters('metricalerts_test_new_alerts_test_log_analytics_name'), '\"')]",
"severity": 1,
"enabled": true,
"scopes": [
"[parameters('webtests_test_new_alerts_test_log_analytics_externalid')]",
"[parameters('components_test_log_analytics_externalid')]"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT5M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria"
},
"actions": []
}
}
]
}
注意:经典警报迁移的停用日期已从最初宣布的 2019 年 6 月 30 日延长至 2019 年 8 月 31 日。
我正在尝试使用 ARM 模板配置应用程序洞察警报。我将以下内容用于服务器响应时间警报;
{
"name": "[variables('responseAlertName')]",
"type": "Microsoft.Insights/alertrules",
"apiVersion": "2014-04-01",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Insights/components', parameters('components_appinsights_name'))]"
],
"tags": {
"[concat('hidden-link:', resourceId('Microsoft.Insights/components', parameters('components_appinsights_name')))]": "Resource"
},
"properties": {
"name": "[variables('responseAlertName')]",
"description": "response time alert",
"isEnabled": true,
"condition": {
"$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.ThresholdRuleCondition, Microsoft.WindowsAzure.Management.Mon.Client",
"odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
"dataSource": {
"$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleMetricDataSource, Microsoft.WindowsAzure.Management.Mon.Client",
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
"resourceUri": "[resourceId('microsoft.insights/components', parameters('components_appinsights_name'))]",
"metricName": "request.duration"
},
"threshold": "10",
"windowSize": "PT5M"
},
"actions": [
{
"$type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.RuleEmailAction, Microsoft.WindowsAzure.Management.Mon.Client",
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
"sendToServiceOwners": true,
"customEmails": []
}
]
}
}
但问题是它被添加为门户中的 'Classic' 警报。应如何更改模板以便将警报添加为新警报而不是经典警报?
类型 "Microsoft.Insights/alertrules" 是经典指标,Classic alerts in Azure Monitor to retire in June 2019。
您可以使用新模块metric alert with the type "Microsoft.Insights/metricAlerts". See Metric Alert in the template,您将了解所有可以设置的属性。
有关旧警报和新警报之间区别的详细信息,请参阅Old and New alerting capabilities。
我最终做了以下事情;
{
"name": "[parameters('metricAlerts_web_response_time_alert_name')]",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"apiVersion": "2018-03-01",
"properties": {
"description": "web server response time",
"severity": 3,
"enabled": true,
"scopes": [
"[resourceId('Microsoft.Insights/components', parameters('components_appinsights_name'))]"
],
"evaluationFrequency": "Pt1m",
"windowSize": "Pt15m",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"name": "iard name",
"metricName": "requests/duration",
"dimensions": [],
"operator": "GreaterThan",
"threshold": 80,
"timeAggregation": "Average"
}
]
},
"actions": [
{
"actionGroupId": "[concat('subscriptions/', subscription().subscriptionId, '/resourcegroups/', resourceGroup().name, '/providers/microsoft.insights/actionGroups/', parameters('actionGroups_alerts_name'))]"
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Insights/actionGroups', parameters('actionGroups_alerts_name'))]",
"[resourceId('Microsoft.Insights/components', parameters('components_appinsights_name'))]"
]
},
您可以使用 Migration tool from the Azure portal to migrate all your configured alerts to newer alerts. You may also refer to the sample template mentioned in this 文档,甚至可以从 Azure 门户导出模板来检查表示。以下模板适合我:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"metricalerts_test_new_alerts_test_log_analytics_name": {
"defaultValue": "test-new-alerts-test-log-analytics",
"type": "String"
},
"webtests_test_new_alerts_test_log_analytics_externalid": {
"defaultValue": "/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourceGroups/alertrg/providers/microsoft.insights/webtests/test-new-alerts-test-log-analytics",
"type": "String"
},
"components_test_log_analytics_externalid": {
"defaultValue": "/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourceGroups/alertrg/providers/microsoft.insights/components/test-log-analytics",
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "microsoft.insights/metricalerts",
"apiVersion": "2018-03-01",
"name": "[parameters('metricalerts_test_new_alerts_test_log_analytics_name')]",
"location": "global",
"tags": {
"hidden-link:/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourcegroups/alertrg/providers/microsoft.insights/components/test-log-analytics": "Resource",
"hidden-link:/subscriptions/xxxxx-xxxx-xxx-xxx-xxxxxxxx/resourcegroups/alertrg/providers/microsoft.insights/webtests/test-new-alerts-test-log-analytics": "Resource"
},
"properties": {
"description": "[concat('Automatically created alert rule for availability test \"', parameters('metricalerts_test_new_alerts_test_log_analytics_name'), '\"')]",
"severity": 1,
"enabled": true,
"scopes": [
"[parameters('webtests_test_new_alerts_test_log_analytics_externalid')]",
"[parameters('components_test_log_analytics_externalid')]"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT5M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria"
},
"actions": []
}
}
]
}
注意:经典警报迁移的停用日期已从最初宣布的 2019 年 6 月 30 日延长至 2019 年 8 月 31 日。