从 Azure Monitor 监视和调试 Azure Cosmos DB 指标Monitor and debug Azure Cosmos DB metrics from Azure Monitor

可以从 Azure Monitor API 查看 Azure Cosmos DB 指标。You can view Azure Cosmos DB metrics from Azure Monitor API. Azure Monitor 提供多种方式来与指标交互,包括 Azure 门户、通过 REST API 访问指标,或者使用 PowerShell 或 CLI 查询指标。Azure Monitor provides several ways to interact with metrics, including the Azure portal, accessing them through the REST API, or querying them using PowerShell or CLI. Azure Cosmos DB 指标是低延迟的数字值,默认每隔一分钟收集一次。你也可以聚合这些指标。Azure Cosmos DB metrics are low-latency numerical values, collected at one-minute frequency by default, you can also aggregate these metrics. 这些指标能够支持实时方案。These metrics are capable of supporting real-time scenarios.

本文介绍可以使用 Azure 门户从 Azure Monitor 查看的不同 Azure Cosmos DB 指标。This article describes different Azure Cosmos DB metrics you can view from Azure Monitor using Azure portal. 若要了解常见用例以及如何重复使用 Azure Cosmos DB 指标分析和调试问题,请参阅在 Azure Cosmos DB 中使用指标进行监视和调试一文。If you are interested in common use cases and how Azure Cosmos DB metrics re used to analyze and debug these issues see Monitor and debug with metrics in Azure Cosmos DB article. 你将使用某个现有的 Azure Cosmos 帐户,在数据库、容器、区域、请求或操作级别查看不同的指标。You will use one of your existing Azure Cosmos accounts and view the different metrics at the database, container, region, request, or operation levels. 因此,请务必准备好一个包含示例数据的 Azure Cosmos 帐户,并对这些数据执行 CRUD 操作。So, make sure you have an Azure Cosmos account with sample data and perform CRUD operations on that data.

从 Azure 门户查看指标View metrics from Azure portal

  1. 登录 Azure 门户Sign in to the Azure portal.

  2. 在左侧导航栏中选择“监视”,然后选择“指标”。 Select Monitor from the left-hand navigation bar, and select Metrics.

    Azure Monitor 中的“指标”窗格

  3. 在“指标”窗格中选择一个资源,然后选择所需的订阅和资源组。 From the Metrics pane > Select a resource > choose the required subscription, and resource group. 对于“资源类型”,请选择“Azure Cosmos DB 帐户”,选择一个现有的 Azure Cosmos 帐户,然后选择“应用”。 For the Resource type, select Azure Cosmos DB accounts, choose one of your existing Azure Cosmos accounts, and select Apply.

    选择 Cosmos DB 帐户以查看指标

  4. 接下来,可以从可用指标列表中选择一个指标。Next you can select a metric from the list of available metrics. 可以选择特定于请求单位、存储、延迟、可用性、Cassandra 等的指标。You can select metrics specific to request units, storage, latency, availability, Cassandra, and others. 若要详细了解此列表中的所有可用指标,请参阅本文的按类别划分的指标部分。To learn in detail about all the available metrics in this list, see the Metrics by category section of this article. 在此示例中,让我们选择“请求单位”和“平均”作为聚合值。 In this example, let's select Request units and Avg as the aggregation value.

    除这些详细信息外,还可以选择指标的“时间范围”和“时间粒度”。 In addition to these details, you can also select the Time range and Time granularity of the metrics. 可以查看过去最长 30 天的指标。At max, you can view metrics for the past 30 days. 应用筛选器后,系统会根据该筛选器显示图表。After you apply the filter, a chart is displayed based on your filter. 可以查看所选时间段内每分钟消耗的平均请求单位数。You can see the average number of request units consumed per minute for the selected period.

    从 Azure 门户中选择指标

向指标添加筛选器Add filters to metrics

