通过ARM模板启用VM基本度量标准

时间:2016-08-03 01:08:14

标签: azure azure-virtual-machine azure-resource-manager arm-template

我正在尝试通过ARM模板为Ubunutu 14.04计算机启用基本指标收集

我在模板的vm部分有一个类似下面的部分。

"resources": [  {
      "name": "Microsoft.Insights.VMDiagnosticsSettings",
      "type": "extensions",
      "location": "[resourceGroup().location]",
      "apiVersion": "[variables('apiVersion')]",
      "dependsOn": [
        "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
      ],
      "tags": {
        "displayName": "AzureDiagnostics"
      },
      "properties": {
        "publisher": "Microsoft.OSTCExtensions",
        "type": "LinuxDiagnostic",
        "typeHandlerVersion": "2.3",
        "autoUpgradeMinorVersion": true,
        "protectedSettings": {
          "storageAccountName": "[parameters('metricsStorageAccountName')]",
          "storageAccountKey": "[listkeys(variables('accountid'), variables('apiVersion')).key1]",
          "storageAccountEndPoint": "https://core.windows.net"
        }
      }
    }]

我尝试从门户网站导出模板以尝试对该方法进行反向工程,但导出的模板不包含任何诊断部分。

还需要什么才能启用基本指标,并且我能够在虚拟机上创建警报?

1 个答案:

答案 0 :(得分:3)

导出模板选项不包含LinuxDiagnostics扩展名,我们必须手动将其添加到模板中。

您指定的模板:

"resources": [  {
  "name": "Microsoft.Insights.VMDiagnosticsSettings",
  "type": "extensions",
  "location": "[resourceGroup().location]",
  "apiVersion": "[variables('apiVersion')]",
  "dependsOn": [
    "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
  ],
  "tags": {
    "displayName": "AzureDiagnostics"
  },
  "properties": {
    "publisher": "Microsoft.OSTCExtensions",
    "type": "LinuxDiagnostic",
    "typeHandlerVersion": "2.3",
    "autoUpgradeMinorVersion": true,
    "protectedSettings": {
      "storageAccountName": "[parameters('metricsStorageAccountName')]",
      "storageAccountKey": "[listkeys(variables('accountid'), variables('apiVersion')).key1]",
      "storageAccountEndPoint": "https://core.windows.net"
    }
  }
}]

会添加扩展程序,但您无法在azure门户网站上查看监控图表,也无法创建任何警报规则,如此处的支持文档中所述(在重要通知标题下) : Linux Diagnostics Github page

但是有一种解决方法可以添加扩展程序以便能够查看图形。为此,我创建了2个VM,并使用门户在第一个VM上添加了扩展,第二个VM使用了如上所示的模板格式。接下来,我使用了Azure CLI,获得了JSON格式的扩展细节。以下是第一个VM扩展的详细信息:

C:\Users\gkapagun\Downloads\ExportedTemplate>azure vm extension get --json <resource-group-name> <vm-name>
[
  {
    "id": "/subscriptions/<subscription_id>/resourceGroups/<resource-group-name>/providers/Microsoft.Compute/virtualMachines/<vm-name>/extensions/LinuxDiagnostic",
    "name": "LinuxDiagnostic",
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "location": "eastus2",
    "publisher": "Microsoft.OSTCExtensions",
    "virtualMachineExtensionType": "LinuxDiagnostic",
    "typeHandlerVersion": "2.3",
    "autoUpgradeMinorVersion": true,
    "settings": {
      "StorageAccount": "<storage-account-name>",
      "xmlCfg": "PFdhZENmZz48RGlhZ25vc3RpY01vbml0b3JDb25maWd1cmF0aW9uIG92ZXJhbGxRdW90YUluTUI9IjQwOTYiPjxEaWFnbm9zdGljSW5mcmFzdHJ1Y3R1cmVMb2dzIHNjaGVkdWxlZFRyYW5zZmVyUGVyaW9kPSJQVDFNIiBzY2hlZHVsZWRUcmFuc2ZlckxvZ0xldmVsRmlsdGVyPSJXYXJuaW5nIi8+PFBlcmZvcm1hbmNlQ291bnRlcnMgc2NoZWR1bGVkVHJhbnNmZXJQZXJpb2Q9IlBUMU0iPjxQZXJmb3JtYW5jZUNvdW50ZXJDb25maWd1cmF0aW9uIGNvdW50ZXJTcGVjaWZpZXI9IlxNZW1vcnlcQXZhaWxhYmxlTWVtb3J5IiBzYW1wbGVSYXRlPSJQVDE1UyIgdW5pdD0iQnl0ZXMiPjxhbm5vdGF0aW9uIGRpc3BsYXlOYW1lPSJNZW1vcnkgYXZhaWxhYmxlIiBsb2NhbGU9ImVuLXVzIi8+PC9QZXJmb3JtYW5jZUNvdW50ZXJDb25maWd1cmF0aW9uP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QZXJpb2Q9IlBUMUgiLz48TWV0cmljQWdncmVnYXRpb24gc2NoZWR1bGVkVHJhbnNmZXJQZXJpb2Q9IlBUMU0iLz48L01ldHJpY3M+PC9EaWFnbm9zdGljTW9uaXRvckNvbmZpZ3VyYXRpb24+PC9XYWRDZmc+"
    },
    "provisioningState": "Succeeded"
  }
]

