跳转到主要内容
GET
/
connz
curl -X GET "http://localhost:5001/connz?offset=0&limit=50&subs=1"
{
  "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"
    }
  ]
}

概述

获取当前服务器的连接统计信息,包括连接数量、用户分布等监控数据。

查询参数

offset
integer
default:0
偏移量,用于分页
limit
integer
default:20
限制数量,用于分页
subs
integer
default:0
是否包含订阅信息
  • 0 - 不包含订阅信息
  • 1 - 包含订阅信息
curl -X GET "http://localhost:5001/connz?offset=0&limit=50&subs=1"
{
  "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"
    }
  ]
}

响应字段

now
string
required
当前服务器时间(ISO 8601 格式)
num_connections
integer
required
当前连接数量
total
integer
required
总连接数量
offset
integer
required
当前偏移量
limit
integer
required
当前限制数量
connections
array
required
连接详情列表

状态码

状态码说明
200成功获取连接信息
500服务器内部错误

最佳实践

  1. 分页查询:对于大量连接,使用分页避免性能问题
  2. 定期监控:设置合理的监控间隔,避免过于频繁
  3. 告警机制:设置连接数、活跃度等关键指标的告警
  4. 数据导出:支持连接数据的导出和分析
  5. 性能优化:监控连接的性能指标,及时发现问题
  6. 安全监控:关注异常 IP 的连接情况

最佳实践

  1. 分页查询:对于大量连接,使用分页避免性能问题
  2. 定期监控:设置合理的监控间隔,避免过于频繁
  3. 告警机制:设置连接数、活跃度等关键指标的告警
  4. 数据导出:支持连接数据的导出和分析
  5. 性能优化:监控连接的性能指标,及时发现问题
  6. 安全监控:关注异常 IP 的连接情况