云服务监视简介Introduction to Cloud Service Monitoring

可以监视任何云服务的关键性能指标。You can monitor key performance metrics for any cloud service. 每个云服务角色都会收集最少的数据:CPU 使用率、网络使用量和磁盘利用率。Every cloud service role collects minimal data: CPU usage, network usage, and disk utilization. 如果云服务已将 Microsoft.Azure.Diagnostics 扩展应用到某个角色,则该角色可以收集其他数据点。If the cloud service has the Microsoft.Azure.Diagnostics extension applied to a role, that role can collect additional points of data. 本文介绍适用于云服务的 Azure 诊断。This article provides an introduction to Azure Diagnostics for Cloud Services.

使用基本监视时,默认情况下,将每隔 3 分钟从角色实例中采样和收集性能计数器数据。With basic monitoring, performance counter data from role instances is sampled and collected at 3-minute intervals. 此基本监视数据不会存储在存储帐户中,并且不会产生相关的额外费用。This basic monitoring data is not stored in your storage account and has no additional cost associated with it.

使用高级监视时,将每隔 5 分钟、1 小时和 12 小时采样和收集其他指标。With advanced monitoring, additional metrics are sampled and collected at intervals of 5 minutes, 1 hour, and 12 hours. 聚合的数据存储在存储帐户的表中,将在 10 天后予以清除。The aggregated data is stored in a storage account, in tables, and is purged after 10 days. 使用的存储帐户是按角色配置的;可以对不同的角色使用不同的存储帐户。The storage account used is configured by role; you can use different storage accounts for different roles. 这种配置是使用 .csdef.cscfg 文件中的连接字符串完成的。This is configured with a connection string in the .csdef and .cscfg files.

基本监视Basic monitoring

如简介中所述,云服务自动从虚拟机主机收集基本监视数据。As stated in the introduction, a cloud service automatically collects basic monitoring data from the host virtual machine. 此数据包括 CPU 百分比、网络输入/输出和磁盘读取/写入。This data includes CPU percentage, network in/out, and disk read/write. Azure 门户中云服务的概述和指标页上自动显示了所收集的监视数据。The collected monitoring data is automatically displayed on the overview and metrics pages of the cloud service, in the Azure portal.

基本监视不需要存储帐户。Basic monitoring does not require a storage account.

基本云服务监视磁贴

高级监视Advanced monitoring

高级监视涉及到对想要监视的角色使用 Azure 诊断扩展(和可选的 Application Insights SDK)。Advanced monitoring involves using the Azure Diagnostics extension (and optionally the Application Insights SDK) on the role you want to monitor. 该诊断扩展使用名为 diagnostics.wadcfgx 的配置文件(按角色)来配置所监视的诊断指标。The diagnostics extension uses a config file (per role) named diagnostics.wadcfgx to configure the diagnostics metrics monitored. Azure 诊断扩展收集数据,并将数据存储在 Azure 存储帐户中。The Azure Diagnostic extension collects and stores data in an Azure Storage account. .wadcfgx.csdef.cscfg 文件中配置这些设置。These settings are configured in the .wadcfgx, .csdef, and .cscfg files. 这意味着,高级监视会产生额外的成本。This means that there is an extra cost associated with advanced monitoring.

创建每个角色时,Visual Studio 会将 Azure 诊断扩展添加到其中。As each role is created, Visual Studio adds the Azure Diagnostics extension to it. 此诊断扩展可收集以下类型的信息:This diagnostics extension can collect the following types of information:

  • 自定义性能计数器Custom performance counters
  • 应用程序日志Application logs
  • Windows 事件日志Windows event logs
  • .NET 事件源.NET event source
  • IIS 日志IIS logs
  • 基于清单的 ETWManifest based ETW
  • 故障转储Crash dumps
  • 客户错误日志Customer error logs

Important

尽管所有这些数据都会聚合到存储帐户中,但门户提供绘制数据图表的本机方法。While all this data is aggregated into the storage account, the portal does not provide a native way to chart the data. 强烈建议你将另一个服务(如 Application Insights)集成到应用程序中。It is highly recommended that you integrate another service, like Application Insights, into your application.

设置诊断扩展Setup diagnostics extension