还可以按 CollectionNameDatabaseNameOperationTypeRegionStatusCode 筛选指标及显示的图表。You can also filter metrics and the chart displayed by a specific CollectionName, DatabaseName, OperationType, Region, and StatusCode. 若要筛选指标,请选择“添加筛选器”,选择所需的属性(例如 OperationType),然后选择一个值(例如 Query)。To filter the metrics, select Add filter and choose the required property such as OperationType and select a value such as Query. 然后,图表中会显示查询操作在所选时间段内消耗的请求单位数。The graph then displays the request units consumed for the query operation for the selected period. 不会记录通过存储过程执行的操作,因此 OperationType 指标下不会显示这些操作。The operations executed via Stored procedure are not logged so they are not available under the OperationType metric.

添加筛选器以选择指标粒度

可以使用“应用拆分”选项将指标分组。 You can group metrics by using the Apply splitting option. 例如,可按操作类型将请求单位分组,并一次性查看所有操作的图表,如下图所示:For example, you can group the request units per operation type and view the graph for all the operations at once as shown in the following image:

添加“应用拆分”筛选器

按类别划分的指标Metrics by category

请求指标Request metrics

Metric(指标显示名称)Metric (Metric Display Name) Unit(聚合类型)Unit (Aggregation Type) 说明Description 维度Dimensions 时间粒度Time granularities 旧指标映射Legacy metric mapping 使用情况Usage
TotalRequests(请求总数)TotalRequests (Total Requests) Count(计数)Count (Count) 已发出的请求数Number of requests made DatabaseName, CollectionName, Region, StatusCodeDatabaseName, CollectionName, Region, StatusCode AllAll TotalRequests、Http 2xx、Http 3xx、Http 400、Http 401、内部服务器错误、服务不可用、受限制的请求数、每秒平均请求数TotalRequests, Http 2xx, Http 3xx, Http 400, Http 401, Internal Server error, Service Unavailable, Throttled Requests, Average Requests per Second 用于按状态代码、容器监视请求,以分钟为粒度。Used to monitor requests per status code, container at a minute granularity. 若要获取每秒的平均请求数,请在分钟级别使用“计数”聚合并除以 60。To get average requests per second, use Count aggregation at minute and divide by 60.
MetadataRequests(元数据请求数)MetadataRequests (Metadata Requests) Count(计数)Count (Count) 元数据请求的计数。Count of metadata requests. Azure Cosmos DB 为每个帐户维护系统元数据容器,允许你免费枚举集合、数据库及其配置等等。Azure Cosmos DB maintains system metadata container for each account, that allows you to enumerate collections, databases, etc., and their configurations, free of charge. DatabaseName, CollectionName, Region, StatusCodeDatabaseName, CollectionName, Region, StatusCode AllAll 用于监视由于元数据请求而导致的限制。Used to monitor throttles due to metadata requests.
MongoRequests(Mongo 请求数)MongoRequests (Mongo Requests) Count(计数)Count (Count) 已发出的 Mongo 请求数Number of Mongo Requests Made DatabaseName, CollectionName, Region, CommandName, ErrorCodeDatabaseName, CollectionName, Region, CommandName, ErrorCode AllAll Mongo 查询请求速率、Mongo 更新请求速率、Mongo 删除请求速率、Mongo 插入请求速率、Mongo 计数请求速率Mongo Query Request Rate, Mongo Update Request Rate, Mongo Delete Request Rate, Mongo Insert Request Rate, Mongo Count Request Rate 用于监视 Mongo 请求错误以及每个命令类型的使用情况。Used to monitor Mongo request errors, usages per command type.

请求单位指标Request Unit metrics

