跳转至

查询流量数据统计

1. 接口描述

接口请求路径:POST /prod-api/multiCdn/statistic/describeTrafficData

describeTrafficData 用于查询 CDN 流量趋势与域名流量排行。一次请求可在 action 中声明多个指标,返回的 dataaction 顺序一一对应。

流量数值单位为字节(Byte)。时间范围仅支持查询最近 180 天。Token 获取方式见 密钥鉴权

2. 输入参数

以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数

参数名称 必选 类型 描述
action Array 统计指标列表,不能为空
action.metricName String 统计指标。仅支持:traffic(流量趋势)、trafficRank(域名流量排行)
示例值:traffic
action.pageNo Integer 页码,从 1 开始,默认 1。仅 trafficRank 有效
示例值:1
action.pageSize Integer 每页条数,默认 10。仅 trafficRank 有效
示例值:10
domains Array of String 域名过滤。空数组或不传表示当前账号全部域名;支持通配符,如 *.example.com
示例值:[]
interval String 时间粒度。取值:5m(5 分钟)、1h(1 小时)、1d(1 天)。不传时按时间跨度自动选择:≤8 天用 5m,≤30 天用 1h,≤90 天用 1d
示例值:5m
params.beginTime String 开始时间,格式 yyyy-MM-dd HH:mm:ss,仅支持查询最近 180 天
示例值:2026-07-13 00:00:00
params.endTime String 结束时间,格式 yyyy-MM-dd HH:mm:ss,仅支持查询最近 180 天
示例值:2026-07-20 15:57:29

3. 示例

示例1 查询流量趋势与域名排行

输入示例

{
  "action": [
    {
      "metricName": "trafficRank",
      "pageNo": 1,
      "pageSize": 10
    },
    {
      "metricName": "traffic"
    }
  ],
  "domains": [],
  "interval": "5m",
  "params": {
    "beginTime": "2026-07-13 00:00:00",
    "endTime": "2026-07-20 15:57:29"
  }
}

代码调用

请将 {登录域名}token 替换为实际值。

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class DescribeTrafficDataTest {

    public static void main(String[] args) throws Exception {
        String url = "https://{登录域名}/prod-api/multiCdn/statistic/describeTrafficData";
        String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";

        String requestBody = "{"
                + "\"action\":["
                + "{\"metricName\":\"trafficRank\",\"pageNo\":1,\"pageSize\":10},"
                + "{\"metricName\":\"traffic\"}"
                + "],"
                + "\"domains\":[],"
                + "\"interval\":\"5m\","
                + "\"params\":{"
                + "\"beginTime\":\"2026-07-13 00:00:00\","
                + "\"endTime\":\"2026-07-20 15:57:29\""
                + "}"
                + "}";

        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpPost httpPost = new HttpPost(url);
            httpPost.setHeader("Authorization", "Bearer " + token);
            httpPost.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));

            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
                int statusCode = response.getStatusLine().getStatusCode();
                String body = EntityUtils.toString(response.getEntity(), "UTF-8");
                System.out.println("Status Code: " + statusCode);
                System.out.println("Body: " + body);
            }
        }
    }
}
package main

import (
    "bytes"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://{登录域名}/prod-api/multiCdn/statistic/describeTrafficData"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "action": [
    {"metricName": "trafficRank", "pageNo": 1, "pageSize": 10},
    {"metricName": "traffic"}
  ],
  "domains": [],
  "interval": "5m",
  "params": {
    "beginTime": "2026-07-13 00:00:00",
    "endTime": "2026-07-20 15:57:29"
  }
}`)

    req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(requestBody))
    if err != nil {
        panic(err)
    }
    req.Header.Set("Authorization", "Bearer "+token)
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }
    fmt.Println("Status Code:", resp.StatusCode)
    fmt.Println("Body:", string(body))
}

输出示例

{
  "msg": "成功",
  "code": 200,
  "data": [
    {
      "metricName": "trafficRank",
      "list": [
        {
          "name": "demo.com",
          "value": 12249208789340
        },
        {
          "name": "test.com",
          "value": 1077190784870
        }
      ]
    },
    {
      "metricName": "traffic",
      "objectArrayListMap": {
        "outside_chinese_mainland": [
          [1783872300000, 4439270124],
          [1783872600000, 8560077203],
          [1783872900000, 10278522994]
        ],
        "bytesSent": [
          [1783872300000, 4439270124],
          [1783872600000, 8560077203],
          [1783872900000, 10278522994]
        ]
      },
      "totalMap": {
        "outside_chinese_mainland": 13326595592492,
        "bytesSent": 13326595592492
      }
    }
  ]
}

4. 输出参数

参数名称 类型 描述
code Integer 状态码。示例值:200
msg String 提示信息。示例值:成功
data Array 指标结果列表,顺序与请求 action 一致
data[].metricName String 指标名称,如 traffictrafficRank
data[].list Array 排行数据(trafficRank)。元素含 name(域名)、value(流量字节数)
data[].objectArrayListMap Object 流量时间序列(traffic)。bytesSent 为汇总;其余 key 为区域名。每个点为 [毫秒时间戳, 流量字节数]
data[].totalMap Object 流量合计(traffic)。bytesSent 为总流量;其余 key 为区域合计

5. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限
action 不能为空 未传 action
metricName 只能是 traffic 或 trafficRank metricName 取值非法
无效的interval interval 不是 5m / 1h / 1d
请选择时间范围 未传 params 或缺少 beginTime / endTime
只能查询最近180天的数据 时间范围超出限制