轻量级beszel hub-agent监控搭建实现告警飞书通知

1. Beszel架构

1.1 逻辑角色划分

  • beszel-hub:中心控制与展示节点,负责聚合状态、告警判定
  • beszel-agent:部署在各被监控节点上,负责采集指标并与 hub 建立长连接
  • feishu-proxy:告警转发组件,用于对接飞书 Webhook(格式问题)

1.2 通信关系总览

  • hub 与 agent:双向通信(WebSocket / ssh)
  • hub 与飞书:间接通信(通过 feishu-proxy)

2. 整体架构

graph TD
    subgraph Monitoring
        H[beszel-hub]
        A1[beszel-agent
node-1] A2[beszel-agent
node-2] A3[beszel-agent
node-3] end subgraph Notification F[feishu-proxy] W[feishu-webhook] end H <--> A1 H <--> A2 H <--> A3 H -->|Alert Event| F F -->|Webhook POST| W

3.download

4.install

4.1container

647e9a0011a2cd6fcdc0081d72282aef.png

docker pull ghcr.io/henrygd/beszel/beszel:0.17
docker pull ghcr.io/henrygd/beszel/beszel-agent:0.17
docker pull ghcr.io/henrygd/beszel/beszel-agent-nvidia:0.17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
services:
beszel-hub:
image: henrygd/beszel:latest
container_name: beszel-hub
restart: unless-stopped
network_mode: host
# ports:
# - "8090:8090"
volumes:
- ./beszel_hub:/beszel_data
environment:
- TZ=${TZ}
healthcheck:
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:8090/health"]
interval: 30s
timeout: 5s
retries: 3

beszel-agent:
image: henrygd/beszel-agent:latest
container_name: beszel-agent
restart: unless-stopped
network_mode: host
volumes:
#- /var/run/docker.sock:/var/run/docker.sock:ro
- ./beszel-agent:/var/lib/beszel-agent
environment:
- TZ=${TZ}
# Hub 中创建节点时生成
- TOKEN=${TOKEN}
# Hub WebSocket 地址(必须能访问)
- HUB_URL=${HUB_URL}
# SSH 公钥(非常关键,401/启动失败 90% 因为它)
- KEY=${KEY}
# Agent 监听端口(仅用于本机)
- LISTEN=${LISTEN}

--
# .env hub启动后注册后修正
TZ=Asia/Shanghai
HUB_URL=http://127.0.0.1:8090
TOKEN=6bb9-ca05841804-2a9f-eb8c2ced56
KEY=ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOK2FNYLhxZg5BzlNsCK2SlUh31OGG/snL6lyKUh96Ys
LISTEN=45876
mac@GaGa beszel % docker-compose logs
beszel-agent  | 2026/01/09 05:45:22 INFO Data directory path=/var/lib/beszel-agent
beszel-agent  | 2026/01/09 05:45:22 INFO Detected root device name=vdb1
beszel-agent  | 2026/01/09 05:45:22 INFO Detected network interface name=eth0 sent=12092022 recv=241918580
beszel-agent  | 2026/01/09 05:45:22 INFO Detected network interface name=.orbmirror0 sent=872 recv=18086
beszel-agent  | 2026/01/09 05:45:22 INFO WebSocket connected host=127.0.0.1:8090
beszel-hub    | 2026/01/09 05:45:22 Server started at http://0.0.0.0:8090
beszel-hub    | ├─ REST API:  http://0.0.0.0:8090/api/
beszel-hub    | └─ Dashboard: http://0.0.0.0:8090/_/

4.2binary

hub

cat > /etc/systemd/system/beszel-hub.service <<'EOF'
[Unit]
Description=Beszel Hub
After=network.target

[Service]
# 通过代理后访问beszel-hub
Environment="APP_URL=http://xxx.xxx.internal"
Type=simple
Restart=always
RestartSec=3
User=root
WorkingDirectory=/local/base/beszel-hub
ExecStart=/local/base/beszel-hub/beszel serve --http "0.0.0.0:10020"

[Install]
WantedBy=multi-user.target
EOF

agent

cat > /etc/systemd/system/beszel-agent.service <<'EOF'
[Unit]
Description=Beszel Agent Service
After=network-online.target

[Service]
# 从hub新增agent获取
Environment="LISTEN=45876"
Environment="KEY=xxxx"
Environment="HUB_URL=http://127.0.0.1:10020"
Environment="TOKEN=zzzz"

Type=simple
Restart=always
RestartSec=3
User=root
WorkingDirectory=/local/base/beszel-agent
ExecStart=/local/base/beszel-agent/beszel-agent

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now beszel-agent && systemctl status beszel-agent

4.3feishu-proxy

cat > /etc/systemd/system/feishu-proxy.service <<'EOF'
[Unit]
Description=feishu-proxy Service
After=network-online.target

[Service]
# feishu webhook
Environment="FEISHU_WEBHOOK=https://open.feishu.cn/open-apis/bot/v2/hook/xxx"

Type=simple
Restart=always
RestartSec=3
User=root
WorkingDirectory=/local/base/feishu-proxy
ExecStart=/local/base/feishu-proxy/feishu-proxy

[Install]
WantedBy=multi-user.target
EOF


systemctl daemon-reload
systemctl enable --now feishu-proxy && systemctl status feishu-proxy

5.login && add agent

login
8070aa276a19f5bf4f9514ee8e12f194.png

add agent
67936a1e01b395221868754f336f8971.png

8da00a383b4de0a118b3413a789731ca.png

6.add notify

# 默认generic https
generic://ip:8000/feishu?type=interactive&title=高负载警告

# http
text: generic+http://你的代理域名:8000/feishu
post: generic+http://你的代理域名:8000/feishu?type=post&title=服务器警报
card: generic+http://你的代理域名:8000/feishu?type=interactive&title=高负载警告

5a6f15b5c45e17fa24ac38b7e9dc6e5b.png

3d575bbba20fd0c483fa0fcc6d06b0f2.png