【问题标题】:Use terraform to add a VM to the new Azure Monitoring (without OMS Agent)使用 terraform 将 VM 添加到新的 Azure 监控(无 OMS 代理)
【发布时间】:2022-09-28 01:04:03
【问题描述】:
标签:
azure
azure-virtual-machine
azure-monitoring
【解决方案1】:
对,那是正确的。 omsagent 已被标记为旧版,Azure 现在有一个名为“Azure Monitor agent”的新监控代理。下面给出的解决方案适用于 Linux,请查看适用于 Windows 机器的官方 Terraform 文档。
在 Terraform 中,我们需要做三件事来完成与 UI 相同的操作。
- azurerm_log_analytics_workspace
- azurerm_monitor_data_collection_rule
- azurerm_monitor_data_collection_rule_association
下面是示例代码:
resource "azurerm_log_analytics_workspace" "example" {
name = "example-workspace"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
}
resource "azurerm_monitor_data_collection_rule" "example" {
name = "example-rule"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
destinations {
log_analytics {
workspace_resource_id = azurerm_log_analytics_workspace.example.id
name = "test-destination-log"
}
}
data_flow {
streams = ["Microsoft-Perf"]
destinations = ["test-destination-log"]
}
data_sources {
performance_counter {
streams = ["Microsoft-Perf", "Microsoft-InsightsMetrics"]
sampling_frequency_in_seconds = 10
counter_specifiers = ["Processor(*)\\% Processor Time"]
name = "test-datasource-perfcounter"
}
}
description = "data collection rule example"
tags = {
foo = "bar"
}
}
resource "azurerm_monitor_data_collection_rule_association" "example1" {
name = "example1-dcra"
target_resource_id = azurerm_linux_virtual_machine.example.id
data_collection_rule_id = azurerm_monitor_data_collection_rule.example.id
description = "example"
}
参考:
monitor_data_collection_rule
monitor_data_collection_rule_association