监视 Azure 容器实例中的容器资源Monitor container resources in Azure Container Instances

Azure Monitor 可以洞察容器实例使用的计算资源。Azure Monitor provides insight into the compute resources used by your containers instances. 此资源使用情况数据有助于确定容器组的最佳资源设置。This resource usage data helps you determine the best resource settings for your container groups. Azure Monitor 还提供用于在容器实例中跟踪网络活动的指标。Azure Monitor also provides metrics that track network activity in your container instances.

本文档详述了如何使用 Azure 门户和 Azure CLI 收集容器实例的 Azure Monitor 指标。This document details gathering Azure Monitor metrics for container instances using both the Azure portal and Azure CLI.

Important

Azure 容器实例中的 Azure Monitor 指标目前为预览版,并且存在某些限制Azure Monitor metrics in Azure Container Instances are currently in preview, and some limitations apply. 需同意补充使用条款才可使用预览版。Previews are made available to you on the condition that you agree to the supplemental terms of use. 在正式版 (GA) 推出之前,此功能的某些方面可能会有所更改。Some aspects of this feature may change prior to general availability (GA).

预览版限制Preview limitations

目前,仅提供了 Linux 容器的 Azure Monitor 指标。At this time, Azure Monitor metrics are only available for Linux containers.

可用指标Available metrics

Azure Monitor 提供下述 Azure 容器实例指标Azure Monitor provides the following metrics for Azure Container Instances. 这些指标适用于容器组和单独的容器。These metrics are available for a container group and individual containers.

  • CPU 使用率 - 以毫核心为单位进行度量。CPU Usage - measured in millicores. 一个毫核心是一个 CPU 核心的 1/1000,因此 500 毫核心(或 500 毫)表示 CPU 核心的使用率为 50%。One millicore is 1/1000th of a CPU core, so 500 millicores (or 500 m) represents 50% usage of a CPU core. 聚合为所有核心的平均使用率Aggregated as average usage across all cores.

  • 内存使用率 - 聚合为平均字节数Memory Usage - aggregated as average bytes.

  • 每秒接收的网络字节数每秒传输的网络字节数 - 聚合为每秒平均字节数Network Bytes Received Per Second and Network Bytes Transmitted Per Second - aggregated as average bytes per second.

获取指标 - Azure 门户Get metrics - Azure portal

创建容器组时,Azure Monitor 数据在 Azure 门户中可用。When a container group is created, Azure Monitor data is available in the Azure portal. 若要查看容器组的指标,请转到容器组的“概览”页。 To see metrics for a container group, go to the Overview page for the container group. 在这里可以看到为每个可用指标预先创建的图表。Here you can see pre-created charts for each of the available metrics.

双图表

在包含多个容器的容器组中,使用维度按容器显示指标。In a container group that contains multiple containers, use a dimension to present metrics by container. 若要创建包含个体容器指标的图表,请执行以下步骤:To create a chart with individual container metrics, perform the following steps:

  1. 在“概览”页中选择一个指标图表,例如“CPU”。 In the Overview page, select one of the metric charts, such as CPU.

  2. 选择“应用拆分”按钮,然后选择“容器名称” 。 Select the Apply splitting button, and select Container Name.

    维度

获取指标 - Azure CLIGet metrics - Azure CLI

还可以使用 Azure CLI 收集容器实例的指标。Metrics for container instances can also be gathered using the Azure CLI. 首先,使用以下命令获取容器组的 ID。First, get the ID of the container group using the following command. <resource-group> 替换为你的资源组名称,将 <container-group> 替换为你的容器组的名称。Replace <resource-group> with your resource group name and <container-group> with the name of your container group.

CONTAINER_GROUP=$(az container show --resource-group <resource-group> --name <container-group> --query id --output tsv)

使用以下命令获取 CPU 使用情况指标。Use the following command to get CPU usage metrics.

az monitor metrics list --resource $CONTAINER_GROUP --metric CPUUsage --output table
Timestamp            Name       Average
-------------------  ---------  ---------
2019-04-23 22:59:00  CPU Usage
2019-04-23 23:00:00  CPU Usage
2019-04-23 23:01:00  CPU Usage  0.0
2019-04-23 23:02:00  CPU Usage  0.0
2019-04-23 23:03:00  CPU Usage  0.5
2019-04-23 23:04:00  CPU Usage  0.5
2019-04-23 23:05:00  CPU Usage  0.5
2019-04-23 23:06:00  CPU Usage  1.0
2019-04-23 23:07:00  CPU Usage  0.5
2019-04-23 23:08:00  CPU Usage  0.5
2019-04-23 23:09:00  CPU Usage  1.0
2019-04-23 23:10:00  CPU Usage  0.5

