feat: show node connection status and traffic stats in admin panel

Enable sing-box Clash/V2Ray APIs for per-user metrics, persist cumulative
traffic in SQLite, and refresh the dashboard every five seconds.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-16 09:57:16 +08:00
parent f0a3317e8b
commit ccf7e2a4c7
12 changed files with 595 additions and 3 deletions
+2
View File
@@ -89,6 +89,8 @@ bash scripts/install.sh
| 添加节点 | 自动生成 UUID + Hy2 密码,更新 sing-box |
| 复制链接 | VLESS Reality + Hysteria2 分享链接 |
| 删除节点 | 至少保留 1 个节点 |
| 连接状态 | 在线/离线、当前连接数(Clash API) |
| 流量统计 | 实时速率 + 累计上下行(V2Ray 统计,重启 sing-box 后继续累计) |
---
+21
View File
@@ -37,10 +37,31 @@ curl -I "http://66.hyf2.cc/$(grep ^PANEL_PATH= /opt/jiedian/.env | cut -d= -f2)/
> 443 端口已被 sing-box Reality 占用,面板走 80 端口子路径。请妥善保管 `PANEL_PATH`,相当于隐藏入口。
面板可查看每个节点的 **在线状态、连接数、实时速率、累计流量**(数据来自 sing-box Clash API + V2Ray 统计,仅监听 127.0.0.1)。
---
## 常见问题
### 面板流量/在线状态显示「不可用」
sing-box 统计 API 未就绪,按顺序检查:
```bash
systemctl is-active sing-box
ss -tlnp | grep -E '9090|9091' # Clash API / V2Ray gRPC
grep CLASH_API_SECRET /opt/jiedian/.env
python3 /opt/jiedian/scripts/render-server.py
systemctl restart sing-box jiedian-panel
```
升级后若未重装,需重新生成 sing-box 配置并重启服务,才会启用 `experimental.clash_api``v2ray_api`
### 在线状态始终离线但客户端能连
- 有流量时面板会按速率推断在线;若仍显示离线,执行 `curl -s -H "Authorization: Bearer $(grep CLASH_API_SECRET /opt/jiedian/.env | cut -d= -f2)" http://127.0.0.1:9090/connections | head` 查看连接 metadata 是否含 user 字段
- 修改节点或升级后需重新渲染配置:`python3 /opt/jiedian/scripts/render-server.py && systemctl restart sing-box`
### 面板打不开 / 404
1. **路径不对**:必须用完整路径,末尾带 `/`,例如 `http://域名/jiedian-xxxx/login`