使用 ARM 模板设置 Linux 诊断扩展
Setup Linux Diagnostic extension using ARM templates
您好,我正在尝试创建一个 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?
# 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
我在这里回答我自己的问题。
与 Windows 的 Azure 诊断代理进行比较时的差异是:
type
在 properties
下。这将对应于 LinuxDiagnostic
而不是 IaaSDiagnostics
.
typehandlerversion
:这基本上就是LAD版本了。最新的是 3.0
.
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(在受保护的设置部分)。
settings
:这将采用以下形式:
{
"ladCfg": { ... },
"perfCfg": { ... },
"fileLogs": { ... },
"StorageAccount": "the storage account to receive data",
"mdsdHttpProxy" : ""
}
其中每一项都已详细讨论 here(在 public 设置中)。
对我有用的 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"
}
]
}
}
}
}
}
}
]
您好,我正在尝试创建一个 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?
# 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
我在这里回答我自己的问题。
与 Windows 的 Azure 诊断代理进行比较时的差异是:
type
在properties
下。这将对应于LinuxDiagnostic
而不是IaaSDiagnostics
.typehandlerversion
:这基本上就是LAD版本了。最新的是3.0
.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(在受保护的设置部分)。
settings
:这将采用以下形式:{ "ladCfg": { ... }, "perfCfg": { ... }, "fileLogs": { ... }, "StorageAccount": "the storage account to receive data", "mdsdHttpProxy" : "" }
其中每一项都已详细讨论 here(在 public 设置中)。
对我有用的 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"
}
]
}
}
}
}
}
}
]