問題描述
在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中卻沒有受到指標資料。
相應的配置檔案為:
PublicWadConfig.xsd
<?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>
PrivateConfig.xml
<?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>
執行的PowerShell命令為:
# 登入中國區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,修改後的檔案為:
PrivateConfig.xml
<?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資料成功!
附件一:WAD Extension不允許使用重複的名稱,所以可以通過名稱過濾掉需要刪除的Extension名稱後,執行以下的指令碼
# 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