跳转到主要内容
GET
/
varz
curl -X GET "http://localhost:5001/varz?sort=in_msgs&conn_limit=50"
{
  "server_id": "wukongim-node-1",
  "version": "2.0.0",
  "git_commit": "abc123def",
  "go_version": "go1.21.0",
  "start": "2024-01-15T08:00:00Z",
  "now": "2024-01-15T10:30:00Z",
  "uptime": "2h30m0s",
  "connections": 1250,
  "total_connections": 15000,
  "in_msgs": 125000,
  "out_msgs": 130000,
  "in_bytes": 12500000,
  "out_bytes": 13000000,
  "slow_consumers": 5,
  "subscriptions": 8500,
  "http_req_stats": {
    "uri_stats": [
      {
        "uri": "/message/send",
        "count": 5000,
        "avg_time": "15ms"
      },
      {
        "uri": "/channel/create",
        "count": 200,
        "avg_time": "25ms"
      }
    ]
  },
  "cpu": 15.5,
  "mem": 536870912,
  "config": {
    "max_connections": 10000,
    "max_subscriptions_per_conn": 100,
    "max_payload": 1048576
  }
}

概述

获取 WuKongIM 系统的运行时变量和性能指标,用于系统监控和性能分析。

查询参数

sort
string
default:"in_msgs"
排序字段
  • in_msgs - 按接收消息数排序
  • out_msgs - 按发送消息数排序
  • in_bytes - 按接收字节数排序
  • out_bytes - 按发送字节数排序
conn_limit
integer
default:20
连接信息限制数量
node_id
integer
指定节点 ID(集群环境)
curl -X GET "http://localhost:5001/varz?sort=in_msgs&conn_limit=50"
{
  "server_id": "wukongim-node-1",
  "version": "2.0.0",
  "git_commit": "abc123def",
  "go_version": "go1.21.0",
  "start": "2024-01-15T08:00:00Z",
  "now": "2024-01-15T10:30:00Z",
  "uptime": "2h30m0s",
  "connections": 1250,
  "total_connections": 15000,
  "in_msgs": 125000,
  "out_msgs": 130000,
  "in_bytes": 12500000,
  "out_bytes": 13000000,
  "slow_consumers": 5,
  "subscriptions": 8500,
  "http_req_stats": {
    "uri_stats": [
      {
        "uri": "/message/send",
        "count": 5000,
        "avg_time": "15ms"
      },
      {
        "uri": "/channel/create",
        "count": 200,
        "avg_time": "25ms"
      }
    ]
  },
  "cpu": 15.5,
  "mem": 536870912,
  "config": {
    "max_connections": 10000,
    "max_subscriptions_per_conn": 100,
    "max_payload": 1048576
  }
}

响应字段

服务器信息

server_id
string
required
服务器标识符
version
string
required
WuKongIM 版本号
git_commit
string
required
Git 提交哈希
go_version
string
required
Go 语言版本

运行时信息

start
string
required
服务器启动时间(ISO 8601 格式)
now
string
required
当前时间(ISO 8601 格式)
uptime
string
required
运行时长

连接统计

connections
integer
required
当前连接数
total_connections
integer
required
总连接数(历史累计)
slow_consumers
integer
required
慢消费者数量
subscriptions
integer
required
订阅总数

消息统计

in_msgs
integer
required
接收消息总数
out_msgs
integer
required
发送消息总数
in_bytes
integer
required
接收字节总数
out_bytes
integer
required
发送字节总数

HTTP 请求统计

http_req_stats
object
required
HTTP 请求统计信息

系统资源

cpu
number
required
CPU 使用率(百分比)
mem
integer
required
内存使用量(字节)

配置信息

config
object
required
系统配置信息

状态码

状态码说明
200成功获取系统变量
500服务器内部错误

监控指标说明

性能指标

指标说明正常范围告警阈值
CPU 使用率服务器 CPU 占用百分比< 70%> 80%
内存使用量服务器内存占用< 80%> 90%
连接数当前活跃连接数根据配置接近最大值
慢消费者处理缓慢的连接数< 5%> 10%

吞吐量指标

指标说明监控重点
消息接收速率每秒接收消息数突增或突降
消息发送速率每秒发送消息数与接收速率的比例
字节传输速率网络传输速度带宽使用情况
HTTP 请求统计API 调用频率和响应时间热点 API 和性能瓶颈

最佳实践

  1. 定期监控:建议每 30-60 秒获取一次系统变量
  2. 告警设置:为关键指标设置合理的告警阈值
  3. 趋势分析:记录历史数据,分析系统性能趋势
  4. 容量规划:根据监控数据进行容量规划
  5. 性能优化:识别性能瓶颈并进行优化
  6. 集群监控:在集群环境中监控所有节点的状态