Windows Azure Platform 性能监视器(转载)
我们知道,云计算的特点之一是:弹性计算。如果在某一时间点,用于对云计算资源的使用量超过了实际部署的硬件水平,我们就可以通过修改:
- 增加单个计算节点的硬件配置,比如配置VM Size,从Small改成Extra Large。来提高硬件水平以响应更多的客户请求。
- 多个计算节点并行计算,比如修改Instance Count,从1(单个计算节点),改成2或者更多(多个计算节点)。这样也可以提高服务水平。
但是Windows Azure毕竟是在远程数据中心的托管服务,我们在本地是无法监视和查看Windows Azure托管服务的资源使用情况。如果我们想查看Windows Azure的性能监视器,你可能会想到:
- 使用远程桌面连接。因为Windows Azure提供远程桌面(RDP)连接查看Azure 计算节点的功能,所以您在部署完托管服务后,可以登录到一个计算节点的远程桌面,然后运行Perfmon进行查看。
但是这种方法的缺点显而易见:
- 首先,你只能查看到某一个计算节点的性能监视器而无法查看所有的计算节点。
- 其次,使用远程桌面的步骤是及其繁琐的,需要连接、输入用户名密码、输入命令行查看。
- 而且,通过远程桌面查看到Windows Azure性能监视器的内容,无法保存在客户端。
考虑到这些问题,微软创建了Windows Azure Diagnostics(诊断)的机制。Windows Azure Diagnostics可以诊断检索许多内容,比如跟踪日志,奔溃事件日志等,并且保存下来。在本章里,我将侧重于Peformance Counter(性能计数器),该功能可以提供WIndows Azure应用程序的关键信息。实际上,性能计数器,可以帮助您隔离性能问题。最重要的是,它可以帮您省钱,让Windows Azure的资源得到最佳利用。
Windows Azure Diagnostics
每一个Windows Azure计算节点都有一个内置的诊断进程(DiagnosticsAgent.exe),负责定期收集诊断数据,并缓存到本地文件,并最终存储到一个预定义的Azure存储。请注意,在诊断过程中,也可以手动触发。
具体来说,Peformance Counter的数据被保存到Windows Azure Storage的Table中,表名为WADPerformanceCountersTable。其他Diagnostics,比如跟踪日志,事件日志等数据也都存储在指定的表,像WadLogsTable
,WADDiagnosticInfrastructureLogsTable等
。更多信息,可以参考这里。
每一个Role Instance都有一个Configuration File (配置文件),位于Azure Storage Blob下,Container(概念上类似于文件夹)为wad-control-container。配置文件主要收集性能计数器数据和相关的使用率。
下面显示的是Disnostics Configuration File的位置。你可以下载Cloud Storage Manager访问wad-control-container。
配置文件中使用了一个标准的XML格式,并可以手动修改(不推荐)。
使用代码
在这篇文章中,我们会研究
1.如果配置Role.cs,并且从外部程序读取Peformance Counter
2.如何访问Azure Storage Table中的数据
3.性能计数器的快速分析
Windows Azure诊断API
参考自MSDN
- Microsoft.WindowsAzure.Diagnostics-允许你收集日志和诊断信息从代码运行在你的角色
- Microsoft.WindowsAzure.Diagnostics.Management - 允许你收集日志和远程Diagnostics(诊断)信息
为了Diagnostics 你的Role,你必须先在ServiceDefinition.csdef中修改配置文件。具体的您可以参考我的博文Windows
Azure Platform (二十)使用Windows Azure诊断收集日志记录数据
在WebRole.cs中修改代码

