【问题标题】:Use terraform to add a VM to the new Azure Monitoring (without OMS Agent)使用 terraform 将 VM 添加到新的 Azure 监控(无 OMS 代理)
【发布时间】:2022-09-28 01:04:03
【问题描述】:

当我使用带有此答案Enable Azure Monitor for existing Virtual machines using terraform 的 VM 的 OMS 解决方案配置 Azure 监控时,我注意到此功能已被弃用,Azure 更喜欢您迁移到新的监控解决方案(不使用日志分析代理)。

Azure 允许我使用此 GUI 配置 VM 监控,但我想使用 terraform 来配置。

我必须在 terraform 中使用特定的设置来实现这一点吗? (顺便说一句,我正在使用 Linux VM)

    标签: 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

    【讨论】:

      猜你喜欢
      • 2018-10-30
      • 2021-04-02
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 2016-10-13
      • 2021-10-10
      • 2023-03-30
      • 2014-07-20
      相关资源
      最近更新 更多