【问题标题】:Setup Linux Diagnostic extension using ARM templates使用 ARM 模板设置 Linux 诊断扩展
【发布时间】:2019-01-28 09:27:50
【问题描述】:

您好,我正在尝试创建一个 ARM 模板,以便在我的 Linux VM 上设置 Azure Linux 诊断扩展,使用 ARM 模板来监控挂载点。

我指的是以下文档来实现相同的目的:

https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-template

但是,通过研究 Microsoft 提供的其他文档,我发现 Windows 和 Linux 诊断代理具有不同的监控参数。

Windows:https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-windows

Linux:https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/diagnostics-linux

适用于 Windows 的 ARM JSON 是:

"resources": [
    {
        "name": "Microsoft.Insights.VMDiagnosticsSettings",
        "type": "extensions",
        "location": "[resourceGroup().location]",
        "apiVersion": "2015-06-15",
        "dependsOn": [
            "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
        ],
        "tags": {
            "displayName": "AzureDiagnostics"
        },
        "properties": {
            "publisher": "Microsoft.Azure.Diagnostics",
            "type": "IaaSDiagnostics",
            "typeHandlerVersion": "1.5",
            "autoUpgradeMinorVersion": true,
            "settings": {
                "xmlCfg": "[base64(concat(variables('wadcfgxstart'), variables('wadmetricsresourceid'), variables('vmName'), variables('wadcfgxend')))]",
                "storageAccount": "[parameters('existingdiagnosticsStorageAccountName')]"
            },
            "protectedSettings": {
                "storageAccountName": "[parameters('existingdiagnosticsStorageAccountName')]",
                "storageAccountKey": "[listkeys(variables('accountid'), '2015-05-01-preview').key1]",
                "storageAccountEndPoint": "https://core.windows.net"
            }
        }
    }
]

有人知道 Linux 诊断代理的“settings”和“protectedSettings”是什么吗?

【问题讨论】:

  • 所以啊,你贴的链接有什么问题,它有所有的设置?
  • 我假设 Linux 没有 xmlcfg。如果您看到它具有 wadcfgxstart、wadmetricsresourceid 等的变量,这些变量是 windows 独有的,而不是 LInux 独有的。 Linux 使用 LAD。

标签: linux azure azure-resource-manager arm-template


【解决方案1】:

我在这里回答我自己的问题。

与适用于 Windows 的 Azure 诊断代理比较时的差异是:

  1. typeproperties 下。这将对应于LinuxDiagnostic 而不是IaaSDiagnostics
  2. typehandlerversion:这基本上是LAD版本。最新的是3.0
  3. protectedSettings:可以这样写:

    { "storageAccountName" : "the storage account to receive data", "storageAccountEndPoint": "the hostname suffix for the cloud for this account", "storageAccountSasToken": "SAS access token", "mdsdHttpProxy": "HTTP proxy settings", "sinksConfig": { ... } }

mdsdHttpProxy 和 sinksConfig 参数是可选的,只有在进行了相同的设置后才需要配置。可以在here(在受保护的设置部分)找到更多信息。

  1. settings: 这将采用以下形式:

    { "ladCfg": { ... }, "perfCfg": { ... }, "fileLogs": { ... }, "StorageAccount": "the storage account to receive data", "mdsdHttpProxy" : "" }

每一项都已在here(在公共场合)进行了详细讨论。

对我有用的 Linux 诊断扩展示例如下:

"resources": [
    {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "apiVersion": "2017-12-01",
      "location": "[resourceGroup().location]",
      "name": "[concat(variables('vmName'), '/Microsoft.Insights.VMDiagnosticSettings')]",
      "tags": {
        "displayName": "AzureDiagnostics"
      },
      "properties": {
        "publisher": "Microsoft.Azure.Diagnostics",
        "type": "LinuxDiagnostic",
        "autoUpgradeMinorVersion": true,
        "typeHandlerVersion": "3.0",
        "protectedSettings": {
          "storageAccountName": "[parameters('storageAccountName')]",
          "storageAccountEndPoint": "https://core.windows.net",
          "storageAccountSasToken": "[parameters('sasToken')]"
        },
        "settings": {
          "StorageAccount": "[parameters('storageAccountName')]",
          "ladCfg": {
            "diagnosticMonitorConfiguration": {
              "syslogEvents": {},
              "sampleRateInSeconds": 15,
              "eventVolume": "Medium",
              "metrics": {
                "resourceId": "[resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))]",
                "metricAggregation": [
                  { "scheduledTransferPeriod": "PT1H" },
                  { "scheduledTransferPeriod": "PT1M" }
                ]
              },
              "performanceCounters": {
                "performanceCounterConfiguration": [
                  {
                    "annotation": [
                      {
                        "displayName": "Filesystem % free space",
                        "locale": "en-us"
                      }
                    ],
                    "class": "filesystem",
                    "condition": "IsAggregate=TRUE",
                    "counter": "percentfreespace",
                    "counterSpecifier": "/builtin/filesystem/percentfreespace",
                    "type": "builtin",
                    "unit": "Percent"
                  },
                  {
                    "annotation": [
                      {
                        "displayName": "Filesystem % used space",
                        "locale": "en-us"
                      }
                    ],
                    "class": "filesystem",
                    "condition": "IsAggregate=TRUE",
                    "counter": "percentusedspace",
                    "counterSpecifier": "/builtin/filesystem/percentusedspace",
                    "type": "builtin",
                    "unit": "Percent"
                  },
                  {
                    "annotation": [
                      {
                        "displayName": "Filesystem used space",
                        "locale": "en-us"
                      }
                    ],
                    "class": "filesystem",
                    "condition": "IsAggregate=TRUE",
                    "counter": "usedspace",
                    "counterSpecifier": "/builtin/filesystem/usedspace",
                    "type": "builtin",
                    "unit": "Bytes"
                  },
                  {
                    "annotation": [
                      {
                        "displayName": "Filesystem read bytes/sec",
                        "locale": "en-us"
                      }
                    ],
                    "class": "filesystem",
                    "condition": "IsAggregate=TRUE",
                    "counter": "bytesreadpersecond",
                    "counterSpecifier": "/builtin/filesystem/bytesreadpersecond",
                    "type": "builtin",
                    "unit": "CountPerSecond"
                  },
                  {
                    "annotation": [
                      {
                        "displayName": "Filesystem free space",
                        "locale": "en-us"
                      }
                    ],
                    "class": "filesystem",
                    "condition": "IsAggregate=TRUE",
                    "counter": "freespace",
                    "counterSpecifier": "/builtin/filesystem/freespace",
                    "type": "builtin",
                    "unit": "Bytes"
                  },
                  {
                    "annotation": [
                      {
                        "displayName": "Filesystem % free inodes",
                        "locale": "en-us"
                      }
                    ],
                    "class": "filesystem",
                    "condition": "IsAggregate=TRUE",
                    "counter": "percentfreeinodes",
                    "counterSpecifier": "/builtin/filesystem/percentfreeinodes",
                    "type": "builtin",
                    "unit": "Percent"
                  }
                ]
              }
            }
          }
        }
      }
    }
  ]

【讨论】:

  • 嗨@Akash Masand,你遇到过这种错误吗?我正在尝试使用您的示例,但是在查看 VM 的诊断设置时遇到了错误:TypeError: i.ladCfg(...).sampleRateInSeconds is not a function 我正在尝试不同的迭代,但我总是变得相似尝试通过 ARM 设置诊断扩展时出错。
【解决方案2】:
# Download the sample Public settings. (You could also use curl or any web browser)
wget https://raw.githubusercontent.com/Azure/azure-linux-extensions/master/Diagnostic/tests/lad_2_3_compatible_portal_pub_settings.json -O portal_public_settings.json

# Build the VM resource ID. Replace storage account name and resource ID in the public settings.
my_vm_resource_id=$(az vm show -g $my_resource_group -n $my_linux_vm --query "id" -o tsv)
sed -i "s#__DIAGNOSTIC_STORAGE_ACCOUNT__#$my_diagnostic_storage_account#g" portal_public_settings.json
sed -i "s#__VM_RESOURCE_ID__#$my_vm_resource_id#g" portal_public_settings.json

# Build the protected settings (storage account SAS token)
my_diagnostic_storage_account_sastoken=$(az storage account generate-sas --account-name $my_diagnostic_storage_account --expiry 2037-12-31T23:59:00Z --permissions wlacu --resource-types co --services bt -o tsv)
my_lad_protected_settings="{'storageAccountName': '$my_diagnostic_storage_account', 'storageAccountSasToken': '$my_diagnostic_storage_account_sastoken'}"

# Finallly tell Azure to install and enable the extension
az vm extension set --publisher Microsoft.Azure.Diagnostics --name LinuxDiagnostic --version 3.0 --resource-group $my_resource_group --vm-name $my_linux_vm --protected-settings "${my_lad_protected_settings}" --settings portal_public_settings.json

受保护的设置映射到 json 中的受保护设置。该 json 文件应映射到不受保护的设置

如果您阅读了这篇文章,它还会告诉您如何配置其他东西,例如 sinks\counters\etc

【讨论】:

  • 嘿,我正在尝试使用 ARM 模板来执行此操作。我可以使用 Azure CLI 做到这一点,但这不是我想要实现的。我需要使用 ARM 模板来完成此操作。
  • 我已经告诉你怎么做,受保护的设置映射到受保护的设置,设置映射到设置
  • 我知道。但我正试图通过 ARM 模板实现同样的目标。
  • 你在拖钓还是什么?只需以这个例子并填写模板中的值即可。示例中的值映射到模板中的值
  • 今天早上试过了。不工作。模板部署一直持续到超时。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-21
  • 2019-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多