Azure Monitor 中的指标Metrics in Azure Monitor


Azure Monitor 数据平台基于两种基本数据类型:指标和日志。The Azure Monitor data platform is based on two fundamental data types: Metrics and Logs. 本文介绍指标。This article describes Metrics. 有关日志的详细介绍,请参阅 Azure Monitor 中的日志;有关日志与指标的比较,请参阅 Azure Monitor 数据平台Refer to Logs in Azure Monitor for a detailed description of logs and to Azure Monitor data platform for a comparison of the two.

Azure Monitor 中的指标是能够为近实时方案提供支持的轻型数据,因此,它们特别适合用于警报和快速检测问题。Metrics in Azure Monitor are lightweight and capable of supporting near real-time scenarios making them particularly useful for alerting and fast detection of issues. 本文将介绍指标的构建方式、可对指标执行哪些操作,以及如何识别需要在指标中存储数据的不同数据源。This article describes how metrics are structured, what you can do with them, and identifies different data sources that store data in metrics.

什么是指标?What are metrics?

指标是数字值,用于描述系统某些方面在特定时间的情况。Metrics are numerical values that describe some aspect of a system at a particular time. 指标是按固定间隔收集的,可用于警报,因为它们可以频繁采样,而警报则可以使用相对简单的逻辑快速触发。Metrics are collected at regular intervals and are useful for alerting because they can be sampled frequently, and an alert can be fired quickly with relatively simple logic.

可对 Azure Monitor 指标执行哪些操作?What can you do with Azure Monitor Metrics?

下表列出了 Azure Monitor 中的指标数据的不同使用方式。The following table lists the different ways that you can use metric data in Azure Monitor.

分析Analyze 使用指标资源管理器可以在图表中分析收集的指标,并比较来自不同资源的指标。Use metrics explorer to analyze collected metrics on a chart and compare metrics from different resources.
可视化Visualize 将指标资源管理器中的图表固定到 Azure 仪表板Pin a chart from metrics explorer to an Azure dashboard.
创建一个工作簿,用于在交互式报表中合并多个数据集。Create a workbook to combine with multiple sets of data in an interactive report.
警报Alert 配置指标警报规则,以便在指标值超过阈值时发送通知或执行自动化操作Configure a metric alert rule that sends a notification or takes automated action when the metric value crosses a threshold.
自动化Automate 根据超过阈值的指标值,使用自动缩放来增加或减少资源。Use Autoscale to increase or decrease resources based on a metric value crossing a threshold.
导出Export 将指标路由到日志,以连同 Azure Monitor 日志中的数据一起分析 Azure Monitor 指标中的数据,并将指标值存储 93 天以上。Route Metrics to Logs to analyze data in Azure Monitor Metrics together with data in Azure Monitor Logs and to store metric values for longer than 93 days.
将指标流式传输到事件中心,以将其路由到外部系统。Stream Metrics to an Event Hub to route them to external systems.
检索Retrieve 使用 PowerShell cmdlet 从命令行访问指标值Access metric values from a command line using PowerShell cmdlets
使用 REST API 从自定义应用程序访问指标值。Access metric values from custom application using REST API.
使用 CLI 从命令行访问指标值。Access metric values from a command line using CLI.
ArchiveArchive 出于符合性、审核或脱机报告目的,对资源的性能或运行状况历史记录进行 存档Archive the performance or health history of your resource for compliance, auditing, or offline reporting purposes.

Azure Monitor 指标中的数据是如何构建的?How is data in Azure Monitor Metrics structured?

Azure Monitor 指标收集的数据存储在时序数据库中,该数据库经过优化,可用于分析带时间戳的数据。Data collected by Azure Monitor Metrics is stored in a time-series database which is optimized for analyzing time-stamped data. 每组指标值是包含以下属性的时序:Each set of metric values is a time series with the following properties:

  • 值的收集时间The time the value was collected
  • 与关联的资源The resource the value is associated with
  • 类似于指标类别的命名空间A namespace that acts like a category for the metric
  • 指标名称A metric name
  • 值本身The value itself
  • 多维指标中所述,某指标可能包含多个维度。Some metrics may have multiple dimensions as described in Multi-dimensional metrics. 自定义指标最多可以包含 10 个维度。Custom metrics can have up to 10 dimensions.

