ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

【Azure 云服务】Azure Cloud Service (Extended Support) 云服务开启诊断日志插件 WAD Extension (Windows Azure Diagnosti

2022-04-08 19:34:11  阅读:341  来源: 互联网

标签:插件 Extended name Service Get cloudService Extension Azure Cloud


问题描述

在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

"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}"
            }
        ]
    }
}

 

 

标签:插件,Extended,name,Service,Get,cloudService,Extension,Azure,Cloud
来源: https://www.cnblogs.com/lulight/p/16119429.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有