如何为 linux 诊断设置 azurerm_virtual_machine_extension
How to setup azurerm_virtual_machine_extension for linux diagnostics
我一直在努力使用 Terraform 自动设置 linux 诊断设置。我可以创建扩展,但它似乎没有报告指标,如果我尝试在 Azure 门户中编辑它,它无法保存。希望大家指出我哪里做错了。
resource "azurerm_virtual_machine_extension" "vm_linux_diagnostics" {
name = "LinuxDiagnostics"
virtual_machine_id = azurerm_virtual_machine.vm.id
publisher = "Microsoft.Azure.Diagnostics"
type = "LinuxDiagnostic"
type_handler_version = "3.0"
auto_upgrade_minor_version = "true"
protected_settings = <<PROTECTED_SETTINGS
{
"storageAccountName": "${var.metrics_storage_account_name}",
"storageAccountSasToken": "${var.metrics_storage_account_token}"
}
PROTECTED_SETTINGS
settings = <<SETTINGS
{
"StorageAccount": "${var.metrics_storage_account_name}",
"ladCfg": {
"diagnosticMonitorConfiguration": {
"eventVolume": "Medium",
"metrics": {
"metricAggregation": [
{
"scheduledTransferPeriod": "PT1M"
},
{
"scheduledTransferPeriod": "PT1H"
}
],
"resourceId": "${azurerm_virtual_machine.vm.id}"
},
"performanceCounters": {
"performanceCounterConfiguration": [
{
"annotation": [
{
"displayName": "Filesystem % used space",
"locale": "en-us"
}
],
"class": "filesystem",
"condition": "IsAggregate=TRUE",
"counter": "percentusedspace",
"counterSpecifier": "/builtin/filesystem/percentusedspace",
"sampleRate": "PT15S",
"type": "builtin",
"unit": "Percent"
}
]
},
"syslogEvents": {
"syslogEventConfiguration": {}
}
},
"sampleRateInSeconds": 15
}
}
SETTINGS
}
答案是不再报告指标,我不得不安装 telegraf 并以这种方式报告磁盘使用指标。然后你制作一个 azurerm_monitor_metric_alert 如下所示:
resource "azurerm_monitor_metric_alert" "diskUsage" {
name = "vm-disk-usage-alert"
resource_group_name = var.resource_group
scopes = [azurerm_virtual_machine.vm.id]
window_size = "PT1H"
frequency = "PT30M"
criteria {
metric_namespace = "telegraf/disk"
metric_name = "used_percent"
aggregation = "Maximum"
operator = "GreaterThan"
threshold = 80
}
action {
action_group_id = var.action_group_id
}
}
我一直在努力使用 Terraform 自动设置 linux 诊断设置。我可以创建扩展,但它似乎没有报告指标,如果我尝试在 Azure 门户中编辑它,它无法保存。希望大家指出我哪里做错了。
resource "azurerm_virtual_machine_extension" "vm_linux_diagnostics" {
name = "LinuxDiagnostics"
virtual_machine_id = azurerm_virtual_machine.vm.id
publisher = "Microsoft.Azure.Diagnostics"
type = "LinuxDiagnostic"
type_handler_version = "3.0"
auto_upgrade_minor_version = "true"
protected_settings = <<PROTECTED_SETTINGS
{
"storageAccountName": "${var.metrics_storage_account_name}",
"storageAccountSasToken": "${var.metrics_storage_account_token}"
}
PROTECTED_SETTINGS
settings = <<SETTINGS
{
"StorageAccount": "${var.metrics_storage_account_name}",
"ladCfg": {
"diagnosticMonitorConfiguration": {
"eventVolume": "Medium",
"metrics": {
"metricAggregation": [
{
"scheduledTransferPeriod": "PT1M"
},
{
"scheduledTransferPeriod": "PT1H"
}
],
"resourceId": "${azurerm_virtual_machine.vm.id}"
},
"performanceCounters": {
"performanceCounterConfiguration": [
{
"annotation": [
{
"displayName": "Filesystem % used space",
"locale": "en-us"
}
],
"class": "filesystem",
"condition": "IsAggregate=TRUE",
"counter": "percentusedspace",
"counterSpecifier": "/builtin/filesystem/percentusedspace",
"sampleRate": "PT15S",
"type": "builtin",
"unit": "Percent"
}
]
},
"syslogEvents": {
"syslogEventConfiguration": {}
}
},
"sampleRateInSeconds": 15
}
}
SETTINGS
}
答案是不再报告指标,我不得不安装 telegraf 并以这种方式报告磁盘使用指标。然后你制作一个 azurerm_monitor_metric_alert 如下所示:
resource "azurerm_monitor_metric_alert" "diskUsage" {
name = "vm-disk-usage-alert"
resource_group_name = var.resource_group
scopes = [azurerm_virtual_machine.vm.id]
window_size = "PT1H"
frequency = "PT30M"
criteria {
metric_namespace = "telegraf/disk"
metric_name = "used_percent"
aggregation = "Maximum"
operator = "GreaterThan"
threshold = 80
}
action {
action_group_id = var.action_group_id
}
}