azure - 为所有资源创建 Application Insights 警报

标签 azure azure-application-insights azure-resource-manager

是否有一种简单的方法可以使用 Application Insights 将相同的警报添加到所有资源?

我想创建服务器异常计数/阈值警报,但不想手动更新 20 多个 AI 资源。

此外,随着规则和需求的变化,如果能够做点什么那就太好了。我认为 ARM 可能会提供一种方法来提取资源,然后迭代每个资源以创建警报。还有其他想法吗?或者提示?

最佳答案

您可以使用 Azure Power Shell 或模板来执行此操作。

对于模板:你可以检查这个template .

{
      "name": "[variables('responseAlertName')]",
      "type": "Microsoft.Insights/alertrules",
      "apiVersion": "2014-04-01",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[resourceId('Microsoft.Insights/components', variables('appInsName'))]"
      ],
      "tags": {
        "[concat('hidden-link:', resourceId('Microsoft.Insights/components', variables('appInsName')))]": "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', variables('appInsName'))]",
            "metricName": "request.duration"
          },
          "threshold": "[parameters('responseTime')]",
          "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": []
          }
        ]
      }
    } 

您还可以查看此 link .

对于 PowerShell,您可以使用命令 Add-AzureRmLogAlertRule 。例如:

Add-AzureRmLogAlertRule -Name "logRule" -Location "East US" -ResourceGroup "Default-Web-EastUS" -OperationName "Create" -TargetResourceId "/subscriptions/abbfb07c-6c93-40be-bc9b-4f0deba32f4c/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/misitiooeltuyo" -Description "My log rule"

关于azure - 为所有资源创建 Application Insights 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48980157/

相关文章:

powershell - 如何使用 PowerShell 将地址空间添加到 Azure Rm 虚拟网络?

azure 管道cron未运行

Azure 缓存(预览版)OutputCache - CPU 高 - 慢

azure - 禁用属性不适用于 Azure Functions

azure - Application Insights 可用性测试失败,返回 200 OK,错误代码为 "System.UriFormatException: Invalid URI: The format of the URI could not be determined."

c# - 检测 Application Insights 是否(以及为什么)可以将遥测数据发送到 Azure

azure - 如何从 Azure 容器应用服务使用 Azure ACR 进行身份验证

azure - 在 Azure Monitor 中查看 opentelemetry 跟踪

arrays - 如何循环访问资源的多个数组

azure - 无法在 Azure 部署中使用 bicepparam 文件