多维指标Multi-dimensional metrics

指标数据的一大难题在于,它通常包含有限的信息,以致无法提供所收集值的上下文。One of the challenges to metric data is that it often has limited information to provide context for collected values. Azure Monitor 通过多维指标解决了这一难题。Azure Monitor addresses this challenge with multi-dimensional metrics. 指标维度是携带附加数据来描述指标值的名称/值对。Dimensions of a metric are name-value pairs that carry additional data to describe the metric value. 例如,指标“可用磁盘空间”可能包含名为“驱动器”并具有值“C:”和“D:”的维度,通过此维度可以查看所有驱动器的可用磁盘空间,或者可以分别查看每个驱动器的可用磁盘空间。 For example, a metric Available disk space could have a dimension called Drive with values C:, D:, which would allow viewing either available disk space across all drives or for each drive individually.

以下示例演示了名为“网络吞吐量”的假设指标的两个数据集。 The example below illustrates two datasets for a hypothetical metric called Network Throughput. 第一个数据集不包含维度。The first dataset has no dimensions. 第二个数据集使用两个维度(IP 地址_和_方向)显示值:The second dataset shows the values with two dimensions, IP Address and Direction:

网络吞吐量Network Throughput

TimestampTimestamp 指标值Metric Value
8/9/2017 8:148/9/2017 8:14 1,331.8 Kbps1,331.8 Kbps
8/9/2017 8:158/9/2017 8:15 1,141.4 Kbps1,141.4 Kbps
8/9/2017 8:168/9/2017 8:16 1,110.2 Kbps1,110.2 Kbps

上述不包含维度的指标只能够回答类似“在某个给定时间我的网络吞吐量是多少?”的基本问题This non-dimensional metric can only answer a basic question like "what was my network throughput at a given time?”

网络吞吐量 + 两个维度(“IP 地址”和“方向”)Network Throughput + two dimensions ("IP" and "Direction")

TimestampTimestamp “IP”维度Dimension "IP" “方向”维度Dimension "Direction" 指标值Metric Value
8/9/2017 8:148/9/2017 8:14 IP=""IP="" Direction="Send"Direction="Send" 646.5 Kbps646.5 Kbps
8/9/2017 8:148/9/2017 8:14 IP=""IP="" Direction="Receive"Direction="Receive" 420.1 Kbps420.1 Kbps
8/9/2017 8:148/9/2017 8:14 IP=""IP="" Direction="Send"Direction="Send" 150.0 Kbps150.0 Kbps
8/9/2017 8:148/9/2017 8:14 IP=""IP="" Direction="Receive"Direction="Receive" 115.2 Kbps115.2 Kbps
8/9/2017 8:158/9/2017 8:15 IP=""IP="" Direction="Send"Direction="Send" 515.2 Kbps515.2 Kbps
8/9/2017 8:158/9/2017 8:15 IP=""IP="" Direction="Receive"Direction="Receive" 371.1 Kbps371.1 Kbps
8/9/2017 8:158/9/2017 8:15 IP=""IP="" Direction="Send"Direction="Send" 155.0 Kbps155.0 Kbps
8/9/2017 8:158/9/2017 8:15 IP=""IP="" Direction="Receive"Direction="Receive" 100.1 Kbps100.1 Kbps

此指标可以回答类似“每个 IP 地址的网络吞吐量是多少?”,以及“相对于收到的数据,发送的数据有多少?”的问题This metric can answer questions such as "what was the network throughput for each IP address?", and "how much data was sent versus received?" 与不包含维度的指标相比,多维指标具有更多分析值和诊断值。Multi-dimensional metrics carry additional analytical and diagnostic value compared to non-dimensional metrics.

与 Azure Monitor 指标交互Interacting with Azure Monitor Metrics

使用指标资源管理器可以交互方式分析指标数据库中的数据,并在图表中绘制多个指标在不同时间段的值。Use Metrics Explorer to interactively analyze the data in your metric database and chart the values of multiple metrics over time. 可将图表固定到仪表板,以结合其他可视化效果一起查看这些图表。You can pin the charts to a dashboard to view them with other visualizations. 还可以使用 Azure 监视 REST API 检索指标。You can also retrieve metrics by using the Azure monitoring REST API.


