• [博客迁移]探索Windows Azure 监控和自动伸缩系列3


    上一篇我们介绍了获取Azure的监控指标和监控数据:

    http://www.cnblogs.com/teld/p/5113376.html

    本篇我们继续:监控虚拟机的自定义性能计数器。

    随着我们应用规模的扩张,几十上百的虚拟机运行在Azure上面,实时监控应用的运行情况是我们智能化运维的需要。因此,我们在应用的核心组件上添加了性能计数器,实时将运行数据记录到性能计数器上。

    监控实时抓取虚拟机中性能计数器的数据。

    在Google中搜一下Azure Monitor extension,找到几个有用的Link:

    https://azure.microsoft.com/en-us/documentation/articles/vs-azure-tools-diagnostics-for-cloud-services-and-virtual-machines/

    https://azure.microsoft.com/en-us/documentation/articles/cloud-services-dotnet-diagnostics/

    第一个链接中图文并茂的说明了如何启用虚拟机监控的扩展以及监控性能技术器的数据:

    微软的Blog资源果然牛逼,说的非常详细。

    启动VS连接Azure,竟然找不到图中Azure的管理UI,细想一下也对,不是所有的VS使用者都需要操作Azure,这个Azure的管理UI应该是VS的一个Plugin。

    咨询了搞大数据的朱哥,发给我一个在线安装程序:选择安装Microsoft Azure SDK for .net(VS 2015)-2.8.1

    安装完成后,Azure的管理菜单出来了,然后选择要监控的虚拟机,添加Microsoft Monitoring Agent Diagnostics,Configure,监控自定义性能计数器,然后保存:

    重新刷新后,扩展启用报错了:

    错误信息:Microsoft.Azure.Diagnostics.IaaSDiagnostics, version 1.4.2.1) with exception Command C:PackagesPluginsMicrosoft.Azure.Diagnostics.IaaSDiagnostics1.4.2.1DiagnosticsPluginLauncher.exe of Microsoft.Azure.Diagnostics.IaaSDiagnostics has exited with code -3

    在虚拟机中的C:PackagesPluginsMicrosoft.Azure.Diagnostics.IaaSDiagnostics1.4.2.1Logs中,找下了更多的错误信息:

    DiagnosticsPluginLauncher.exe Information: 0 : [2016/1/7 7:35:41] Checking VM Type
    DiagnosticsPluginLauncher.exe Information: 0 : [2016/1/7 7:35:41] File HandlerEnvironment.json found. Extension set to IAAS
    DiagnosticsPluginLauncher.exe Information: 0 : [2016/1/7 7:35:41] RcfFileName: C:WindowsAzureConfigac5e6303019644418a08571783b4a103.ac5e6303019644418a08571783b4a103.teldptapp.16.xml
    DiagnosticsPluginLauncher.exe Information: 0 : [2016/1/7 7:35:41] RoleInstanceId: teldptapp; DeploymentId: ac5e6303019644418a08571783b4a103; RoleName: teldptapp
    DiagnosticsPluginLauncher.exe Information: 0 : [2016/1/7 7:35:41] Config file found: C:PackagesPluginsMicrosoft.Azure.Diagnostics.IaaSDiagnostics1.4.2.1RuntimeSettings13.settings
    DiagnosticsPluginLauncher.exe Information: 0 : [2016/1/7 7:35:41] Loading config file: C:PackagesPluginsMicrosoft.Azure.Diagnostics.IaaSDiagnostics1.4.2.1RuntimeSettings13.settings
    DiagnosticsPluginLauncher.exe Information: 0 : [2016/1/7 7:35:41] Reading JSON configuration file
    DiagnosticsPluginLauncher.exe Error: 0 : [2016/1/7 7:35:41] System.ArgumentNullException: 值不能为 null。
    参数名: s
       在 System.Convert.FromBase64String(String s)
       在 Microsoft.Azure.Plugins.Diagnostics.dll.PublicSettings.get_XmlCfg()
       在 Microsoft.Azure.Plugins.Diagnostics.dll.PluginConfigurationSettingsProvider.LoadWadJSONConfig(String fullConfig)
       在 Microsoft.Azure.Plugins.Diagnostics.dll.PluginConfigurationSettingsProvider.LoadWad2Config()
       在 Microsoft.Azure.Plugins.Diagnostics.dll.PluginConfigurationSettingsProvider.Initialize()
    DiagnosticsPluginLauncher.exe Error: 0 : [2016/1/7 7:35:41] Failed to read configuration.
    DiagnosticsPluginLauncher.exe Information: 0 : [2016/1/7 7:35:49] DiagnosticPlugin exited with code -3

    这个错误,搜索、调试了半天,未找到解决方案,同时咨询了微软的工程师,也未回复。

    此时,重新读了第二个链接中的文章内容,通过Powershell启用监控扩展。尝试一下:

    启动Powshell ISE,连接Azure之前,导入.publishsettings文件,这样才可以用你的订阅连接Azure。

    安装第二个链接的内容,一步一步,执行PowerShell以下命令:

    $storage_name = "monitorstorage"
    $key = "nd7QMydWNFNuROfe********ADsasdasdfafs8*****=="
    $config_path="C:UsersAdministratorDocumentsVisual Studio 2015ProjectsWadExampleVMWadExampleVMWadExample.xml"
    $service_name="AzureAVS01"
    $vm_name="AzureAVS02"
    $storageContext = New-AzureStorageContext -StorageAccountName $storage_name -StorageAccountKey $key 
    $VM1 = Get-AzureVM -ServiceName $service_name -Name $vm_name
    $VM2 = Set-AzureVMDiagnosticsExtension -DiagnosticsConfigurationPath $config_path -Version "1.*" -VM $VM1 -StorageContext $storageContext
    $VM3 = Update-AzureVM -ServiceName $service_name -Name $vm_name -VM $VM2.VM

    竟然ok了,牛逼。

    性能计数器的数据写到了Storage-Table-WADPerformanceCountersTable

    VS中不能启用监控扩展,PowerShell可以,说不通,我们还是相信微软的产品质量的。

    继续研读第二个链接的内容:在Troubleshooting章节,仔细读了Exit -3 和 -106的说明;

    https://azure.microsoft.com/en-us/documentation/articles/cloud-services-dotnet-diagnostics/

    然后到虚拟机上找到了 %SystemDrive%WindowsAzureConfig 配置文件:e8e74c36fae542b5bdcc88e20dd0a4c6.e8e74c36fae542b5bdcc88e20dd0a4c6.AzureAVS01.1.xml

    找到了xmlCfg节的内容,

    PFdhZENmZz48RGlhZ25vc3RpY01vbml0b3JDb25maWd1cmF0aW9uIG92ZXJhbGxRdW90YUluTUI9IjI1MDAwIj4NCiAgICAgIDxQZXJmb3JtYW5jZUNvdW50ZXJzIHNjaGVkdWxlZFRyYW5zZmVyUGVyaW9kPSJQVDFNIj4NCiAgICAgICAgPFBlcmZvcm1hbmNlQ291bnRlckNvbmZpZ3VyYXRpb24gY291bnRlclNwZWNpZmllcj0iXFByb2Nlc3NvcihfVG90YWwpXCUgUHJvY2Vzc29yIFRpbWUiIHNhbXBsZVJhdGU9IlBUMU0iIHVuaXQ9InBlcmNlbnQiIC8+DQogICAgICAgIDxQZXJmb3JtYW5jZUNvdW50ZXJDb25maWd1cmF0aW9uIGNvdW50ZXJTcGVjaWZpZXI9IlxNZW1vcnlcQ29tbWl0dGVkIEJ5dGVzIiBzYW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gVGltZSIgc2FtcGxlUmF0ZT0iUFQwUyIgLz48UGVyZm9ybWFuY2VDb3VudGVyQ29uZmlndXJhdGlvbiBjb3VudGVyU3BlY2lmaWVyPSJcTWVtb3J5XEF2YWlsYWJsZSBNQnl0ZXMiIHNhbXBsZVJhdGU9IlBUMFMiIC8+PFBlcmZvcm1hbmNlQ291bnRlckNvbmZpZ3VyYXRpb24gY291bnRlclNwZWNpZmllcj0iXE1lbW9yeVxDb21taXR0ZWQgQnl0ZXMiIHNhbXBsZVJhdGU9IlBUMFMiIC8+PC9QZXJmb3JtYW5jZUNvdW50ZXJzPjwvRGlhZ25vc3RpY01vbml0b3JDb25maWd1cmF0aW9uPjwvV2FkQ2ZnPg==

    base64转码后是

    <WadCfg><DiagnosticMonitorConfiguration overallQuotaInMB="25000">
          <PerformanceCounters scheduledTransferPeriod="PT1M">
            <PerformanceCounterConfiguration counterSpecifier="Processor(_Total)\% Processor Time" sampleRate="PT1M" unit="percent" />
            <PerformanceCounterConfiguration counterSpecifier="MemoryCommitted Bytes" sampleRate="PT1M" unit="bytes" />
          </PerformanceCounters>
          <EtwProviders>
            <EtwEventSourceProviderConfiguration provider="SampleEventSourceWriter" scheduledTransferPeriod="PT5M">
              <Event id="1" eventDestination="EnumsTable" />
              <Event id="2" eventDestination="MessageTable" />
              <Event id="3" eventDestination="SetOtherTable" />
              <Event id="4" eventDestination="HighFreqTable" />
              <DefaultEvents eventDestination="DefaultTable" />
            </EtwEventSourceProviderConfiguration>
          </EtwProviders>
        </DiagnosticMonitorConfiguration><DiagnosticMonitorConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration"><PerformanceCounters><PerformanceCounterConfiguration counterSpecifier="Processor(_Total)\% Processor Time" sampleRate="PT0S" /><PerformanceCounterConfiguration counterSpecifier="MemoryAvailable MBytes" sampleRate="PT0S" /><PerformanceCounterConfiguration counterSpecifier="MemoryCommitted Bytes" sampleRate="PT0S" /></PerformanceCounters></DiagnosticMonitorConfiguration></WadCfg>

    这个不是在Powershell指定的XML文件的内容吗!

    然后对比了通过VS启用扩展的虚拟机之监控扩展的配置文件:

    {"WadCfg":{"DiagnosticMonitorConfiguration":{"PerformanceCounters":{"PerformanceCounterConfiguration":[{"annotation":[],"counterSpecifier":"\Memory\Available MBytes","sampleRate":"PT3M"},{"annotation":[],"counterSpecifier":"\Web Service(_Total)\ISAPI Extension Requests/sec","sampleRate":"PT3M"},{"annotation":[],"counterSpecifier":"\Web Service(_Total)\Bytes Total/Sec","sampleRate":"PT3M"},{"annotation":[],"counterSpecifier":"\ASP.NET Applications(__Total__)\Requests/Sec","sampleRate":"PT3M"},{"annotation":[],"counterSpecifier":"\ASP.NET Applications(__Total__)\Errors Total/Sec","sampleRate":"PT3M"},{"annotation":[],"counterSpecifier":"\ASP.NET\Requests Queued","sampleRate":"PT3M"},{"annotation":[],"counterSpecifier":"\ASP.NET\Requests Rejected","sampleRate":"PT3M"},{"annotation":[],"counterSpecifier":"\Processor(_Total)\% Processor Time","sampleRate":"PT3M"}],"scheduledTransferPeriod":"PT1M"},"overallQuotaInMB":4096}}

    靠,这个竟然是JSON。

    大致想通了:

    Powershell中指定XML文件是ok的,VS中Azure管理插件启用监控扩展失败。

    不同的客户端发的请求不同,应该是Azure管理工具的问题,记得安装的版本是2.8.1,最新的。

    朱哥机器上看了以下是2.7,最新版本的Azure Tool是面向最新的Azure的,中国区的应该滞后一点。

    因此,将本机2.8版本全部卸载,安装2.7版本:

    https://www.microsoft.com/en-us/download/details.aspx?id=48178

    基于2.7这个版本的Azure管理工具启用虚拟机监控扩展,OK。

    本文希望能帮忙在中国搞Azure的小伙伴,也是对Azure的技术支持。

    下一篇我们继续AutoScale的话题。

    周国庆

    2016/3

  • 相关阅读:
    【★】路由环路大总结!
    自制tunnel口建虚拟专网实验
    自制tunnel口建虚拟专网实验
    自制tunnel口建虚拟专网实验
    常用的组播保留地址列表
    常用的组播保留地址列表
    常用的组播保留地址列表
    程序员经常遇到的几个问题!
    ★路由递归查询方法及相关图示【转载】
    ★路由递归查询方法及相关图示【转载】
  • 原文地址:https://www.cnblogs.com/tianqing/p/6526238.html
Copyright © 2020-2023  润新知