使用 REST API 获取负载均衡器利用率指标Get Load Balancer utilization metrics using the REST API

本操作指南演示如何使用 Azure REST API 收集标准负载均衡器在一段时间内处理的字节数。This how-to shows how to collect the number of bytes processed by a Standard Load Balancer for an interval of time using the Azure REST API.

有关 REST API 的完整参考文档和其他示例,请查看 Azure Monitor REST reference(Azure Monitor REST 参考)。Complete reference documentation and additional samples for the REST API are available in the Azure Monitor REST reference.

生成请求Build the request

使用以下 GET 请求从标准负载均衡器收集 ByteCount 指标。Use the following GET request to collect the ByteCount metric from a Standard Load Balancer.

GET https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/providers/microsoft.insights/metrics?api-version=2018-01-01&metricnames=ByteCount&timespan=2018-06-05T03:00:00Z/2018-06-07T03:00:00Z

请求标头Request headers

以下标头是必需的:The following headers are required:

请求标头Request header 说明Description
Content-Type:Content-Type: 必需。Required. 设置为 application/jsonSet to application/json.
Authorization:Authorization: 必需。Required. 设置为有效的 Bearer 访问令牌Set to a valid Bearer access token.

URI 参数URI parameters

NameName 说明Description
subscriptionIdsubscriptionId 用于标识 Azure 订阅的订阅 ID。The subscription ID that identifies an Azure subscription. 如果拥有多个订阅,请参阅使用多个订阅If you have multiple subscriptions, see Working with multiple subscriptions.
resourceGroupNameresourceGroupName 包含该资源的资源组名称。The name of the resource group that contains the resource. 可以从 Azure 资源管理器 API、CLI 或门户获取此值。You can obtain this value from the Azure Resource Manager API, CLI, or the portal.
loadBalancerNameloadBalancerName Azure 负载均衡器的名称。The name of the Azure Load Balancer.
metricnamesmetricnames 包含有效负载均衡器指标的逗号分隔的列表。Comma-separated list of valid Load Balancer metrics.
api-versionapi-version 用于请求的 API 版本。The API version to use for the request.

本文档介绍上述 URL 中包括的 api-version 2018-01-01This document covers api-version 2018-01-01, included in the above URL.
timespantimespan 查询的时间跨度。The timespan of the query. 它是具有格式 startDateTime_ISO/endDateTime_ISO 的字符串。It is a string with the following format startDateTime_ISO/endDateTime_ISO. 设置此可选参数是为了在示例中返回一天的时间。This optional parameter is set to return a day's worth of data in the example.
   

请求正文Request body

此操作不需请求正文。No request body is needed for this operation.

处理响应Handle the response

成功返回指标值列表以后,会返回状态代码 200。Status code 200 is returned when the list of metric values is returned successfully. 参考文档中提供错误代码的完整列表。A full list of error codes is available in the reference documentation.

示例响应Example response

{
    "cost": 0,
    "timespan": "2018-06-05T03:00:00Z/2018-06-07T03:00:00Z",
    "interval": "PT1M",
    "value": [
        {
            "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/providers/Microsoft.Insights/metrics/ByteCount",
            "type": "Microsoft.Insights/metrics",
            "name": {
                "value": "ByteCount",
                "localizedValue": "Byte Count"
            },
            "unit": "Count",
            "timeseries": [
                {
                    "metadatavalues": [],
                    "data": [
                        {
                            "timeStamp": "2018-06-06T17:24:00Z",
                            "total": 1067921034.0
                        },
                        {
                            "timeStamp": "2018-06-06T17:25:00Z",
                            "total": 0.0
                        },
                        {
                            "timeStamp": "2018-06-06T17:26:00Z",
                            "total": 3781344.0
                        },
                    ]
                }
            ]
        }
    ],
    "namespace": "Microsoft.Network/loadBalancers",
    "resourceregion": "chinaeast"
}