跳转至

查询访问监控数据(V2)

1. 接口描述

接口请求路径:POST /prod-api/cdn/layer7/statistic/v2/describeL7Data

describeL7Data(V2)基于汇聚数据查询访问监控,支持流量、带宽、请求数、状态码、请求耗时等趋势与排行。一次请求可在 action 中声明多个指标,返回的 dataaction 顺序一一对应。

仅支持查询最近 180 天内的数据;单次最多查询 30 个域名。Token 获取方式见 密钥鉴权

2. 输入参数

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

参数名称 必选 类型 描述
action Array 统计指标列表,不能为空
action.metricName String 统计指标,支持以下值:
trafficTrend:流量统计图
trafficRank:流量排行
bandwidthTrend:带宽统计图
requestTrend:请求数统计图
requestRank:请求排行
statusCodeTrend:状态码统计图
statusCodeRank:状态码排行
requestTimeTrend:请求平均时长统计图
示例值:trafficTrend
action.pageNo Integer 页码,从 1 开始,默认 1。排行类指标有效
示例值:1
action.pageSize Integer 每页条数,默认 10。排行类指标有效
示例值:10
domains Array of String 域名过滤。空数组表示当前账号全部域名;单次最多 30 个
示例值:[]
interval String 时间粒度,支持以下值:
1m:1 分钟
5m:5 分钟
1h:1 小时
1d:1 天
不传时按时间跨度自动选择
示例值:1m
otherFilter Array 附属筛选条件
params.beginTime String 开始时间,格式 yyyy-MM-dd HH:mm:ss,仅支持查询最近 180 天
示例值:2025-04-09 00:00:00
params.endTime String 结束时间,格式 yyyy-MM-dd HH:mm:ss,仅支持查询最近 180 天
示例值:2025-04-09 23:59:59

3. 示例

示例1 查询多指标访问监控

输入示例

{
  "interval": "1m",
  "params": {
    "beginTime": "2025-04-09 00:00:00",
    "endTime": "2025-04-09 23:59:59"
  },
  "action": [
    {
      "metricName": "trafficTrend"
    },
    {
      "metricName": "bandwidthTrend"
    },
    {
      "metricName": "requestTrend"
    },
    {
      "metricName": "statusCodeTrend"
    },
    {
      "metricName": "requestTimeTrend"
    },
    {
      "pageSize": 10,
      "pageNo": 1,
      "metricName": "trafficRank"
    },
    {
      "pageSize": 10,
      "pageNo": 1,
      "metricName": "requestRank"
    }
  ],
  "domains": []
}

代码调用

请将 {登录域名}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 DescribeL7DataV2Test {

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

        String requestBody = "{"
                + "\"interval\":\"1m\","
                + "\"params\":{"
                + "\"beginTime\":\"2025-04-09 00:00:00\","
                + "\"endTime\":\"2025-04-09 23:59:59\""
                + "},"
                + "\"action\":["
                + "{\"metricName\":\"trafficTrend\"},"
                + "{\"metricName\":\"bandwidthTrend\"},"
                + "{\"metricName\":\"requestTrend\"},"
                + "{\"metricName\":\"statusCodeTrend\"},"
                + "{\"metricName\":\"requestTimeTrend\"},"
                + "{\"pageSize\":10,\"pageNo\":1,\"metricName\":\"trafficRank\"},"
                + "{\"pageSize\":10,\"pageNo\":1,\"metricName\":\"requestRank\"}"
                + "],"
                + "\"domains\":[]"
                + "}";

        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/cdn/layer7/statistic/v2/describeL7Data"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "interval": "1m",
  "params": {
    "beginTime": "2025-04-09 00:00:00",
    "endTime": "2025-04-09 23:59:59"
  },
  "action": [
    {"metricName": "trafficTrend"},
    {"metricName": "bandwidthTrend"},
    {"metricName": "requestTrend"},
    {"metricName": "statusCodeTrend"},
    {"metricName": "requestTimeTrend"},
    {"pageSize": 10, "pageNo": 1, "metricName": "trafficRank"},
    {"pageSize": 10, "pageNo": 1, "metricName": "requestRank"}
  ],
  "domains": []
}`)

    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": "trafficTrend",
      "objectArrayListMap": {
        "upstreamBytesSent": [],
        "totalBytesSent": [],
        "bytesSent": []
      },
      "totalMap": {
        "upstreamBytesSent": 0,
        "totalBytesSent": 0,
        "bytesSent": 0
      }
    },
    {
      "metricName": "bandwidthTrend",
      "objectArrayListMap": {
        "upstreamBytesSent": [],
        "totalBytesSent": [],
        "bytesSent": []
      },
      "maxMap": {
        "upstreamBytesSent": 0,
        "totalBytesSent": 0,
        "bytesSent95Peak": 0,
        "bytesSent": 0,
        "totalBytesSent95Peak": 0,
        "upstreamBytesSent95Peak": 0
      }
    },
    {
      "metricName": "requestTrend",
      "objectArrayListMap": {
        "requestCounter": []
      },
      "totalMap": {
        "requestCounter": 0
      }
    },
    {
      "metricName": "statusCodeTrend",
      "objectArrayListMap": {
        "list5xx": [],
        "list4xx": [],
        "list3xx": [],
        "list2xx": [],
        "list1xx": []
      },
      "totalMap": {
        "1xx": 0,
        "2xx": 0,
        "3xx": 0,
        "4xx": 0,
        "5xx": 0
      }
    },
    {
      "metricName": "requestTimeTrend",
      "objectArrayListMap": {
        "requestTime": []
      }
    },
    {
      "metricName": "trafficRank",
      "list": [],
      "total": 0
    },
    {
      "metricName": "requestRank",
      "list": [],
      "total": 0
    }
  ]
}

4. 输出参数

参数名称 类型 描述
code Integer 状态码。示例值:200
msg String 提示信息。示例值:成功
data Array 指标结果列表,顺序与请求 action 一致
data[].metricName String 指标名称
data[].objectArrayListMap Object 趋势序列。流量/带宽含 bytesSent(下行)、upstreamBytesSent(上行)、totalBytesSent(合计);请求含 requestCounter;状态码含 list1xx~list5xx;请求耗时含 requestTime。每个点为 [毫秒时间戳, 数值]
data[].totalMap Object 合计值。流量含上下行与合计字节数;请求含 requestCounter;状态码含 1xx~5xx
data[].maxMap Object 峰值(带宽类)。含上下行峰值及 95 峰值字段,如 bytesSent95Peak
data[].list Array 排行列表(trafficRank / requestRank / statusCodeRank
data[].total Integer 排行总条数

5. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限
请选择时间范围 未传 params 或缺少 beginTime / endTime
只能查询最近180天的数据 时间范围超出限制
一次性最多查询30个域名 domains 超过 30 个
无效的interval interval 不是 1m / 5m / 1h / 1d
查询失败,请确认查询参数是否合法 查询执行失败或参数非法