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.
AlertAlert 配置指标警报规则,以在指标值超过阈值时发送通知或执行自动化操作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.
存档Archive 出于符合性、审核或脱机报告目的,对资源的性能或运行状况历史记录进行 存档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

时间戳Timestamp 指标值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")

时间戳Timestamp “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 诊断扩展 (WAD) 为 Windows 虚拟机启用来宾 OS 指标,并使用 InfluxData Telegraf 代理为 Linux 虚拟机启用来宾 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.

指标保留期Retention of Metrics

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

来宾 OS 指标Guest OS metrics

基于 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