Querying API Calls Within a Period
Function
This API is used to query the number of times an API is called during a period. The query can be based on 1 minute, 1 hour, or 1 day.
- If the time range is within one hour, the server returns data of the latest N minutes, with the number of API calls collected every minute.
- If the time range is within one day, the server returns data of the latest N hours (or N + 1 hours if N is not an integer), with the number of API calls collected every hour. For example, if the time range is within 2 to 3 hours, data of the latest 2 + 1 hours will be returned.
- If the time range is longer than one day, the server returns data of the latest N days (or N + 1 days if N is not an integer), with the number of API calls collected every day.
For security purposes, clear your operation records, including but not limited to records in the ~/.bash_history and /var/log/messages directories (if any), after running the curl command on the server to query information.
URI
The following table lists the HTTP/HTTPS request method and URI of the API.
| Request Method | URI |
|---|---|
| GET | /v1.0/apigw/statistics/api/latest?api_id=[api_id]&duration=[duration] |
Request
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| api_id | Yes | String | API ID |
| duration | Yes | String | Time range (unit: h or m). For example, 1h refers to the latest 1 hour and 1m refers to the latest 1 minute. |
Response
| Parameter | Type | Description | Operation Type |
|---|---|---|---|
| code | String | Response code | R |
| msg | String | Response message | R |
| start_time | Long | Timestamp (UTC) of the start time | R |
| end_time | Long | Timestamp (UTC) of the end time | R |
| list | Structure | Statistic data | R |
| Parameter | Type | Description | Operation Type |
|---|---|---|---|
| cycle | String | Interval (reserved) | R |
| api_id | String | API ID | R |
| current_minute | Long | Timestamp (UTC) of API access | R |
| group_id | String | API group ID | R |
| provider | String | API provider | R |
| req_count | Integer | Total number of requests | R |
| max_latency | Integer | Maximum latency | R |
| avg_latency | Double | Average latency | R |
| max_backend_latency | Integer | Maximum backend latency | R |
| avg_backend_latency | Double | Average backend latency | R |
| max_inner_latency | Integer | Maximum gateway latency | R |
| avg_inner_latency | Double | Average gateway latency | R |
| output_throughput | Integer | Downstream throughput (bytes) | R |
| input_throughput | Integer | Upstream throughput (bytes) | R |
| req_count4xx | Integer | Total number of 4xx response codes | R |
| req_count5xx | Integer | Total number of 5xx response codes | R |
| req_count2xx | Integer | Total number of 2xx response codes | R |
| req_count_error | Integer | Number of errors | R |
| register_time | String | Recording time (yyy-MM-dd HH:mm:ss) | R |
| req_time | String | API request time (yyy-MM-dd HH:mm:ss) | R |
| status | Integer | Status (reserved) | R |
Example response:
{
"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
}
]
}
Status Codes
| Status Code | Description |
|---|---|
| 200 | Query Success |
Last Article: Querying Metrics
Next Article: Querying API Calls Under an API Group in the Last One Hour
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.