public class WebRole : RoleEntryPoint { /// <summary> /// Entry point before starting the Role /// </summary> public override bool OnStart() { // Get the Role instance Diagnostics configuration. var config = DiagnosticMonitor.GetDefaultInitialConfiguration(); // Define interval for persisting the performance counter data to azure storage. config.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(); // CPU Utilization Counter PerformanceCounterConfiguration cpuUtilizationCounter = new PerformanceCounterConfiguration() { CounterSpecifier = @"\Processor(_Total)\% Processor Time", //define the sample internal for the specific performance counter SampleRate = TimeSpan.FromSeconds() }; if (!config.PerformanceCounters.DataSources.Contains(cpuUtilizationCounter, new PerformanceCounterComparer())) { config.PerformanceCounters.DataSources.Add(cpuUtilizationCounter); } // Start diagnostic monitor with the new configuration. DiagnosticMonitor.Start ("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config); return base.OnStart(); } /// <summary> /// Performance Counter Comparer /// </summary> private class PerformanceCounterComparer : IEqualityComparer<PerformanceCounterConfiguration> { public bool Equals(PerformanceCounterConfiguration a, PerformanceCounterConfiguration b) { //Check whether the compared objects reference the same data. if (Object.ReferenceEquals(a, b)) return true; //Check whether any of the compared objects is null. if (Object.ReferenceEquals(a, null) || Object.ReferenceEquals(b, null)) return false; // Check if the counter specifier and the sampling rate are the same. return (a.CounterSpecifier == b.CounterSpecifier && a.SampleRate == b.SampleRate); } public int GetHashCode(PerformanceCounterConfiguration counter) { //Check whether the object is null if (Object.ReferenceEquals(counter, null)) return ; //Get hash code for the CounterSpecifier field if it is not null. int hashCounterSpecifier = counter.CounterSpecifier == null ? : counter.CounterSpecifier.GetHashCode(); //Calculate the hash code for the counter. return hashCounterSpecifier ^ counter.SampleRate.GetHashCode(); } } }

远程配置 Performance Counter(性能计数器)
使用 Microsoft.WindowsAzure.Diagnostics.Management
.

const string storageAccoutName = "Storage-Name-Here"; const string privateKey = "Storge-Private-Key-Here"; const string deploymentId = "Deployment-Id-Here"; var storageAccount = CloudStorageAccount.Parse(String.Format( "DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", storageAccoutName, privateKey)); // Get the diagnostics manager for the entire storage account. var diagnosticManager = storageAccount.CreateDeploymentDiagnosticManager(deploymentId); // Get diagnostics manager for the specific role instance. RoleInstanceDiagnosticManager roleDiagManager = diagnosticManager.GetRoleInstanceDiagnosticManager("WebRole1", "WebRole1_IN_0"); //Modify current configuration var currentConfiguariton = roleDiagManager.GetCurrentConfiguration(); currentConfiguariton.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(); currentConfiguariton.PerformanceCounters.DataSources.Add (new PerformanceCounterConfiguration() { CounterSpecifier = @"\Processor(_Total)\% Processor Time", SampleRate = TimeSpan.FromSeconds() }); //Commit the changes roleDiagManager.SetCurrentConfiguration(currentConfiguariton);

检索性能计数器数据
现在,我们已经配置了我们要监视的计数器。让我们访问Azure Storage Table(表名WADPerformanceCountersTable),并显示出来。
我创建了PerformanceDataContext,派生自TableServiceContext
。这是为了连接到Azure表,Microsoft提供的ADO扩展的一部分。你可以使用LINQ查询以检 索数据。

/// <summary> /// Query helper for retrieving data from the WADPerformanceCountersTable /// </summary> public class QueryExecuter { /// <summary> /// Cloud storage account client /// </summary> private CloudStorageAccount accountStorage; /// <summary> /// Default Constructor - Use development storage emulator. /// </summary> public QueryExecuter() { accountStorage = CloudStorageAccount.DevelopmentStorageAccount; } /// <summary> /// Constructor /// </summary> /// <param name="accountName">Azure storage name</param> /// <param name="privateKey">Azure storage private key</param> public QueryExecuter(string accountName, string privateKey) { accountStorage = CloudStorageAccount.Parse(String.Format( "DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", account } /// <summary> /// Retrieve Performance counter data /// </summary> /// <param name="counterFullName">Counter specifier full name</param> /// <param name="deploymentid">Deployment id</param> /// <param name="roleName">Role name</param> /// <param name="roleInstanceName">Role instance name</param> /// <param name="startPeriod">Start sample date time</param> /// <param name="endPeriod">End sample date time</param> /// <returns></returns> public List<PerformanceData> QueryPerformanceCounter(string counterFullName, string deploymentid, string roleName, string roleInstanceName, DateTime startPeriod, DateTime endPeriod) { PerformanceDataContext context = new PerformanceDataContext( accountStorage.TableEndpoint.ToString(), accountStorage.Credentials); var data = context.PerfData; CloudTableQuery<PerformanceData> query = null; query = (from d in data where d.PartitionKey.CompareTo("" + startPeriod.Ticks) >= && d.PartitionKey.CompareTo ("" + endPeriod.Ticks) <= && d.CounterName == counterFullName && d.EventTickCount >= startPeriod.Ticks && d.EventTickCount <= endPeriod.Ticks && d.DeploymentId == deploymentid && d.Role == roleName && d.RoleInstance == roleInstanceName select d).AsTableServiceQuery<PerformanceData>(); List<PerformanceData> selectedData = new List<PerformanceData>(); try { selectedData = query.Execute().ToList<PerformanceData>(); } catch { } return selectedData; } }

此演示,我创建了一个WindowsForm,将Diagnostics Table中的数据填充到图表中。
显示的是过去2个小时内,某一个Role Instance的CPU使用率。
第三方工具
Quest 软件公司开发了一个非常方便和容易使用的工具。称为Spotlight on Azure。为我们对整个Azure订阅提供了深度监控的功能,包括Role Instance,数据聚合,历史数据展示,提醒机制,用户自定义深度分析计数器。
Windows Azure Platform 性能监视器(转载)的更多相关文章
- Windows Azure Platform Introduction (11) 了解Org ID、Windows Azure订阅、账户
<Windows Azure Platform 系列文章目录> 了解和掌握Windows Azure相关的基础知识是非常重要的. 问题1:什么叫做Org ID Org ID是Azure C ...
- Windows Azure Platform 系列文章目录
Windows Azure Platform (一) 云计算的出现 Windows Azure Platform (二) 云计算的分类和服务层次 Windows Azure Platform (三) ...
- Windows Azure Platform (一) 云计算的出现
<Windows Azure Platform 系列文章目录> 最近的一年一直致力于微软云计算技术的推广和研究,对于微软的云计算平台Windows Azure Platform有一定的了解 ...
- Windows Azure Platform Introduction (14) 申请海外的Windows Azure账户
<Windows Azure Platform 系列文章目录> 本文的最后更新时间为:2017-12-27 本文介绍国内用户,注册和使用海外Azure账户. 前提: 1.需要一个有效的Wi ...
- 使用 windows server 2012 性能监视器
监控Windows server的内存.CPU.磁盘IO等性能 配置方法: 打开Aministrator Tools --> Performance Monitor Performances - ...
- Windows Azure Storage (21) 使用AzCopy工具,加快Azure Storage传输速度
<Windows Azure Platform 系列文章目录> Update 2016-09-28 想要在Azure云端,使用AzCopy工具,从Azure China 上海数据中心存储账 ...
- Windows Azure Virtual Machine (26) 使用高级存储(SSD)和DS系列VM
<Windows Azure Platform 系列文章目录> Update: 2016-11-3,如果大家在使用Linux VM,使用FIO进行IOPS测试的时候,请使用以下命令: su ...
- Windows Azure Storage (18) 使用HTML5 Portal的Azure CDN服务
<Windows Azure Platform 系列文章目录> Update:2015-04-15 如果读者使用的是国内由世纪互联运维的Azure China服务,请参考笔者的文档:Azu ...
- Windows Azure Storage (19) 再谈Azure Block Blob和Page Blob
<Windows Azure Platform 系列文章目录> 请读者在参考本文之前,预习相关背景知识:Windows Azure Storage (1) Windows Azure St ...
随机推荐
- [转][Navicat for MySQL系列]Navicat如何使用(二)
上一篇经验已经建立了数据连接,这篇我介绍一下Navicat for MySQL的“增删改查”功能是如何操作的. 工具/原料 Navicat for MySQL 10.1.7 数据库操作(基本) 1 远 ...
- Mac下JAVA开发环境搭建
最近开始学习JAVA, 首先配置下环境! 1.Mac自带的jdk版本老了,需要到oracle官网去下载新的jdk,具体下载那个版本看个人需求,然后安装. 安装完成之后打开Terminal, 执行命 ...
- 技术分享:杂谈如何绕过WAF(Web应用防火墙)(转)
0×01开场白 这个议题呢,主要是教大家一个思路,而不是把现成准备好的代码放给大家. 可能在大家眼中WAF(Web应用防火墙)就是"不要脸"的代名词.如果没有他,我们的" ...
- 你家的Wifi密码安全吗?
WiFi在给我们提供方便的无线网络同时,也带了一些隐患.如果对WiFi不设密码的话,一来会因为蹭网而影响网速,二来给信息安全带来了不小隐患.针对WiFi的安全手段,一般来说就是加密.最初的加密方式是W ...
- Android-25种开源炫酷动画框架
前言 忙碌的工作终于可以停息一段时间了,最近突然有一个想法,就是自己写一个app,所以找了一些合适开源控件,这样更加省时,再此分享给大家,希望能对大家有帮助,此博文介绍的都是UI上面的框架,接下来会有 ...
- Linux下的基础命令
在容器环境中很多时候要确定底层操作系统是什么和什么版本,网上找了一把,发现了一些比较有用的命令,从其他地方转过来,参考 # uname -a # 查看内核/操作系统/CPU信息 # head -n / ...
- [Java]在窗口界面上画出硬盘中图片文件
利用类javax.swing.JPanel来在窗口界面上画图.图片文件通过javax.imageio.ImageIO类来获取. import java.awt.Graphics; import jav ...
- synchronized 线程同步
synchronized 通常用来形容一次方法的调用,调用一旦开始,调用者必须等到方法调用返回后,才能继续执行后续的操作. 1.demo package demo1; public class My ...
- SQL性能调优基础教材
一.数据库体系结构 1. Oracle数据库和实例 数据库:物理操作系统文件或磁盘的集合. 实例:一组Oracle后台进程/线程以及一个共享内存区,这些内存由同一个计算机上运行的线程/进程 ...
- SQL盲注攻击的简单介绍
1 简介 1.1 普通SQL注入技术概述 目前没有对SQL注入技术的标准定义,微软中国技术中心从2个方面进行了描述[1]: (1) 脚本注入式的攻击 (2) 恶意用户输 ...