API统计信息查询-最近一段时间
功能介绍
根据API的id和最近的一段时间查询API被调用的次数,统计周期为1分钟、小时、天。
- 查询范围一小时以内,一分钟一个样本,其样本值为一分钟内的累计值,服务器返回服务器的时间的上一分钟到往前推N分钟的数据;
- 查询范围一天以内,返回一小时一个样本,其样本值为一小时内的累计值,服务器会返回最近时长横跨统计周期的数据,比如时长为大于2小时,且小于3小时,那么会查询最近3个小时的数据;
- 查询超过一天以上,返回一天为一个样本,其样本值为一天内的累计值,服务器会返回最近时长横跨统计周期的数据。
为了安全起见,在服务器上使用curl命令调用接口查询信息后,需要清理历史操作记录,包括但不限于“~/.bash_history”、“/var/log/messages”(如有)。
URI
HTTP/HTTPS请求方法以及URI如下表所示。
| 请求方法 | URI |
|---|---|
| GET | /v1.0/apigw/statistics/api/latest?api_id=[api_id]&duration=[duration] |
请求消息
| 参数 | 是否必选 | 类型 | 说明 |
|---|---|---|---|
| api_id | 是 | String | API的id |
| duration | 是 | String | 最近统计时长,单位必须为h和m,比如1h和1m,分别代表最近1小时和最近1分钟 |
响应消息
| 参数 | 类型 | 说明 | 操作类型 |
|---|---|---|---|
| code | String | 响应码 | R |
| msg | String | 返回消息 | R |
| start_time | Long | 开始时间的UTC的时间戳 | R |
| end_time | Long | 截止时间的UTC的时间戳 | R |
| list | 结构体数据类型 | 统计指标的数据结构结构体 | R |
| 参数 | 类型 | 说明 | 操作类型 |
|---|---|---|---|
| cycle | String | 统计周期(预留) | R |
| api_id | String | API的id | R |
| current_minute | Long | API访问的UTC时间戳 | R |
| group_id | String | API的分组ID | R |
| provider | String | API拥有者 | R |
| req_count | Integer | 请求总次数 | R |
| max_latency | Integer | 最大延时 | R |
| avg_latency | Double | 平均耗时 | R |
| max_backend_latency | Integer | 最大后端延时 | R |
| avg_backend_latency | Double | 平均后端延时 | R |
| max_inner_latency | Integer | 最大网关内部延时 | R |
| avg_inner_latency | Double | 平均网关内部延时 | R |
| output_throughput | Integer | 下行吞吐量(byte) | R |
| input_throughput | Integer | 上行吞吐量(byte) | R |
| req_count4xx | Integer | 4xx响应码总次数 | R |
| req_count5xx | Integer | 5xx响应码总次数 | R |
| req_count2xx | Integer | 2xx响应码总次数 | R |
| req_count_error | Integer | 错误次数 | R |
| register_time | String | 记录时间(yyy-MM-dd HH:mm:ss) | R |
| req_time | String | API请求时间(yyy-MM-dd HH:mm:ss) | R |
| status | Integer | 状态-预留 | R |
响应消息样例:
{
"code":"APIG.0000",
"msg":"",
"start_time":1524735000,
"end_time":1524735000,
"list":[
{
"api_id":"ae12b59fef2e4c6b8e01d44e98b738c0",
"current_minute":1524735000,
"group_id":"26463e4b2445415eabb55b2414012989",
"provider":"d4ef919b31bd43d3927c5d46c71b68c4",
"req_count":45,
"max_latency":59,
"avg_latency":2.53,
"max_backend_latency":0,
"avg_backend_latency":0,
"max_inner_latency":59,
"avg_inner_latency":2.53,
"output_throughput":31815,
"input_throughput":334474,
"req_count4xx":0,
"req_count5xx":0,
"req_count2xx":45,
"req_count_error":0,
"register_time":"2018-04-26 17:30:48",
"req_time":"2018-04-26 17:30:00",
"status":1
}
]
}
状态码
| 状态码 | 说明 |
|---|---|
| 200 | Query Success |