> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/api-reference/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/api-reference/cn/bmc/bare-metal-instance/describeinstancetraffic.md).

# DescribeInstanceTraffic

## 1. 接口描述

本接口(DescribeInstanceTraffic)用于查询实例指定时间段内的流量信息。

{% hint style="info" %}
**注意事项**

* 开始时间和结束时间的跨度不能超过一天。
* 只能查询30天内的流量数据。
  {% endhint %}

## 2. 请求参数

以下请求参数列表仅列出了接口中需要的请求参数

| 参数名称       | 必选 | 类型     | 描述                                                                                                                                                 |
| ---------- | -- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| startTime  | 是  | String | <p>查询开始时间。</p><p>按照ISO8601标准表示，并且使用UTC时间。格式为：YYYY-MM-ddTHH<span data-gb-custom-inline data-tag="emoji" data-code="1f1f2-1f1f2">🇲🇲</span>ssZ。</p> |
| endTime    | 是  | String | <p>查询结束时间。</p><p>按照ISO8601标准表示，并且使用UTC时间。格式为：YYYY-MM-ddTHH<span data-gb-custom-inline data-tag="emoji" data-code="1f1f2-1f1f2">🇲🇲</span>ssZ。</p> |
| instanceId | 是  | String | 实例ID。                                                                                                                                              |

## 3. 响应结果

| 参数名称                    | 类型                                                                                         | 描述                                                                                                                            |
| ----------------------- | ------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
| requestId               | String                                                                                     | <p>唯一请求 ID。</p><p>每次请求都会返回。定位问题时需要提供该次请求的 requestId。</p>                                                                      |
| dataList                | Array of [InstanceTrafficData](/api-reference/cn/bmc/datastructure.md#instancetrafficdata) | 带宽数据列表。                                                                                                                       |
| in95                    | Integer                                                                                    | 入口带宽95值。                                                                                                                      |
| in95Time                | String                                                                                     | <p>入口带宽95值时间。</p><p>格式为：YYYY-MM-ddTHH<span data-gb-custom-inline data-tag="emoji" data-code="1f1f2-1f1f2">🇲🇲</span>ssZ。</p> |
| inAvg                   | Integer                                                                                    | 入口带宽平均值。                                                                                                                      |
| inMax                   | Integer                                                                                    | 入口带宽最大值。                                                                                                                      |
| inMin                   | Integer                                                                                    | 入口带宽最小值。                                                                                                                      |
| inTotal                 | Integer                                                                                    | 入口带宽总流量。                                                                                                                      |
| out95                   | Integer                                                                                    | 出口带宽95值。                                                                                                                      |
| out95Time               | String                                                                                     | <p>出口带宽95值时间。</p><p>格式为：YYYY-MM-ddTHH<span data-gb-custom-inline data-tag="emoji" data-code="1f1f2-1f1f2">🇲🇲</span>ssZ。</p> |
| outAvg                  | Integer                                                                                    | 出口带宽平均值。                                                                                                                      |
| outMax                  | Integer                                                                                    | 出口带宽最大值。                                                                                                                      |
| outMin                  | Integer                                                                                    | 出口带宽最小值。                                                                                                                      |
| outTotal                | Integer                                                                                    | 出口带宽总流量。                                                                                                                      |
| maxBandwidth95ValueMbps | Float                                                                                      | 最大带宽95值。单位：Mbps。                                                                                                              |
| totalUnit               | String                                                                                     | 总流量单位。例如：B。                                                                                                                   |
| unit                    | String                                                                                     | 带宽值单位。例如：bps。                                                                                                                 |

## 4. 代码示例

{% tabs %}
{% tab title="示例" %}

1. **查询实例一天内的流量数据。**

```json
POST /api/v2/bmc HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: DescribeInstanceTraffic
Request:
{
  "instanceId": "instanceId",
  "startTime": "2023-01-01T00:00:00Z",
  "endTime": "2023-01-01T23:59:59Z"
}
Response:
{
  "requestId": "T4C35327C-7B13-47B8-A815-5E5213D4A9F9",
  "response": {
    "requestId": "T4C35327C-7B13-47B8-A815-5E5213D4A9F9",
    "dataList": [
      {
        "internetRX": 873034,
        "internetTX": 11971,
        "time": "2023-01-01T00:00:00Z"
      },
      {
        "internetRX": 873034,
        "internetTX": 11971,
        "time": "2023-01-01T00:05:00Z"
      },
      {
        "internetRX": 635218,
        "internetTX": 9028,
        "time": "2023-01-01T00:10:00Z"
      }
    ],
    "in95": 873034,
    "in95Time": "2023-01-01T00:00:00Z",
    "inAvg": 793762,
    "inMax": 873034,
    "inMin": 635218,
    "inTotal": 89298270,
    "maxBandwidth95ValueMbps": 0.88,
    "out95": 11971,
    "out95Time": "2023-01-01T00:00:00Z",
    "outAvg": 10990,
    "outMax": 11971,
    "outMin": 9028,
    "outTotal": 1236457,
    "totalUnit": "B",
    "unit": "bps"
  }
}
```

{% endtab %}
{% endtabs %}

## 5. 开发者工具

Zenlayer Cloud API 2.0 提供了配套的[开发工具集（SDK）](/api-reference/cn/api-introduction/toolkit.md)，未来会陆续支持更多开发语言，方便快速接入和使用Zenlayer的产品和服务。

## 6. 错误码

下面包含业务逻辑中遇到的错误码，其他错误码见[公共错误码](/api-reference/cn/api-introduction/instruction/commonerrorcode.md)

| HTTP状态码 | 错误码                           | 说明     |
| ------- | ----------------------------- | ------ |
| 404     | INVALID\_INSTANCE\_NOT\_FOUND | 实例不存在。 |
