[博客迁移]探索Windows Azure 监控和自动伸缩系列3 - 启用Azure监控扩展收集自定义监控数据

上一篇我们介绍了获取Azure的监控指标和监控数据:本篇我们继续:监控虚拟机的自定义性能计数器。随着我们应用规模的扩张,几十上百的虚拟机运行在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这个错误,搜索、调试了半天,未找到解决方案,同时咨询了微软的工程师,也未回复。启动Powshell ISE,连接Azure之前,导入.publishsettings文件,这样才可以用你的订阅连接Azure。
$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-WADPerformanceCountersTableVS中不能启用监控扩展,PowerShell可以,说不通,我们还是相信微软的产品质量的。https://azure.microsoft.com/en-us/documentation/articles/cloud-services-dotnet-diagnostics/然后到虚拟机上找到了 %SystemDrive%WindowsAzureConfig 配置文件:e8e74c36fae542b5bdcc88e20dd0a4c6.e8e74c36fae542b5bdcc88e20dd0a4c6.AzureAVS01.1.xml找到了xmlCfg节的内容,PFdhZENmZz48RGlhZ25vc3RpY01vbml0b3JDb25maWd1cmF0aW9uIG92ZXJhbGxRdW90YUluTUI9IjI1MDAwIj4NCiAgICAgIDxQZXJmb3JtYW5jZUNvdW50ZXJzIHNjaGVkdWxlZFRyYW5zZmVyUGVyaW9kPSJQVDFNIj4NCiAgICAgICAgPFBlcmZvcm1hbmNlQ291bnRlckNvbmZpZ3VyYXRpb24gY291bnRlclNwZWNpZmllcj0iXFByb2Nlc3NvcihfVG90YWwpXCUgUHJvY2Vzc29yIFRpbWUiIHNhbXBsZVJhdGU9IlBUMU0iIHVuaXQ9InBlcmNlbnQiIC8+DQogICAgICAgIDxQZXJmb3JtYW5jZUNvdW50ZXJDb25maWd1cmF0aW9uIGNvdW50ZXJTcGVjaWZpZXI9IlxNZW1vcnlcQ29tbWl0dGVkIEJ5dGVzIiBzYW1wbGVSYXRlPSJQVDFNIiB1bml0PSJieXRlcyIgLz4NCiAgICAgIDwvUGVyZm9ybWFuY2VDb3VudGVycz4NCiAgICAgIDxFdHdQcm92aWRlcnM+DQogICAgICAgIDxFdHdFdmVudFNvdXJjZVByb3ZpZGVyQ29uZmlndXJhdGlvbiBwcm92aWRlcj0iU2FtcGxlRXZlbnRTb3VyY2VXcml0ZXIiIHNjaGVkdWxlZFRyYW5zZmVy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W9yeVxDb21taXR0ZWQgQnl0ZXMiIHNhbXBsZVJhdGU9IlBUMFMiIC8+PC9QZXJmb3JtYW5jZUNvdW50ZXJzPjwvRGlhZ25vc3RpY01vbml0b3JDb25maWd1cmF0aW9uPjwvV2FkQ2ZnPg==base64转码后是
     
       
       
     

     
       
         
         
         
         
         
       

     

   
这个不是在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。下一篇我们继续AutoScale的话题。 周国庆2016/3

相关内容推荐