在 Linux 擴展集範本中使用客體計量自動調整規模
Azure 中有兩種收集自 VM 和擴展集的常用計量類型:主機計量和客體計量。 概括而言,如果您想要使用標準的 CPU、磁碟及網路計量,則適合採用主機計量。 不過,如果您需要更大的計量選取範圍,則應採用客體計量。
主機計量不需要額外的安裝,因為它們會由主機 VM 所收集,而客體計量需要您在客體 VM 中安裝 Windows Azure 診斷擴充功能或 Linux Azure 診斷擴充功能。 使用客體計量而非主機計量的一個常見原因是,客體計量會提供比主機計量更大的計量選取範圍。 記憶體耗用量計量即為一例,這類計量只能透過客體計量使用。 這裡會列出支援的主機度量,而常用的客體計量則列於這裡。 本文將說明如何根據適用於 Linux 擴展集的客體計量來修改基本可行的擴展集範本,以使用自動調整規模規則。
變更範本定義
在上一篇文章中,我們建立了基本的擴展集範本。 我們現在會使用先前的範本並加以修改以建立範本,使用以客體計量為基礎的自動調整規模來部署 Linux 擴展集。
首先,新增 storageAccountName
和 storageAccountSasToken
的參數。 診斷代理程式會將計量資料儲存於此儲存體帳戶的表格中。 從 Linux 診斷代理程式 3.0 版開始,不再支援使用儲存體存取金鑰。 請改用 SAS 權杖。
},
"adminPassword": {
"type": "securestring"
+ },
+ "storageAccountName": {
+ "type": "string"
+ },
+ "storageAccountSasToken": {
+ "type": "securestring"
}
},
接下來,修改擴展集 extensionProfile
以包含診斷擴充功能。 在此設定中,指定要從中收集計量之擴展集的資源識別碼,以及要用來儲存計量的儲存體帳戶和 SAS 權杖。 指定彙總計量資訊的頻率 (在此案例中為每隔一分鐘),以及要追蹤的計量 (在此案例中為已使用記憶體的百分比)。 如需此設定及已使用記憶體的百分比以外之計量的詳細資訊,請參閱這份文件。
}
}
]
+ },
+ "extensionProfile": {
+ "extensions": [
+ {
+ "name": "LinuxDiagnosticExtension",
+ "properties": {
+ "publisher": "Microsoft.Azure.Diagnostics",
+ "type": "LinuxDiagnostic",
+ "typeHandlerVersion": "3.0",
+ "settings": {
+ "StorageAccount": "[parameters('storageAccountName')]",
+ "ladCfg": {
+ "diagnosticMonitorConfiguration": {
+ "performanceCounters": {
+ "sinks": "WADMetricJsonBlob",
+ "performanceCounterConfiguration": [
+ {
+ "unit": "percent",
+ "type": "builtin",
+ "class": "memory",
+ "counter": "percentUsedMemory",
+ "counterSpecifier": "/builtin/memory/percentUsedMemory",
+ "condition": "IsAggregate=TRUE"
+ }
+ ]
+ },
+ "metrics": {
+ "metricAggregation": [
+ {
+ "scheduledTransferPeriod": "PT1M"
+ }
+ ],
+ "resourceId": "[resourceId('Microsoft.Compute/virtualMachineScaleSets', 'myScaleSet')]"
+ }
+ }
+ }
+ },
+ "protectedSettings": {
+ "storageAccountName": "[parameters('storageAccountName')]",
+ "storageAccountSasToken": "[parameters('storageAccountSasToken')]",
+ "sinksConfig": {
+ "sink": [
+ {
+ "name": "WADMetricJsonBlob",
+ "type": "JsonBlob"
+ }
+ ]
+ }
+ }
+ }
+ }
+ ]
}
}
}
最後,新增 autoscaleSettings
資源,以根據這些計量來設定自動調整規模。 此資源含有 dependsOn
子句,其會參考擴展集以確定擴展集存在,然後再嘗試自動調整其規模。 如果您選擇不同的計量來自動調整規模,可以使用來自診斷擴充功能設定的 counterSpecifier
,作為自動調整規模設定中的 metricName
。 如需自動調整規模設定的詳細資訊,請參閱自動調整規模的最佳做法和 Azure 監視器 REST API 參考文件 \(英文\)。
+ },
+ {
+ "type": "Microsoft.Insights/autoscaleSettings",
+ "apiVersion": "2015-04-01",
+ "name": "guestMetricsAutoscale",
+ "location": "[resourceGroup().location]",
+ "dependsOn": [
+ "Microsoft.Compute/virtualMachineScaleSets/myScaleSet"
+ ],
+ "properties": {
+ "name": "guestMetricsAutoscale",
+ "targetResourceUri": "[resourceId('Microsoft.Compute/virtualMachineScaleSets', 'myScaleSet')]",
+ "enabled": true,
+ "profiles": [
+ {
+ "name": "Profile1",
+ "capacity": {
+ "minimum": "1",
+ "maximum": "10",
+ "default": "3"
+ },
+ "rules": [
+ {
+ "metricTrigger": {
+ "metricName": "/builtin/memory/percentUsedMemory",
+ "metricNamespace": "",
+ "metricResourceUri": "[resourceId('Microsoft.Compute/virtualMachineScaleSets', 'myScaleSet')]",
+ "timeGrain": "PT1M",
+ "statistic": "Average",
+ "timeWindow": "PT5M",
+ "timeAggregation": "Average",
+ "operator": "GreaterThan",
+ "threshold": 60
+ },
+ "scaleAction": {
+ "direction": "Increase",
+ "type": "ChangeCount",
+ "value": "1",
+ "cooldown": "PT1M"
+ }
+ },
+ {
+ "metricTrigger": {
+ "metricName": "/builtin/memory/percentUsedMemory",
+ "metricNamespace": "",
+ "metricResourceUri": "[resourceId('Microsoft.Compute/virtualMachineScaleSets', 'myScaleSet')]",
+ "timeGrain": "PT1M",
+ "statistic": "Average",
+ "timeWindow": "PT5M",
+ "timeAggregation": "Average",
+ "operator": "LessThan",
+ "threshold": 30
+ },
+ "scaleAction": {
+ "direction": "Decrease",
+ "type": "ChangeCount",
+ "value": "1",
+ "cooldown": "PT1M"
+ }
+ }
+ ]
+ }
+ ]
+ }
}
]
}
下一步
您可以依照 Azure Resource Manager 文件所述來部署上述範本。
本教學課程系列可從基本的擴展集範本文章開始。
您可了解如何修改基本的擴展集範本,以將擴展集部署至現有虛擬網路。
您可了解如何修改基本的擴展集範本,以使用自訂映像部署擴展集。
您可了解如何修改基本的擴展集範本,以使用來賓型自動調整來部署 Linux 擴展集。
如需擴展集的詳細資訊,請參考擴展集概觀頁面。