首先,如果你没有经典存储帐户,请创建一个First, if you don't have a classic storage account, create one. 确保为创建的存储帐户指定经典部署模型Make sure the storage account is created with the Classic deployment model specified.

接下来,导航到“存储帐户(经典)”资源。Next, navigate to the Storage account (classic) resource. 选择“设置” > “访问密钥”,并复制“主连接字符串”值。Select Settings > Access keys and copy the Primary connection string value. 云服务需要此值。You need this value for the cloud service.

必须更改两个配置文件才能启用高级诊断:ServiceDefinition.csdefServiceConfiguration.cscfgThere are two config files you must change for advanced diagnostics to be enabled, ServiceDefinition.csdef and ServiceConfiguration.cscfg.

ServiceDefinition.csdefServiceDefinition.csdef

ServiceDefinition.csdef 文件中,针对使用高级诊断的每个角色添加名为 Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString 的新设置。In the ServiceDefinition.csdef file, add a new setting named Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString for each role that uses advanced diagnostics. 创建新项目时,Visual Studio 会将此值添加到文件。Visual Studio adds this value to the file when you create a new project. 如果缺少该设置,可以立即添加。In case it is missing, you can add it now.

<ServiceDefinition name="AnsurCloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6">
  <WorkerRole name="WorkerRoleWithSBQueue1" vmsize="Small">
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />

此代码定义必须添加到每个 ServiceConfiguration.cscfg 文件的新设置。This defines a new setting that must be added to every ServiceConfiguration.cscfg file.

很可能有两个 .cscfg 文件,一个名为 ServiceConfiguration.cloud.cscfg,用于部署到 Azure;另一个名为 ServiceConfiguration.local.cscfg,用于在模拟环境中进行本地部署。Most likely you have two .cscfg files, one named ServiceConfiguration.cloud.cscfg for deploying to Azure, and one named ServiceConfiguration.local.cscfg that is used for local deployments in the emulated environment. 打开并更改每个 .cscfg 文件。Open and change each .cscfg file. 添加名为 Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString 的设置。Add a setting named Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString. 将值设置为经典存储帐户的主连接字符串Set the value to the Primary connection string of the classic storage account. 如果想要在开发计算机上使用本地存储,请使用 UseDevelopmentStorage=trueIf you want to use the local storage on your development machine, use UseDevelopmentStorage=true.

<ServiceConfiguration serviceName="AnsurCloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">
  <Role name="WorkerRoleWithSBQueue1">
    <Instances count="1" />
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=mystorage;AccountKey=KWwkdfmskOIS240jnBOeeXVGHT9QgKS4kIQ3wWVKzOYkfjdsjfkjdsaf+sddfwwfw+sdffsdafda/w==" />

<!-- or use the local development machine for storage
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
-->

使用 Application InsightsUse Application Insights

从 Visual Studio 发布云服务时,可以选择将诊断数据发送到 Application Insights。When you publish the Cloud Service from Visual Studio, you are given the option to send the diagnostic data to Application Insights. 可以在那时创建 Application Insights Azure 资源,或者将数据发送到现有 Azure 资源。You can create the Application Insights Azure resource at that time or send the data to an existing Azure resource. Application Insights 可以监视云服务的可用性、性能、故障和使用情况。Your cloud service can be monitored by Application Insights for availability, performance, failures, and usage. 可将自定义图表添加到 Application Insights,以便查看最重要的数据。Custom charts can be added to Application Insights so that you can see the data that matters the most. 在云服务项目中使用 Application Insights SDK 可以收集角色实例数据。Role instance data can be collected by using the Application Insights SDK in your cloud service project. 有关如何集成 Application Insights 的详细信息,请参阅包含云服务的 Application InsightsFor more information on how to integrate Application Insights, see Application Insights with Cloud Services.

请注意,尽管可以使用 Application Insights 来显示通过 Windows Azure 诊断扩展指定的性能计数器(和其他设置),但是只有将 Application Insights SDK 集成到辅助角色和 Web 角色,才能获得更丰富的体验。Note that while you can use Application Insights to display the performance counters (and the other settings) you have specified through the Windows Azure Diagnostics extension, you only get a richer experience by integrating the Application Insights SDK into your worker and web roles.

后续步骤Next steps