使用ARM模板设置Linux诊断扩展

时间:2018-08-22 07:06:38

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

嗨,我正在尝试创建一个ARM模板,以使用ARM模板来监视安装点,从而在我的Linux VM上设置Azure Linux Diagnostic扩展。

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

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

但是,在研究Microsoft提供的其他文档时,我发现Windows和Linux Diagnostic代理具有不同的监视参数。

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的Linux诊断代理的“ settings”和“ protectedSettings”是什么吗?

2 个答案:

答案 0 :(得分:4)

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

与Windows的Azure Diagnostic代理进行比较时的区别是:

  1. type,位于properties下。这将对应于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"
                  }
                ]
              }
            }
          }
        }
      }
    }
  ]

答案 1 :(得分:0)

# 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文件应映射到不受保护的设置

如果您阅读了该文章,它还会告诉您如何配置其他内容,例如接收器\计数器\等

相关问题