更改命令中 --metric 参数的值即可获取其他支持的指标Change the value of the --metric parameter in the command to get other supported metrics. 例如,使用以下命令获取内存使用率指标。For example, use the following command to get memory usage metrics.

az monitor metrics list --resource $CONTAINER_GROUP --metric MemoryUsage --output table
Timestamp            Name          Average
-------------------  ------------  ----------
2019-04-23 22:59:00  Memory Usage
2019-04-23 23:00:00  Memory Usage
2019-04-23 23:01:00  Memory Usage  0.0
2019-04-23 23:02:00  Memory Usage  8859648.0
2019-04-23 23:03:00  Memory Usage  9181184.0
2019-04-23 23:04:00  Memory Usage  9580544.0
2019-04-23 23:05:00  Memory Usage  10280960.0
2019-04-23 23:06:00  Memory Usage  7815168.0
2019-04-23 23:07:00  Memory Usage  7739392.0
2019-04-23 23:08:00  Memory Usage  8212480.0
2019-04-23 23:09:00  Memory Usage  8159232.0
2019-04-23 23:10:00  Memory Usage  8093696.0

对于多容器组,添加 containerName 维度即可返回每个容器的指标。For a multi-container group, the containerName dimension can be added to return metrics per container.

az monitor metrics list --resource $CONTAINER_GROUP --metric MemoryUsage --dimension containerName --output table
Timestamp            Name          Containername             Average
-------------------  ------------  --------------------  -----------
2019-04-23 22:59:00  Memory Usage  aci-tutorial-app
2019-04-23 23:00:00  Memory Usage  aci-tutorial-app
2019-04-23 23:01:00  Memory Usage  aci-tutorial-app      0.0
2019-04-23 23:02:00  Memory Usage  aci-tutorial-app      16834560.0
2019-04-23 23:03:00  Memory Usage  aci-tutorial-app      17534976.0
2019-04-23 23:04:00  Memory Usage  aci-tutorial-app      18329600.0
2019-04-23 23:05:00  Memory Usage  aci-tutorial-app      19742720.0
2019-04-23 23:06:00  Memory Usage  aci-tutorial-app      14786560.0
2019-04-23 23:07:00  Memory Usage  aci-tutorial-app      14651392.0
2019-04-23 23:08:00  Memory Usage  aci-tutorial-app      15470592.0
2019-04-23 23:09:00  Memory Usage  aci-tutorial-app      15450112.0
2019-04-23 23:10:00  Memory Usage  aci-tutorial-app      15339520.0
2019-04-23 22:59:00  Memory Usage  aci-tutorial-sidecar
2019-04-23 23:00:00  Memory Usage  aci-tutorial-sidecar
2019-04-23 23:01:00  Memory Usage  aci-tutorial-sidecar  0.0
2019-04-23 23:02:00  Memory Usage  aci-tutorial-sidecar  884736.0
2019-04-23 23:03:00  Memory Usage  aci-tutorial-sidecar  827392.0
2019-04-23 23:04:00  Memory Usage  aci-tutorial-sidecar  831488.0
2019-04-23 23:05:00  Memory Usage  aci-tutorial-sidecar  819200.0
2019-04-23 23:06:00  Memory Usage  aci-tutorial-sidecar  843776.0
2019-04-23 23:07:00  Memory Usage  aci-tutorial-sidecar  827392.0
2019-04-23 23:08:00  Memory Usage  aci-tutorial-sidecar  954368.0
2019-04-23 23:09:00  Memory Usage  aci-tutorial-sidecar  868352.0
2019-04-23 23:10:00  Memory Usage  aci-tutorial-sidecar  847872.0

后续步骤Next steps

Azure 监视概述详细了解 Azure 监视。Learn more about Azure Monitoring at the Azure Monitoring overview.

了解如何创建指标警报,以便在 Azure 容器实例的指标超出阈值时获得通知。Learn how to create metric alerts to get notified when a metric for Azure Container Instances crosses a threshold.