Azure Monitor 指标的源Sources of Azure Monitor Metrics

Azure Monitor 从三个基本源收集指标。There are three fundamental sources of metrics collected by Azure Monitor. 在 Azure Monitor 指标数据库中收集这些指标后,不管指标的源是什么,都可以统一评估这些指标。Once these metrics are collected in the Azure Monitor metric database, they can be evaluated together regardless of their source.

平台指标由 Azure 资源创建,可用于洞察这些资源的运行状况和性能。Platform metrics are created by Azure resources and give you visibility into their health and performance. 每种资源创建一组非重复性指标,无需进行任何配置。Each type of resource creates a distinct set of metrics without any configuration required. 除非指标定义中另有指定,否则,将以一分钟频率从 Azure 资源收集平台指标。Platform metrics are collected from Azure resources at one-minute frequency unless specified otherwise in the metric's definition.

来宾 OS 指标是从虚拟机的来宾操作系统收集的。Guest OS metrics are collected from the guest operating system of a virtual machine. 对于 Windows 虚拟机和 Linux 虚拟机,可以分别使用 Windows 诊断扩展 (WAD)InfluxData Telegraf 代理启用来宾 OS 指标。Enable guest OS metrics for Windows virtual machines with Windows Diagnostic Extension (WAD) and for Linux virtual machines with InfluxData Telegraf Agent.

应用程序指标由 Application Insights 为受监视的应用程序创建,可帮助检测性能问题,以及跟踪应用程序的用法趋势。Application metrics are created by Application Insights for your monitored applications and help you detect performance issues and track trends in how your application is being used. 此类指标包括“服务器响应时间”和“浏览器异常”等值。 This includes such values as Server response time and Browser exceptions.

自定义指标是在自动提供的标准指标之外定义的指标。Custom metrics are metrics that you define in addition to the standard metrics that are automatically available.

指标的保留期Retention of Metrics

对于 Azure 中的大多数资源,指标存储 93 天。For most resources in Azure, metrics are stored for 93 days. 有一些例外情况:There are some exceptions:

来宾 OS 指标Guest OS metrics

  • 经典来宾 OS 指标Classic guest OS metrics. 这些是由 Windows 诊断扩展 (WAD)Linux 诊断扩展 (LAD) 收集并路由到 Azure 存储帐户的性能计数器。These are performance counters collected by the Windows Diagnostic Extension (WAD) or the Linux Diagnostic Extension (LAD) and routed to an Azure storage account. 这些指标的保留期为 14 天。Retention for these metrics is 14 days.
  • 发送到 Azure Monitor 指标的来宾 OS 指标Guest OS metrics sent to Azure Monitor Metrics. 这些是由 Windows 诊断扩展 (WAD) 收集并发送到 Azure Monitor 接收器的性能计数器,或通过 Linux 计算机上的 InfluxData Telegraf 代理收集的性能计数器。These are performance counters collected by the Windows Diagnostic Extension (WAD) and send to the Azure Monitor Sink, or via the InfluxData Telegraf Agent on Linux machines. 这些指标的保留期为 93 天。Retention for these metrics is 93 days.
  • Log Analytics 代理收集的来宾 OS 指标Guest OS metrics collected by Log Analytics agent. 这些是由 Log Analytics 代理收集并发送到 Log Analytics 工作区的性能计数器。These are performance counters collected by the Log Analytics agent and sent to a Log Analytics workspace. 这些指标的保留期为 31 天,最长可延长到 2 年。Retention for these metrics is 31 days, and can be extended up to 2 years.

Application Insights 基于日志的指标Application Insights log-based metrics.

  • 在后台,基于日志的指标将转换为日志查询。Behind the scene, log-based metrics translate into log queries. 其保留期与基础日志中事件的保留期相匹配。Their retention matches the retention of events in underlying logs. 对于 Application Insights 资源,日志存储 90 天。For Application Insights resources, logs are stored for 90 days.

后续步骤Next steps