Metric(指标显示名称)Metric (Metric Display Name) Unit(聚合类型)Unit (Aggregation Type) 说明Description 维度Dimensions 时间粒度Time granularities 旧指标映射Legacy metric mapping 使用情况Usage
MongoRequestCharge(Mongo 请求费用)MongoRequestCharge (Mongo Request Charge) Count(总数)Count (Total) Mongo 已消耗的请求单位Mongo Request Units Consumed DatabaseName, CollectionName, Region, CommandName, ErrorCodeDatabaseName, CollectionName, Region, CommandName, ErrorCode AllAll Mongo 查询请求费用、Mongo 更新请求费用、Mongo 删除请求费用、Mongo 插入请求费用、Mongo 计数请求费用Mongo Query Request Charge, Mongo Update Request Charge, Mongo Delete Request Charge, Mongo Insert Request Charge, Mongo Count Request Charge 用于监视一分钟内的 Mongo 资源 RU。Used to monitor Mongo resource RUs in a minute.
TotalRequestUnits(请求单位总数)TotalRequestUnits (Total Request Units) Count(总数)Count (Total) 已消耗的请求单位Request Units consumed DatabaseName, CollectionName, Region, StatusCodeDatabaseName, CollectionName, Region, StatusCode AllAll TotalRequestUnitsTotalRequestUnits 用于在分钟粒度监视总的 RU 使用量。Used to monitor Total RU usage at a minute granularity. 若要获取每秒平均使用的 RU,请在分钟级别使用“总计”聚合并除以 60。To get average RU consumed per second, use Total aggregation at minute and divide by 60.
ProvisionedThroughput(预配的吞吐量)ProvisionedThroughput (Provisioned Throughput) Count(最大值)Count (Maximum) 以容器粒度预配的吞吐量Provisioned throughput at container granularity DatabaseName、ContainerNameDatabaseName, ContainerName 5M5M 用于监视每个容器的预配吞吐量。Used to monitor provisioned throughput per container.

存储度量值Storage metrics

Metric(指标显示名称)Metric (Metric Display Name) Unit(聚合类型)Unit (Aggregation Type) 说明Description 维度Dimensions 时间粒度Time granularities 旧指标映射Legacy metric mapping 使用情况Usage
AvailableStorage(可用存储空间)AvailableStorage (Available Storage) Bytes(总数)Bytes (Total) 每个区域按 5 分钟粒度报告的可用存储总量Total available storage reported at 5-minutes granularity per region DatabaseName、CollectionName、RegionDatabaseName, CollectionName, Region 5M5M 可用存储Available Storage 用于监视可用存储容量(仅适用于固定存储集合)。最小粒度应当为 5 分钟。Used to monitor available storage capacity (applicable only for fixed storage collections) Minimum granularity should be 5 minutes.
DataUsage(数据用量)DataUsage (Data Usage) Bytes(总数)Bytes (Total) 每个区域按 5 分钟粒度报告的数据总用量Total data usage reported at 5-minutes granularity per region DatabaseName、CollectionName、RegionDatabaseName, CollectionName, Region 5M5M 数据大小Data size 用于在容器和区域级别监视总的数据使用情况,最小粒度应当为 5 分钟。Used to monitor total data usage at container and region, minimum granularity should be 5 minutes.
IndexUsage(索引用量)IndexUsage (Index Usage) Bytes(总数)Bytes (Total) 每个区域按 5 分钟粒度报告的索引总用量Total Index usage reported at 5-minutes granularity per region DatabaseName、CollectionName、RegionDatabaseName, CollectionName, Region 5M5M 索引大小Index Size 用于在容器和区域级别监视总的数据使用情况,最小粒度应当为 5 分钟。Used to monitor total data usage at container and region, minimum granularity should be 5 minutes.
DocumentQuota(文档配额)DocumentQuota (Document Quota) Bytes(总数)Bytes (Total) 每个区域按 5 分钟粒度报告的存储配额总量。Total storage quota reported at 5-minutes granularity per region. DatabaseName、CollectionName、RegionDatabaseName, CollectionName, Region 5M5M 存储容量Storage Capacity 用于在容器和区域级别监视总的配额,最小粒度应当为 5 分钟。Used to monitor total quota at container and region, minimum granularity should be 5 minutes.
DocumentCount(文档计数)DocumentCount (Document Count) Count(总数)Count (Total) 每个区域按 5 分钟粒度报告的文档总数Total document count reported at 5-minutes granularity per region DatabaseName、CollectionName、RegionDatabaseName, CollectionName, Region 5M5M 文档计数Document Count 用于在容器和区域级别监视文档计数,最小粒度应当为 5 分钟。Used to monitor document count at container and region, minimum granularity should be 5 minutes.

