Files
2026-03-01 01:43:46 +08:00

101 lines
4.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 网关转发记录曲线图接口说明
## 接口概述
新增了一个高效的曲线图数据查询接口,用于展示网关转发记录的统计数据。该接口支持多种时间粒度的聚合查询,并提供丰富的过滤条件。
## 接口信息
- **接口路径**: `POST /gateway/record/chart`
- **请求方式**: POST
- **Content-Type**: application/json
## 请求参数
### 必填参数
| 参数名 | 类型 | 说明 | 示例 |
|--------|------|------|------|
| startTime | LocalDateTime | 查询开始时间 | "2024-01-01 00:00:00" |
| endTime | LocalDateTime | 查询结束时间 | "2024-01-01 23:59:59" |
| timeGranularity | String | 时间粒度 | "5MIN" |
### 时间粒度选项
| 值 | 说明 | 聚合方式 |
|----|------|----------|
| 5MIN | 5分钟 | 按5分钟间隔聚合(00:00-00:04, 00:05-00:09…) |
| 1HOUR | 1小时 | 按小时聚合 |
| 1DAY | 1天 | 按天聚合 |
| 1WEEK | 1周 | 按周聚合(周一为起始) |
| 1MONTH | 1月 | 按月聚合 |
### 可选过滤参数
| 参数名 | 类型 | 说明 | 是否支持模糊查询 |
|--------|------|------|------------------|
| requestUrl | String | 接口路径 | ✅ |
| method | String | 请求方法 | ❌ |
| targetEndpoint | String | 目的地址 | ✅ |
| httpCode | Integer | HTTP状态码 | ❌ |
| gatewayEndpoint | String | 网关地址 | ✅ |
| minCostTime | Integer | 最小耗时(ms) | ❌ |
| maxCostTime | Integer | 最大耗时(ms) | ❌ |
| routeId | Long | 路由ID | ❌ |
| routeName | String | 路由名称 | ✅ |
## 请求示例
```json
{
"startTime": "2024-01-01 00:00:00", "endTime": "2024-01-01 23:59:59", "timeGranularity": "1HOUR", "requestUrl": "/api/user", "method": "GET", "minCostTime": 100, "maxCostTime": 5000}
```
## 响应数据结构
```json
{
"code": 200, "msg": "操作成功",
"data": { "dataPoints": [ { "timePoint": "2024-01-01 00:00:00", "count2xx": 150, "count4xx": 10, "count5xx": 2, "countOther": 1, "avgCostTime": 245.67 }, { "timePoint": "2024-01-01 01:00:00", "count2xx": 200, "count4xx": 15, "count5xx": 3, "countOther": 0, "avgCostTime": 198.34 } ] }}
```
## 响应字段说明
### dataPoints 数组中每个元素的字段
| 字段名 | 类型 | 说明 |
|--------|------|------|
| timePoint | LocalDateTime | 时间点(X轴) |
| count2xx | Long | 2xx状态码请求次数(左Y轴) |
| count4xx | Long | 4xx状态码请求次数(左Y轴) |
| count5xx | Long | 5xx状态码请求次数(左Y轴) |
| countOther | Long | 其他状态码请求次数(左Y轴) |
| avgCostTime | BigDecimal | 平均耗时ms,保留2位小数(右Y轴) |
## 性能优化说明
1. **索引优化**: 建议在 `request_time` 字段上创建索引以提高查询效率
2. **模糊查询**: 仅在 `requestUrl`、`targetEndpoint`、`gatewayEndpoint`、`routeName` 字段支持模糊查询
3. **时间范围**: 建议查询时间范围不要过大,以保证响应速度
4. **聚合查询**: 使用数据库层面的聚合查询,减少内存占用
## 前端图表建议
- **左Y轴**: 显示请求次数(count2xx, count4xx, count5xx, countOther
- **右Y轴**: 显示平均耗时(avgCostTime
- **X轴**: 显示时间(timePoint
- **图表类型**: 建议使用折线图或柱状图
- **颜色建议**:
- 2xx: 绿色(成功)
- 4xx: 橙色(客户端错误)
- 5xx: 红色(服务器错误)
- 其他: 灰色
- 平均耗时: 蓝色
## 注意事项
1. 时间粒度为左闭右开区间
2. 大数据量查询时建议适当限制时间范围
3. 模糊查询会影响性能,请谨慎使用
4. 平均耗时为0表示该时间段内没有有效的耗时数据