C:\Users\gkapagun\Downloads\ExportedTemplate>

对于第二个VM:

C:\Users\gkapagun\Downloads\ExportedTemplate>azure vm extension get --json <resource-group-name> <vm-name>
[
  {
    "id": "/subscriptions/<subscription_id>/resourceGroups/<resource-group-name>/providers/Microsoft.Compute/virtualMachines/<vm-name>/extensions/LinuxDiagnostic",
    "name": "LinuxDiagnostic",
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "location": "eastus2",
    "publisher": "Microsoft.OSTCExtensions",
    "virtualMachineExtensionType": "LinuxDiagnostic",
    "typeHandlerVersion": "2.3",
    "autoUpgradeMinorVersion": true,
    "provisioningState": "Succeeded"
  }
]

C:\Users\gkapagun\Downloads\ExportedTemplate>

区别在于提供设置的方式,尤其是xmlCfg密钥。

xmlCfg只不过是一个base64编码的字符串,其中包含如何收集指标。在解码时,我能够获得以下XML数据:

<?xml version="1.0" encoding="UTF-8"?>
<WadCfg>
   <DiagnosticMonitorConfiguration overallQuotaInMB="4096">
      <DiagnosticInfrastructureLogs scheduledTransferPeriod="PT1M" scheduledTransferLogLevelFilter="Warning" />
      <PerformanceCounters scheduledTransferPeriod="PT1M">
         <PerformanceCounterConfiguration counterSpecifier="\Memory\AvailableMemory" sampleRate="PT15S" unit="Bytes">
            <annotation displayName="Memory available" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Memory\PercentAvailableMemory" sampleRate="PT15S" unit="Percent">
            <annotation displayName="Mem. percent available" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Memory\UsedMemory" sampleRate="PT15S" unit="Bytes">
            <annotation displayName="Memory used" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Memory\PercentUsedMemory" sampleRate="PT15S" unit="Percent">
            <annotation displayName="Memory percentage" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Memory\PercentUsedByCache" sampleRate="PT15S" unit="Percent">
            <annotation displayName="Mem. used by cache" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Memory\PagesPerSec" sampleRate="PT15S" unit="CountPerSecond">
            <annotation displayName="Pages" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Memory\PagesReadPerSec" sampleRate="PT15S" unit="CountPerSecond">
            <annotation displayName="Page reads" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Memory\PagesWrittenPerSec" sampleRate="PT15S" unit="CountPerSecond">
            <annotation displayName="Page writes" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Memory\AvailableSwap" sampleRate="PT15S" unit="Bytes">
            <annotation displayName="Swap available" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Memory\PercentAvailableSwap" sampleRate="PT15S" unit="Percent">
            <annotation displayName="Swap percent available" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Memory\UsedSwap" sampleRate="PT15S" unit="Bytes">
            <annotation displayName="Swap used" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Memory\PercentUsedSwap" sampleRate="PT15S" unit="Percent">
            <annotation displayName="Swap percent used" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Processor\PercentIdleTime" sampleRate="PT15S" unit="Percent">
            <annotation displayName="CPU idle time" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Processor\PercentUserTime" sampleRate="PT15S" unit="Percent">
            <annotation displayName="CPU user time" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Processor\PercentNiceTime" sampleRate="PT15S" unit="Percent">
            <annotation displayName="CPU nice time" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Processor\PercentPrivilegedTime" sampleRate="PT15S" unit="Percent">
            <annotation displayName="CPU privileged time" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Processor\PercentInterruptTime" sampleRate="PT15S" unit="Percent">
            <annotation displayName="CPU interrupt time" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Processor\PercentDPCTime" sampleRate="PT15S" unit="Percent">
            <annotation displayName="CPU DPC time" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Processor\PercentProcessorTime" sampleRate="PT15S" unit="Percent">
            <annotation displayName="CPU percentage guest OS" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\Processor\PercentIOWaitTime" sampleRate="PT15S" unit="Percent">
            <annotation displayName="CPU IO wait time" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk\BytesPerSecond" sampleRate="PT15S" unit="BytesPerSecond">
            <annotation displayName="Disk total bytes" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk\ReadBytesPerSecond" sampleRate="PT15S" unit="BytesPerSecond">
            <annotation displayName="Disk read guest OS" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk\WriteBytesPerSecond" sampleRate="PT15S" unit="BytesPerSecond">
            <annotation displayName="Disk write guest OS" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk\TransfersPerSecond" sampleRate="PT15S" unit="CountPerSecond">
            <annotation displayName="Disk transfers" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk\ReadsPerSecond" sampleRate="PT15S" unit="CountPerSecond">
            <annotation displayName="Disk reads" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk\WritesPerSecond" sampleRate="PT15S" unit="CountPerSecond">
            <annotation displayName="Disk writes" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk\AverageReadTime" sampleRate="PT15S" unit="Seconds">
            <annotation displayName="Disk read time" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk\AverageWriteTime" sampleRate="PT15S" unit="Seconds">
            <annotation displayName="Disk write time" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk\AverageTransferTime" sampleRate="PT15S" unit="Seconds">
            <annotation displayName="Disk transfer time" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\PhysicalDisk\AverageDiskQueueLength" sampleRate="PT15S" unit="Count">
            <annotation displayName="Disk queue length" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\BytesTransmitted" sampleRate="PT15S" unit="Bytes">
            <annotation displayName="Network out guest OS" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\BytesReceived" sampleRate="PT15S" unit="Bytes">
            <annotation displayName="Network in guest OS" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\PacketsTransmitted" sampleRate="PT15S" unit="Count">
            <annotation displayName="Packets sent" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\PacketsReceived" sampleRate="PT15S" unit="Count">
            <annotation displayName="Packets received" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\BytesTotal" sampleRate="PT15S" unit="Bytes">
            <annotation displayName="Network total bytes" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\TotalRxErrors" sampleRate="PT15S" unit="Count">
            <annotation displayName="Packets received errors" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\TotalTxErrors" sampleRate="PT15S" unit="Count">
            <annotation displayName="Packets sent errors" locale="en-us" />
         </PerformanceCounterConfiguration>
         <PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\TotalCollisions" sampleRate="PT15S" unit="Count">
            <annotation displayName="Network collisions" locale="en-us" />
         </PerformanceCounterConfiguration>
      </PerformanceCounters>
      <Metrics resourceId="<vm URI>">
         <MetricAggregation scheduledTransferPeriod="PT1H" />
         <MetricAggregation scheduledTransferPeriod="PT1M" />
      </Metrics>
   </DiagnosticMonitorConfiguration>
</WadCfg>

因此扩展的资源模板必须是:

{
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "name": "[concat(parameters('virtualMachine_name'),'/LinuxDiagnostic')]",
    "apiVersion": "2015-05-01-preview",
    "location": "[resourceGroup().location]",
    "dependsOn": ["[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachine_name'))]"],
    "properties": {
        "publisher": "Microsoft.OSTCExtensions",
        "type": "LinuxDiagnostic",
        "typeHandlerVersion": "2.3",
        "autoUpgradeMinorVersion":true,
        "settings": {
            "storageAccount" : "[parameters('storageAccount_name')]",
            "xmlCfg" : "[parameters('extensionXMLCfg')]"
        },
        "protectedSettings": {
            "storageAccountName": "[parameters('storageAccount_name')]",
            "storageAccountKey": "<key>",
            "storageAccountEndPoint": "https://core.windows.net"
        }
    }
}

参数extensionXMLCfg是指定了VM URI的base64编码的XML数据。

使用此功能,您还可以在模板中添加警报规则。