This topic describes how to obtain session statistics of a tenant by using an API, including statistics by database, user, and client IP.
API description
If a password is set, you must pass authentication. For more information, see API hybrid encryption.
Request path
GET /api/v1/tenant/:name/sessions/stats
Request parameters
Parameter |
Type |
Required |
Example value |
Description |
|---|---|---|---|---|
| name | string | Yes | t1 | The name of the tenant. This parameter is specified in the path. |
Response
Parameter |
Type |
Description |
|---|---|---|
| successful | bool | Indicates whether the request was successful. |
| timestamp | time.Time | The timestamp when the server completed the request. |
| duration | int | The time taken by the server to process the request, in milliseconds. |
| status | int | The HTTP status code. |
| traceId | string | The trace ID of the request. |
| data | TenantSession | The details of the returned session. For more information, see the TenantSessionStats data structure in the following section. |
| error | ApiError | The error information returned by the request. The error information contains the following parameters:
|
TenantSessionStats data structure:
Parameter |
Type |
Description |
|---|---|---|
| total_count | int | The total number of sessions. |
| active_count | int | The number of active sessions. |
| max_active_time | float64 | The maximum active time, in seconds. |
| db_stats | []TenantSessionDbStats | The session statistics by database. The statistics contain the following information:
|
| user_stats | []TenantSessionUserStats | The session statistics by user. The statistics contain the following information:
|
| client_stats | []TenantSessionClientStats | The session statistics by client IP address. The statistics contain the following information:
|
Examples
Request example
GET 10.10.10.1:2886/api/v1/tenant/t1/sessions/stats
Response example
{
"successful": true,
"timestamp": "2025-10-14T15:16:01.277047628+08:00",
"duration": 30,
"status": 200,
"traceId": "e6f64ba7f54e7a49",
"data": {
"total_count": 10,
"active_count": 5,
"max_active_time": 3600.5,
"db_stats": [
{
"db_name": "test",
"total_count": 8,
"active_count": 4
},
{
"db_name": "sys",
"total_count": 2,
"active_count": 1
}
],
"user_stats": [
{
"user_name": "root",
"total_count": 7,
"active_count": 3
},
{
"user_name": "admin",
"total_count": 3,
"active_count": 2
}
],
"client_stats": [
{
"client_ip": "10.10.10.100",
"total_count": 6,
"active_count": 3
},
{
"client_ip": "10.10.10.101",
"total_count": 4,
"active_count": 2
}
]
}
}
