查询 Trace 指标
更新时间:2026-06-26
DescribeTraceMetricData
Trace指标查询,基于调用链数据计算指标,支持GroupBy分组、时间聚合及聚合值计算。
API Explorer
去调试
您可以在 API Explorer 中直接运行该接口,免去您计算签名的困扰。运行成功后,API Explorer 可以自动生成 SDK 代码示例。
请求结构
Plain Text
1POST /v1/apm/query?action=DescribeTraceMetricData HTTP/1.1
2Host: apm.bj.baidubce.com
3Authorization: authorization string
4
5{
6 "beginDatetime": "20241011T10:10:10Z",
7 "endDatetime": "20241011T10:25:10Z",
8 "metrics": [
9 {
10 "name": "apm_requests_count"
11 }
12 ],
13 "filters": [
14 {
15 "key": "service.name",
16 "op": "=",
17 "value": "mall-gateway"
18 }
19 ],
20 "groupBy": ["attributes.http.response.status_code"],
21 "periodSeconds": 60,
22 "aggregate": ["sum", "sumPerSecond"]
23}
请求头域
除公共头域外,无其他特殊头域
请求参数
| 参数名称 | 类型 | 是否必需 | 参数位置 | 描述 |
|---|---|---|---|---|
| version | String | 是 | URL参数 | API版本号,当前取值为v1 |
| action | String | 是 | URL参数 | API接口名称,当前取值为DescribeTraceMetricData |
| beginDatetime | String | 是 | RequestBody参数 | 开始时间,UTC时间 |
| endDatetime | String | 是 | RequestBody参数 | 结束时间,UTC时间 |
| metrics | List<TraceMetricQuery> | 是 | RequestBody参数 | 指标名列表。可选指标:apm_requests_count(请求数)、apm_error_requests_count(错误数)、apm_requests_seconds_avg(平均请求耗时)、apm_requests_seconds_p90(90分位耗时)、apm_requests_seconds_p95(95分位耗时)、apm_requests_seconds_p99(99分位耗时) |
| metrics.name | String | 是 | RequestBody参数 | 指标名 |
| filters | List<Filter> | 否 | RequestBody参数 | 过滤项列表 |
| groupBy | List |
否 | RequestBody参数 | GroupBy列表。可选项:attributes.http.response.status_code(http响应code) |
| periodSeconds | Integer | 否 | RequestBody参数 | 按时间聚合周期,单位:秒。每periodSeconds秒计算一个聚合点。若为0或未设置,表示从起止时间只计算一个聚合点。默认值:0 |
| aggregate | List |
否 | RequestBody参数 | 返回聚合值。可选项:sum(求和)、sumPerSecond(求和后计算每秒平均值) |
返回状态码
成功返回200,失败返回见错误码
返回头域
除公共头域外,无其他特殊头域
返回参数
| 参数名称 | 类型 | 描述 |
|---|---|---|
| success | Boolean | 请求是否成功 |
| code | String | 状态码 |
| message | String | 错误信息 |
| timeseries | List<Timeseries> | 时序数据列表 |
| aggregate | AggregateResult | 聚合值,若在请求中设置了aggregate参数则返回 |
请求示例
Plain Text
1POST /v1/apm/query?action=DescribeTraceMetricData HTTP/1.1
2HOST apm.bj.baidubce.com
3Authorization bce-auth-v1/...
4
5{
6 "beginDatetime": "20241011T10:10:10Z",
7 "endDatetime": "20241011T10:25:10Z",
8 "metrics": [
9 {
10 "name": "apm_requests_count"
11 }
12 ],
13 "filters": [
14 {
15 "key": "service.name",
16 "op": "=",
17 "value": "mall-gateway"
18 }
19 ],
20 "groupBy": ["attributes.http.response.status_code"],
21 "periodSeconds": 60,
22 "aggregate": ["sum", "sumPerSecond"]
23}
响应示例
Plain Text
1HTTP/1.1 200 OK
2x-bce-request-id: request-id-example
3Date: Wed, 08 Jan 2025 03:25:48 GMT
4Transfer-Encoding: chunked
5Content-Type: application/json;charset=UTF-8
6Server: BWS
7
8{
9 "success": true,
10 "code": "OK",
11 "message": "",
12 "timeseries": [
13 {
14 "metric": "apm_requests_count",
15 "dimensions": [
16 {
17 "key": "span.kind",
18 "value": "client"
19 },
20 {
21 "key": "service.name",
22 "value": "java-order-service"
23 }
24 ],
25 "data": [
26 [1656428160, 100],
27 [1656428220, 110]
28 ]
29 }
30 ],
31 "aggregate": {
32 "sum": 100,
33 "sumPerSecond": 10.0
34 }
35}
评价此篇文章
