curl -X GET "http://localhost:5001/connz?offset=0&limit=50&subs=1"
const response = await fetch('http://localhost:5001/connz?offset=0&limit=50&subs=1');
const data = await response.json();
console.log(data);
import requests
params = {
'offset': 0,
'limit': 50,
'subs': 1
}
response = requests.get('http://localhost:5001/connz', params=params)
data = response.json()
print(data)
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
resp, err := http.Get("http://localhost:5001/connz?offset=0&limit=50&subs=1")
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"now": "2024-01-15T10:30:00Z",
"num_connections": 1250,
"total": 1250,
"offset": 0,
"limit": 50,
"connections": [
{
"cid": 12345,
"uid": "user123",
"ip": "192.168.1.100",
"port": 54321,
"start": "2024-01-15T09:15:30Z",
"last_activity": "2024-01-15T10:29:45Z",
"uptime": "1h14m15s",
"idle": "15s",
"pending_bytes": 0,
"in_msgs": 156,
"out_msgs": 203,
"in_bytes": 15680,
"out_bytes": 25440,
"subscriptions": 8,
"device_flag": 1,
"device_level": 1,
"version": "1.0.0"
}
]
}
监控
获取连接信息
获取当前服务器的连接统计信息
GET
/
connz
curl -X GET "http://localhost:5001/connz?offset=0&limit=50&subs=1"
const response = await fetch('http://localhost:5001/connz?offset=0&limit=50&subs=1');
const data = await response.json();
console.log(data);
import requests
params = {
'offset': 0,
'limit': 50,
'subs': 1
}
response = requests.get('http://localhost:5001/connz', params=params)
data = response.json()
print(data)
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
resp, err := http.Get("http://localhost:5001/connz?offset=0&limit=50&subs=1")
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"now": "2024-01-15T10:30:00Z",
"num_connections": 1250,
"total": 1250,
"offset": 0,
"limit": 50,
"connections": [
{
"cid": 12345,
"uid": "user123",
"ip": "192.168.1.100",
"port": 54321,
"start": "2024-01-15T09:15:30Z",
"last_activity": "2024-01-15T10:29:45Z",
"uptime": "1h14m15s",
"idle": "15s",
"pending_bytes": 0,
"in_msgs": 156,
"out_msgs": 203,
"in_bytes": 15680,
"out_bytes": 25440,
"subscriptions": 8,
"device_flag": 1,
"device_level": 1,
"version": "1.0.0"
}
]
}
概述
获取当前服务器的连接统计信息,包括连接数量、用户分布等监控数据。查询参数
integer
默认值:0
偏移量,用于分页
integer
默认值:20
限制数量,用于分页
integer
默认值:0
是否包含订阅信息
0- 不包含订阅信息1- 包含订阅信息
curl -X GET "http://localhost:5001/connz?offset=0&limit=50&subs=1"
const response = await fetch('http://localhost:5001/connz?offset=0&limit=50&subs=1');
const data = await response.json();
console.log(data);
import requests
params = {
'offset': 0,
'limit': 50,
'subs': 1
}
response = requests.get('http://localhost:5001/connz', params=params)
data = response.json()
print(data)
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
resp, err := http.Get("http://localhost:5001/connz?offset=0&limit=50&subs=1")
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"now": "2024-01-15T10:30:00Z",
"num_connections": 1250,
"total": 1250,
"offset": 0,
"limit": 50,
"connections": [
{
"cid": 12345,
"uid": "user123",
"ip": "192.168.1.100",
"port": 54321,
"start": "2024-01-15T09:15:30Z",
"last_activity": "2024-01-15T10:29:45Z",
"uptime": "1h14m15s",
"idle": "15s",
"pending_bytes": 0,
"in_msgs": 156,
"out_msgs": 203,
"in_bytes": 15680,
"out_bytes": 25440,
"subscriptions": 8,
"device_flag": 1,
"device_level": 1,
"version": "1.0.0"
}
]
}
响应字段
string
必填
当前服务器时间(ISO 8601 格式)
integer
必填
当前连接数量
integer
必填
总连接数量
integer
必填
当前偏移量
integer
必填
当前限制数量
array
必填
状态码
| 状态码 | 说明 |
|---|---|
| 200 | 成功获取连接信息 |
| 500 | 服务器内部错误 |
最佳实践
- 分页查询:对于大量连接,使用分页避免性能问题
- 定期监控:设置合理的监控间隔,避免过于频繁
- 告警机制:设置连接数、活跃度等关键指标的告警
- 数据导出:支持连接数据的导出和分析
- 性能优化:监控连接的性能指标,及时发现问题
- 安全监控:关注异常 IP 的连接情况
最佳实践
- 分页查询:对于大量连接,使用分页避免性能问题
- 定期监控:设置合理的监控间隔,避免过于频繁
- 告警机制:设置连接数、活跃度等关键指标的告警
- 数据导出:支持连接数据的导出和分析
- 性能优化:监控连接的性能指标,及时发现问题
- 安全监控:关注异常 IP 的连接情况
⌘I