延迟指标Latency metrics

Metric(指标显示名称)Metric (Metric Display Name) Unit(聚合类型)Unit (Aggregation Type) 说明Description 维度Dimensions 时间粒度Time granularities 使用情况Usage
ReplicationLatency(复制延迟)ReplicationLatency (Replication Latency) MilliSeconds(最小值、最大值、平均值)MilliSeconds (Minimum, Maximum, Average) 启用了异地复制的帐户的源和目标区域之间的 P99 复制延迟P99 Replication Latency across source and target regions for geo-enabled account SourceRegion、TargetRegionSourceRegion, TargetRegion AllAll 用于监视异地复制帐户在任何两个区域之间的 P99 复制延迟。Used to monitor P99 replication latency between any two regions for a geo-replicated account.

可用性指标Availability metrics

Metric(指标显示名称)Metric (Metric Display Name) Unit(聚合类型)Unit (Aggregation Type) 说明Description 时间粒度Time granularities 旧指标映射Legacy metric mapping 使用情况Usage
ServiceAvailability(服务可用性)ServiceAvailability (Service Availability) Percent(最小值、最大值)Percent (Minimum, Maximum) 在一小时粒度内的帐户请求可用性Account requests availability at one hour granularity 1 小时1H 服务可用性Service Availability 表示传递的请求总数百分比。Represents the percent of total passed requests. 如果状态代码为 410、500 或 503,则会认为请求因系统错误而失败。用于按小时粒度监视帐户的可用性。A request is considered to be failed due to system error if the status code is 410, 500 or 503 Used to monitor availability of the account at hour granularity.

Cassandra API 指标Cassandra API metrics

Metric(指标显示名称)Metric (Metric Display Name) Unit(聚合类型)Unit (Aggregation Type) 说明Description 维度Dimensions 时间粒度Time granularities 使用情况Usage
CassandraRequests(Cassandra 请求数)CassandraRequests (Cassandra Requests) Count(计数)Count (Count) 发出的 Cassandra API 请求数Number of Cassandra API requests made DatabaseName、CollectionName、ErrorCode、Region、OperationType、ResourceTypeDatabaseName, CollectionName, ErrorCode, Region, OperationType, ResourceType AllAll 用于按分钟粒度监视 Cassandra 请求。Used to monitor Cassandra requests at a minute granularity. 若要获取每秒的平均请求数,请在分钟级别使用“计数”聚合并除以 60。To get average requests per second, use Count aggregation at minute and divide by 60.
CassandraRequestCharges(Cassandra 请求费用)CassandraRequestCharges (Cassandra Request Charges) Count(合计、最小值、最大值、平均值)Count (Sum, Min, Max, Avg) Cassandra API 请求已消耗的请求单位数Request Units consumed by Cassandra API requests DatabaseName、CollectionName、Region、OperationType、ResourceTypeDatabaseName, CollectionName, Region, OperationType, ResourceType AllAll 用于监视 Cassandra API 帐户每分钟使用的 RU。Used to monitor RUs used per minute by a Cassandra API account.
CassandraConnectionClosures(Cassandra 连接关闭次数)CassandraConnectionClosures (Cassandra Connection Closures) Count(计数)Count (Count) 关闭的 Cassandra 连接数Number of Cassandra Connections closed ClosureReason、RegionClosureReason, Region AllAll 用于监视客户端与 Azure Cosmos DB Cassandra API 之间的连接。Used to monitor the connectivity between clients and the Azure Cosmos DB Cassandra API.

后续步骤Next steps