curl -X GET "http://localhost:5001/varz?sort=in_msgs&conn_limit=50"
const response = await fetch('http://localhost:5001/varz?sort=in_msgs&conn_limit=50');
const data = await response.json();
console.log(data);
import requests
params = {
'sort': 'in_msgs',
'conn_limit': 50
}
response = requests.get('http://localhost:5001/varz', params=params)
data = response.json()
print(data)
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
resp, err := http.Get("http://localhost:5001/varz?sort=in_msgs&conn_limit=50")
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)
}
{
"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
}
}
监控
获取系统变量
获取系统变量和性能指标
GET
/
varz
curl -X GET "http://localhost:5001/varz?sort=in_msgs&conn_limit=50"
const response = await fetch('http://localhost:5001/varz?sort=in_msgs&conn_limit=50');
const data = await response.json();
console.log(data);
import requests
params = {
'sort': 'in_msgs',
'conn_limit': 50
}
response = requests.get('http://localhost:5001/varz', params=params)
data = response.json()
print(data)
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
resp, err := http.Get("http://localhost:5001/varz?sort=in_msgs&conn_limit=50")
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)
}
{
"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 系统的运行时变量和性能指标,用于系统监控和性能分析。查询参数
string
默认值:"in_msgs"
排序字段
in_msgs- 按接收消息数排序out_msgs- 按发送消息数排序in_bytes- 按接收字节数排序out_bytes- 按发送字节数排序
integer
默认值:20
连接信息限制数量
integer
指定节点 ID(集群环境)
curl -X GET "http://localhost:5001/varz?sort=in_msgs&conn_limit=50"
const response = await fetch('http://localhost:5001/varz?sort=in_msgs&conn_limit=50');
const data = await response.json();
console.log(data);
import requests
params = {
'sort': 'in_msgs',
'conn_limit': 50
}
response = requests.get('http://localhost:5001/varz', params=params)
data = response.json()
print(data)
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
resp, err := http.Get("http://localhost:5001/varz?sort=in_msgs&conn_limit=50")
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)
}
{
"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
}
}
响应字段
服务器信息
string
必填
服务器标识符
string
必填
WuKongIM 版本号
string
必填
Git 提交哈希
string
必填
Go 语言版本
运行时信息
string
必填
服务器启动时间(ISO 8601 格式)
string
必填
当前时间(ISO 8601 格式)
string
必填
运行时长
连接统计
integer
必填
当前连接数
integer
必填
总连接数(历史累计)
integer
必填
慢消费者数量
integer
必填
订阅总数
消息统计
integer
必填
接收消息总数
integer
必填
发送消息总数
integer
必填
接收字节总数
integer
必填
发送字节总数
HTTP 请求统计
系统资源
number
必填
CPU 使用率(百分比)
integer
必填
内存使用量(字节)
配置信息
状态码
| 状态码 | 说明 |
|---|---|
| 200 | 成功获取系统变量 |
| 500 | 服务器内部错误 |
监控指标说明
性能指标
| 指标 | 说明 | 正常范围 | 告警阈值 |
|---|---|---|---|
| CPU 使用率 | 服务器 CPU 占用百分比 | < 70% | > 80% |
| 内存使用量 | 服务器内存占用 | < 80% | > 90% |
| 连接数 | 当前活跃连接数 | 根据配置 | 接近最大值 |
| 慢消费者 | 处理缓慢的连接数 | < 5% | > 10% |
吞吐量指标
| 指标 | 说明 | 监控重点 |
|---|---|---|
| 消息接收速率 | 每秒接收消息数 | 突增或突降 |
| 消息发送速率 | 每秒发送消息数 | 与接收速率的比例 |
| 字节传输速率 | 网络传输速度 | 带宽使用情况 |
| HTTP 请求统计 | API 调用频率和响应时间 | 热点 API 和性能瓶颈 |
最佳实践
- 定期监控:建议每 30-60 秒获取一次系统变量
- 告警设置:为关键指标设置合理的告警阈值
- 趋势分析:记录历史数据,分析系统性能趋势
- 容量规划:根据监控数据进行容量规划
- 性能优化:识别性能瓶颈并进行优化
- 集群监控:在集群环境中监控所有节点的状态
⌘I

