在Azure中国区上面创建一个云服务(外延支持)后,根据官方文档(在云服务(外延支持)中应用 Azure 诊断扩展: https://docs.azure.cn/zh-cn/cloud-services-extended-support/enable-wad),启用了WAD扩展来收集实例的Metrics信息到Stroage Account。根据官方的实例,配置好了公共配置 XML 文件(PublicWadConfig.xsd)和专用 XML 配置文件(PrivateConfig.xml)后,在Storage Account中却没有受到指标数据。
<?xml version="1.0" encoding="utf-8"?> <PublicConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration"> <WadCfg> <DiagnosticMonitorConfiguration overallQuotaInMB="25000"> <PerformanceCounters scheduledTransferPeriod="PT1M"> <PerformanceCounterConfiguration counterSpecifier="\Processor(_Total)\% Processor Time" sampleRate="PT1M" unit="percent" /> <PerformanceCounterConfiguration counterSpecifier="\Memory\Committed Bytes" sampleRate="PT1M" unit="bytes"/> </PerformanceCounters> <EtwProviders> <EtwEventSourceProviderConfiguration provider="SampleEventSourceWriter" scheduledTransferPeriod="PT5M"> <Event id="1" eventDestination="EnumsTable"/> <DefaultEvents eventDestination="DefaultTable" /> </EtwEventSourceProviderConfiguration> </EtwProviders> </DiagnosticMonitorConfiguration> </WadCfg> </PublicConfig>
<?xml version="1.0" encoding="utf-8"?> <PrivateConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration"> <StorageAccount name="stroage account name" key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" /> </PrivateConfig>
# 登录中国区Azure Connect-AzAccount -Environment AzureChinaCloud # 选择订阅号 Select-AzSubscription -Subscription 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # 如果没有安装az cloud service模块,用下面命令安装 Install-Module -Name Az.CloudService -Scope CurrentUser -Repository PSGallery -Force # Create WAD extension object $storageAccountKey = Get-AzStorageAccountKey -ResourceGroupName "resource group name" -Name "storage account name" $configFilePath = "PublicWadConfig.xsd" $wadExtension = New-AzCloudServiceDiagnosticsExtension -Name "WADExtension" -ResourceGroupName "resource group name" -CloudServiceName "cloud service name" -StorageAccountName "csstorageaccounttest01" -StorageAccountKey $storageAccountKey[0].Value -DiagnosticsConfigurationPath $configFilePath -TypeHandlerVersion "1.5" -AutoUpgradeMinorVersion $true # Add <privateConfig> settings $wadExtension.ProtectedSetting = "<Insert WAD Private Configuration as raw string here>" # Get existing Cloud Service $cloudService = Get-AzCloudService -ResourceGroup "resource group name" -CloudServiceName "cloud service name" # Add WAD extension to existing Cloud Service extension object $cloudService.ExtensionProfile.Extension = $cloudService.ExtensionProfile.Extension + $wadExtension # Update Cloud Service $cloudService | Update-AzCloudService
在Cloud Service的Extension页面查看到WADExtention 已经配置好(状态为Success)。
但是在配置的Storage Account中,却迟迟收集到不数据。
为了分析这个问题,需要开启应用远程桌面扩展(RDP)查看 WAD插件的日志。相应日志的路径为:
C:\Resources\Directory\<guid>.<webroelx>.DiagnosticStore\WAD0107\Tables
但日志文件为tsf格式,可以通过table2csv.exe 进行转换 (PS: table2csv.exe 文件路径位于 > D:\Packages\Plugins\Microsoft.Azure.Diagnostics.PaaSDiagnostics\<latest extension version>\Monitor\x64\table2csv.exe),使用 <PATH>\table2scv.exe maeventtable.tsf 命令把文件转换为csv格式后 ,即可查看日志内容:
在日志内容中发现:
WinHttpSendRequest failed; URL=https://********************.table.core.windows.net Failed to send bytes to XTable WADPerformanceCountersTable as Xstore rejected the request; Status=12007 Retry:#0; failed to send out data; XTable WADPerformanceCountersTable; PartitionKey 0637848351000000000
因为中国区Storage Account的Endpoint与Global不一样,消息中发现的Endpoint为 core.windows.net, 而中国区的endpoint为 core.chinacloudapi.cn。由于在添加的配置文件中,并没有为Storage Account特别指定Endpoint,导致系统默认使用了Global地址。
所以解决问题的方案就是在PrivateConfig.xml文件中添加Endpoint [ endpoint="https://core.chinacloudapi.cn" ]。
修改PrivateConfig文件,在StorageAccount 节点中添加 endpoint,修改后的文件为:
<?xml version="1.0" encoding="utf-8"?> <PrivateConfig xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration"> <StorageAccount name="stroage account name" key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" endpoint="https://core.chinacloudapi.cn" /> </PrivateConfig>
在Powershell的脚本中可以通过 Get-Content -Path privateConfig.xml 来获取上文内容,并赋值给 $wadExtension.ProtectedSetting。
完整的PowerShell脚本为:
Connect-AzAccount -Environment AzureChinaCloud # 选择订阅号 Select-AzSubscription -Subscription 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # 如果没有安装az cloud service模块,用下面命令安装 Install-Module -Name Az.CloudService -Scope CurrentUser -Repository PSGallery -Force # Create WAD extension object $storageAccountKey = Get-AzStorageAccountKey -ResourceGroupName "resource group name" -Name "storage account name" $configFilePath = "PublicWadConfig.xsd" $wadExtension = New-AzCloudServiceDiagnosticsExtension -Name "WADExtension" -ResourceGroupName "resource group name" -CloudServiceName "cloud service name" -StorageAccountName "csstorageaccounttest01" -StorageAccountKey $storageAccountKey[0].Value -DiagnosticsConfigurationPath $configFilePath -TypeHandlerVersion "1.5" -AutoUpgradeMinorVersion $true # Add <privateConfig> settings $wadExtension.ProtectedSetting = Get-Content -Path PrivateConfig.xml # Get existing Cloud Service $cloudService = Get-AzCloudService -ResourceGroup "resource group name" -CloudServiceName "cloud service name" # Add WAD extension to existing Cloud Service extension object $cloudService.ExtensionProfile.Extension = $cloudService.ExtensionProfile.Extension + $wadExtension # Update Cloud Service $cloudService | Update-AzCloudService
最终,通过 Microsoft Azure Storage Explorer工具查看Cloud Service的Metrics数据。
收集Metrics数据成功!
# Get existing Cloud Service $cloudService = Get-AzCloudService -ResourceGroup "your resource group" -CloudServiceName "cloud service name" $cloudService.ExtensionProfile.Extension = $cloudService.ExtensionProfile.Extension | Where-Object { $_.Name -ne "WADExtension" } # Update Cloud Service $cloudService | Update-AzCloudService
在云服务(外延支持)中应用 Azure 诊断扩展:https://docs.azure.cn/zh-cn/cloud-services-extended-support/enable-wad
Private Config Schem: https://docs.microsoft.com/en-us/azure/azure-monitor/agents/diagnostics-extension-schema-windows#example-configuration
"PrivateConfig" { "storageAccountName": "diagstorageaccount", "storageAccountKey": "{base64 encoded key}", "storageAccountEndPoint": "https://core.windows.net", "storageAccountSasToken": "{sas token}", "EventHub": { "Url": "https://myeventhub-ns.servicebus.windows.net/diageventhub", "SharedAccessKeyName": "SendRule", "SharedAccessKey": "{base64 encoded key}" }, "AzureMonitorAccount": { "ServicePrincipalMeta": { "PrincipalId": "{Insert service principal client Id}", "Secret": "{Insert service principal client secret}" } }, "SecondaryStorageAccounts": { "StorageAccount": [ { "name": "secondarydiagstorageaccount", "key": "{base64 encoded key}", "endpoint": "https://core.windows.net", "sasToken": "{sas token}" } ] }, "SecondaryEventHubs": { "EventHub": [ { "Url": "https://myeventhub-ns.servicebus.windows.net/secondarydiageventhub", "SharedAccessKeyName": "SendRule", "SharedAccessKey": "{base64 encoded key}" } ] } }