azure - 如何使用 Terraform 使用 Log Workspace 实现 Azure Monitoring Alert VM Heartbeat
问题描述
需要使用 KQL/Kusto 查询在 Azure 监控中实现一系列警报。这是非常基本的,例如心跳、可用磁盘空间(基于代理输出到日志工作区)。
查看 Terraform 文档,我不确定要使用哪些资源。我希望我需要先在资源中构建查询,然后再构建警报资源。但是,查看文档似乎应该将查询添加到此资源中。
无论如何,如果有人能分享一个为虚拟机 Win/linux 实现天蓝色监视器警报的示例,那就太棒了。
解决方案
谢谢用户P。发布您的建议作为帮助其他社区成员的答案。
azurerm_monitor_scheduled_query_rules_alert
- 管理 Azure Monitor 中的 AlertingAction 计划查询规则资源。
resource "azurerm_resource_group" "example" {
name = "monitoring-resources"
location = "West Europe"
}
resource "azurerm_application_insights" "example" {
name = "appinsights"
location = var.location
resource_group_name = azurerm_resource_group.example.name
application_type = "web"
}
resource "azurerm_application_insights" "example2" {
name = "appinsights2"
location = var.location
resource_group_name = azurerm_resource_group.example.name
application_type = "web"
}
# Example: Alerting Action with metric trigger
resource "azurerm_monitor_scheduled_query_rules_alert" "example" {
name = format("%s-queryrule", var.prefix)
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
action {
action_group = []
email_subject = "Email Header"
custom_webhook_payload = "{}"
}
data_source_id = azurerm_application_insights.example.id
description = "Query results grouped into AggregatedValue; alert when results cross threshold"
enabled = true
# Count all requests with server error result code grouped into 5-minute bins by HTTP operation
query = <<-QUERY
requests
| where tolong(resultCode) >= 500
| summarize AggregatedValue = count() by operation_Name, bin(timestamp, 5m)
QUERY
severity = 1
frequency = 5
time_window = 30
trigger {
operator = "GreaterThan"
threshold = 3
metric_trigger {
operator = "GreaterThan"
threshold = 1
metric_trigger_type = "Total"
metric_column = "operation_Name"
}
}
}
您可以参考azurerm_monitor_scheduled_query_rules_alert和基于日志分析查询的支持警报
推荐阅读
- java - Apache FOP 对于不同的文档是线程安全的吗
- php - Laravel 在关系调用中投射一个字段
- linux-kernel - 内核源代码中 /proc/net/wireless 的实现在哪里
- django - Rest Framework 不会引发错误以响应本机
- java - 我应该传递什么上下文 WorkManager.getInstance().enqueue() ?(使用 MVVM + 房间数据库 + WorkManager)
- python - 列表字典和元组列表比较
- javascript - 适用于 iOS 和 iPad 的 Safari 上的 AR.js 视频播放问题
- django - Django反向页面对象编号
- google-analytics - Google Analytics 4,查询参数中带有电子邮件 ID 的页面路径的数据删除请求
- cross-validation - mlr3 中的留一法交叉验证