Skip to content

Repository files navigation

ServerStatus 中文版

ServerStatus 是一个轻量的服务器探针和云监控面板,支持多节点在线状态、资源占用、三网延迟、服务监测、SSL 证书检查、Watchdog 告警、HTTP API 和 Web 配置管理。

在线演示:https://tz.cloudcpp.com

GoCILicenseVersion

ServerStatus WebUI

一、服务端

# Docker Compose,本地构建加:--build
ADMIN_TOKEN='your-strong-token' docker compose -f docker-compose-server.yml up -d 
# Docker Run
wget -qO ~/serverstatus-config.json \
--header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/server/config.json?ref=master'
mkdir -p ~/serverstatus-data
docker run -d --restart=always --name=serverstatus-server \
-e ADMIN_TOKEN='your-strong-token' \
-v ~/serverstatus-config.json:/app/config/config.json \
-v ~/serverstatus-data:/app/data \
-p 8080:80 -p 35601:35601 \
cppla/serverstatus:server

启动后访问:

ADMIN_TOKEN 不设置时,监控页面仍可读取,管理 API 返回 503,WebUI 的“配置”页不能修改数据。

二、客户端

# Docker Compose,本地构建加:--build
SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD \
docker compose -f docker-compose-client.yml up -d --force-recreate
# Docker Run
docker run -d --restart=always --name=serverstatus-client \
--network=host --pid=host \
-e SERVER=127.0.0.1 \
-e USER=s01 \
-e PASSWORD=USER_DEFAULT_PASSWORD \
cppla/serverstatus:client
# Shell Run
wget -qO client-linux.py --header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/clients/client-linux.py?ref=master'
nohup python3 client-linux.py SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD >/dev/null 2>&1&

USER 是常见的宿主机环境变量名。如果没有显式传递或传递方式错误,Compose 可能会把系统中的 $USER 解析成本机用户名,而不是默认的 s01。推荐优先级:

  1. 运行命令显式传递 USER=s01
  2. 修改 docker-compose-client.yml 中的 USER 默认值
  3. Docker 或系统环境中的 USER
变量默认值说明
SERVER127.0.0.1Go 服务端地址
USERs01客户端用户名,必须匹配服务端配置
PORT35601Agent TCP 上报端口
PASSWORDUSER_DEFAULT_PASSWORD客户端密码,必须匹配服务端配置
INTERVAL1状态上报间隔,单位秒
PROBEPORT80三网 TCP 探测端口
PROBE_PROTOCOL_PREFERipv4探测协议偏好,可选 ipv4ipv6
PING_PACKET_HISTORY_LEN100丢包历史窗口
CUcu.tz.cloudcpp.com联通探测地址
CTct.tz.cloudcpp.com电信探测地址
CMcm.tz.cloudcpp.com移动探测地址
CLIENTpsutil客户端实现,可选 psutillinux

服务端参数

Docker 镜像中的默认路径为:

环境变量默认值说明
CONFIG_PATH/app/config/config.json主配置文件
STATS_PATH/app/data/stats.json月流量与状态持久化文件;每 60 秒写入,关键操作与正常退出时立即写入
WEB_DIR/app/webWebUI 静态文件目录
HTTP_ADDR:80WebUI 与 HTTP API 监听地址
AGENT_ADDR:35601客户端 TCP 上报监听地址
ADMIN_TOKEN管理 API Bearer Token;为空时禁用管理接口
ADMIN_CORS_ORIGIN可选的 API CORS Origin
INSECURE_CALLBACK_TLSfalse是否允许 Watchdog/证书回调使用不可信 TLS 证书
VERBOSEfalse输出 Gin HTTP 请求日志
TZAsia/Shanghai容器时区

对应命令行参数:

--config, -c config.json 路径
--stats stats.json 路径
--web-dir, -d WebUI 目录
--http HTTP 监听地址
--agent Agent TCP 监听地址
--verbose, -v 详细请求日志
--version 输出构建版本

旧参数 --bind/-b--port/-p 仍可用于设置 Agent TCP 监听地址。

HTTP 管理 API

管理接口使用 Bearer Token:

Authorization: Bearer <ADMIN_TOKEN>

无需认证:

方法路径用途
GET/api/health进程、Agent TCP、版本和配置路径状态
GET/api/schema机器可读的端点与配置集合描述
GET/api/openapi.json可供 AI Agent 直接导入的 OpenAPI 3.1 文档
GET/json/stats.jsonWebUI 使用的实时状态快照

需要认证:

方法路径用途
GET/PUT/api/config读取或整体替换配置
GET/POST/api/servers查询或新增节点
PUT/DELETE/api/servers/{username}修改或删除节点
POST/api/servers/{username}/reset-traffic将当前流量设为本月基线
GET/POST/api/monitors查询或新增服务监测
PUT/DELETE/api/monitors/{index-or-name}修改或删除服务监测
GET/POST/api/sslcerts查询或新增证书监测
PUT/DELETE/api/sslcerts/{index-or-name}修改或删除证书监测
GET/POST/api/watchdog查询或新增 Watchdog
PUT/DELETE/api/watchdog/{index-or-name}修改或删除 Watchdog
POST/api/reload从磁盘重新读取配置
POST/api/restart在进程内重启采集运行时

配置修改采用“校验 → 备份 → 持久化 → 原子切换”的顺序。成功后现有 Agent 连接会被关闭,Python 客户端约 3 秒后自动重连并获取新的 monitors/api/restart 不退出 Go 进程,因此 Docker 和手动运行方式具有一致语义。

常用调用:

TOKEN='请替换为 ADMIN_TOKEN'
curl http://127.0.0.1:8080/api/health
curl -H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/config
curl -X POST http://127.0.0.1:8080/api/servers \
-H "Authorization: Bearer ${TOKEN}" \
-H 'Content-Type: application/json' \
-d '{"username":"s05","name":"node5","type":"kvm","host":"host5","location":"SG","password":"change-me","monthstart":1}'
curl -X DELETE \
-H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/servers/s05

请求体最大为 1 MiB。AI Agent 可直接导入 /api/openapi.json;轻量客户端也可以先读取 /api/schema,再根据返回的集合字段调用 CRUD 接口。

配置文件

{
"servers": [
{
"username": "s01",
"name": "node1",
"type": "kvm",
"host": "host1",
"location": "CN",
"password": "USER_DEFAULT_PASSWORD",
"monthstart": 1,
"disabled": false
}
],
"monitors": [
{
"name": "example",
"host": "https://example.com",
"interval": 600,
"type": "https"
}
],
"sslcerts": [
{
"name": "example",
"domain": "https://example.com",
"port": 443,
"interval": 7200,
"callback": "https://example.net/push?message="
}
],
"watchdog": [
{
"name": "offline warning",
"rule": "online4=0&online6=0",
"interval": 600,
"callback": "https://example.net/push?message="
}
]
}

约束:

  • servers.username 必须唯一。
  • monthstart 自动限制在 1-28
  • port 自动限制在 1-65535
  • interval 最小为 1 秒;Watchdog 中表示通知冷却时间,不是客户端采集间隔。
  • 配置写入前会创建 config.json.bak-*,最多保留 10 份。
  • Docker 单文件 bind mount 无法被 rename 覆盖时,服务端会在完成备份后安全地写回原 inode。

使用 Docker 单文件挂载时,配置备份位于容器 /app/config 的可写层;如需长期保留历史版本,建议同时在宿主机备份 server/config.json

Watchdog 表达式

rule 由 Go expr 引擎执行,并兼容旧版 Exprtk 的常用写法。Go 服务会把字符串外的单个操作符自动转换:

& -> &&
| -> ||
= -> ==

例如以下两种写法等价:

cpu>90&load_1>5&username!='s01'
cpu>90 && load_1>5 && username!='s01'

字符串值支持中文、Emoji 和其他 Unicode 字符,例如:

username='节点一号'&name='上海节点'&location='中国 🇨🇳'&type='云主机'

字段名必须使用系统定义的英文名称。可用字段包括:usernamenametypehostlocationload_1load_5load_15cpumemory_totalmemory_usedswap_totalswap_usedhdd_totalhdd_usednetwork_rxnetwork_txnetwork_innetwork_outlast_network_inlast_network_outping_10010ping_189ping_10086time_10010time_189time_10086tcp_countudp_countprocess_countthread_countio_readio_writeonline4online6

客户端断开 25 秒后仍未重连,服务端才计算离线规则,避免短暂网络波动触发告警。每个节点、每条规则分别记录冷却时间。

SSL 证书

证书检查使用 Go crypto/tls,不再调用外部 openssl。服务端记录到期时间、剩余天数和域名匹配状态,并保留原来的 7/3/1 天通知档位与冷却时间。

回调默认校验 HTTPS 证书。仅在必须兼容自签名回调服务时设置:

INSECURE_CALLBACK_TLS=true

源码编译和运行

需要 Go 1.25 或更高版本:

cd server
go mod download
go test ./...
go build -trimpath -ldflags='-s -w' -o serverstatus .

server/ 目录启动:

ADMIN_TOKEN='请替换为高强度随机字符串' \
./serverstatus \
--config=config.json \
--stats=../web/json/stats.json \
--web-dir=../web \
--http=:8080 \
--agent=:35601

访问 http://127.0.0.1:8080/。发送SIGHUP 可以重新读取配置:

kill -HUP "$(pgrep -x serverstatus)"

Systemd 示例位于 service/status-server.service。一键脚本 status.sh 也已切换到 Go 构建,但 Docker 仍是推荐部署方式。

构建和测试

Go 测试需要 Go 1.25+;WebUI 行为测试需要 Node.js 20+ 和 pnpm。

# Go 单元、协议、API、TLS 和回调测试cd server
go test ./...
go test -race ./...
go vet ./...
# Python 客户端指标、参数与平台识别测试cd ..
python3 -m unittest discover -s clients -p 'test_*.py'# WebUI Chromium 行为测试
pnpm install --frozen-lockfile
pnpm exec playwright install chromium
pnpm test:webui
# Docker 镜像
docker build -f Dockerfile.server -t cppla/serverstatus:server .
docker build -f Dockerfile.client -t cppla/serverstatus:client .# 服务端与客户端真实连接、认证和指标上报
SERVER_IMAGE=cppla/serverstatus:server \
CLIENT_IMAGE=cppla/serverstatus:client \
tests/docker-smoke.sh
# Compose 配置
docker compose -f docker-compose-server.yml config
docker compose -f docker-compose-client.yml config

Docker 联通测试在 Linux 上覆盖客户端的 host 网络和 pid 模式;Docker Desktop 未启用 Host Networking 时会明确提示并使用隔离 bridge 完成本地协议测试。

CI 还会运行 Chromium 行为测试、Docker 服务端/客户端联通测试,并验证客户端镜像可同时构建为 AMD64 和 ARM64。

从旧服务端迁移

  1. 备份原来的 config.jsonweb/json/stats.json
  2. 原配置结构和客户端账号无需转换。
  3. Docker 挂载目标改为 /app/config/config.json/app/data
  4. 删除旧的 nginx、manage_api.pysergate 启动或监督配置。
  5. 启动 Go 服务端后检查 /api/health,再观察客户端自动重连。

stats.json 会按节点的 name/type/host/location 恢复月流量基线。修改这些身份字段会被视为新节点。

致谢

About

云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/

Resources

Stars

4.7k stars

Watchers

48 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
GitHub - cppla/ServerStatus: 云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/ · GitHub
Skip to content

Repository files navigation

ServerStatus 中文版

ServerStatus 是一个轻量的服务器探针和云监控面板,支持多节点在线状态、资源占用、三网延迟、服务监测、SSL 证书检查、Watchdog 告警、HTTP API 和 Web 配置管理。

在线演示:https://tz.cloudcpp.com

GoCILicenseVersion

ServerStatus WebUI

一、服务端

# Docker Compose,本地构建加:--build
ADMIN_TOKEN='your-strong-token' docker compose -f docker-compose-server.yml up -d 
# Docker Run
wget -qO ~/serverstatus-config.json \
--header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/server/config.json?ref=master'
mkdir -p ~/serverstatus-data
docker run -d --restart=always --name=serverstatus-server \
-e ADMIN_TOKEN='your-strong-token' \
-v ~/serverstatus-config.json:/app/config/config.json \
-v ~/serverstatus-data:/app/data \
-p 8080:80 -p 35601:35601 \
cppla/serverstatus:server

启动后访问:

ADMIN_TOKEN 不设置时,监控页面仍可读取,管理 API 返回 503,WebUI 的“配置”页不能修改数据。

二、客户端

# Docker Compose,本地构建加:--build
SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD \
docker compose -f docker-compose-client.yml up -d --force-recreate
# Docker Run
docker run -d --restart=always --name=serverstatus-client \
--network=host --pid=host \
-e SERVER=127.0.0.1 \
-e USER=s01 \
-e PASSWORD=USER_DEFAULT_PASSWORD \
cppla/serverstatus:client
# Shell Run
wget -qO client-linux.py --header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/clients/client-linux.py?ref=master'
nohup python3 client-linux.py SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD >/dev/null 2>&1&

USER 是常见的宿主机环境变量名。如果没有显式传递或传递方式错误,Compose 可能会把系统中的 $USER 解析成本机用户名,而不是默认的 s01。推荐优先级:

  1. 运行命令显式传递 USER=s01
  2. 修改 docker-compose-client.yml 中的 USER 默认值
  3. Docker 或系统环境中的 USER
变量默认值说明
SERVER127.0.0.1Go 服务端地址
USERs01客户端用户名,必须匹配服务端配置
PORT35601Agent TCP 上报端口
PASSWORDUSER_DEFAULT_PASSWORD客户端密码,必须匹配服务端配置
INTERVAL1状态上报间隔,单位秒
PROBEPORT80三网 TCP 探测端口
PROBE_PROTOCOL_PREFERipv4探测协议偏好,可选 ipv4ipv6
PING_PACKET_HISTORY_LEN100丢包历史窗口
CUcu.tz.cloudcpp.com联通探测地址
CTct.tz.cloudcpp.com电信探测地址
CMcm.tz.cloudcpp.com移动探测地址
CLIENTpsutil客户端实现,可选 psutillinux

服务端参数

Docker 镜像中的默认路径为:

环境变量默认值说明
CONFIG_PATH/app/config/config.json主配置文件
STATS_PATH/app/data/stats.json月流量与状态持久化文件;每 60 秒写入,关键操作与正常退出时立即写入
WEB_DIR/app/webWebUI 静态文件目录
HTTP_ADDR:80WebUI 与 HTTP API 监听地址
AGENT_ADDR:35601客户端 TCP 上报监听地址
ADMIN_TOKEN管理 API Bearer Token;为空时禁用管理接口
ADMIN_CORS_ORIGIN可选的 API CORS Origin
INSECURE_CALLBACK_TLSfalse是否允许 Watchdog/证书回调使用不可信 TLS 证书
VERBOSEfalse输出 Gin HTTP 请求日志
TZAsia/Shanghai容器时区

对应命令行参数:

--config, -c config.json 路径
--stats stats.json 路径
--web-dir, -d WebUI 目录
--http HTTP 监听地址
--agent Agent TCP 监听地址
--verbose, -v 详细请求日志
--version 输出构建版本

旧参数 --bind/-b--port/-p 仍可用于设置 Agent TCP 监听地址。

HTTP 管理 API

管理接口使用 Bearer Token:

Authorization: Bearer <ADMIN_TOKEN>

无需认证:

方法路径用途
GET/api/health进程、Agent TCP、版本和配置路径状态
GET/api/schema机器可读的端点与配置集合描述
GET/api/openapi.json可供 AI Agent 直接导入的 OpenAPI 3.1 文档
GET/json/stats.jsonWebUI 使用的实时状态快照

需要认证:

方法路径用途
GET/PUT/api/config读取或整体替换配置
GET/POST/api/servers查询或新增节点
PUT/DELETE/api/servers/{username}修改或删除节点
POST/api/servers/{username}/reset-traffic将当前流量设为本月基线
GET/POST/api/monitors查询或新增服务监测
PUT/DELETE/api/monitors/{index-or-name}修改或删除服务监测
GET/POST/api/sslcerts查询或新增证书监测
PUT/DELETE/api/sslcerts/{index-or-name}修改或删除证书监测
GET/POST/api/watchdog查询或新增 Watchdog
PUT/DELETE/api/watchdog/{index-or-name}修改或删除 Watchdog
POST/api/reload从磁盘重新读取配置
POST/api/restart在进程内重启采集运行时

配置修改采用“校验 → 备份 → 持久化 → 原子切换”的顺序。成功后现有 Agent 连接会被关闭,Python 客户端约 3 秒后自动重连并获取新的 monitors/api/restart 不退出 Go 进程,因此 Docker 和手动运行方式具有一致语义。

常用调用:

TOKEN='请替换为 ADMIN_TOKEN'
curl http://127.0.0.1:8080/api/health
curl -H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/config
curl -X POST http://127.0.0.1:8080/api/servers \
-H "Authorization: Bearer ${TOKEN}" \
-H 'Content-Type: application/json' \
-d '{"username":"s05","name":"node5","type":"kvm","host":"host5","location":"SG","password":"change-me","monthstart":1}'
curl -X DELETE \
-H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/servers/s05

请求体最大为 1 MiB。AI Agent 可直接导入 /api/openapi.json;轻量客户端也可以先读取 /api/schema,再根据返回的集合字段调用 CRUD 接口。

配置文件

{
"servers": [
{
"username": "s01",
"name": "node1",
"type": "kvm",
"host": "host1",
"location": "CN",
"password": "USER_DEFAULT_PASSWORD",
"monthstart": 1,
"disabled": false
}
],
"monitors": [
{
"name": "example",
"host": "https://example.com",
"interval": 600,
"type": "https"
}
],
"sslcerts": [
{
"name": "example",
"domain": "https://example.com",
"port": 443,
"interval": 7200,
"callback": "https://example.net/push?message="
}
],
"watchdog": [
{
"name": "offline warning",
"rule": "online4=0&online6=0",
"interval": 600,
"callback": "https://example.net/push?message="
}
]
}

约束:

  • servers.username 必须唯一。
  • monthstart 自动限制在 1-28
  • port 自动限制在 1-65535
  • interval 最小为 1 秒;Watchdog 中表示通知冷却时间,不是客户端采集间隔。
  • 配置写入前会创建 config.json.bak-*,最多保留 10 份。
  • Docker 单文件 bind mount 无法被 rename 覆盖时,服务端会在完成备份后安全地写回原 inode。

使用 Docker 单文件挂载时,配置备份位于容器 /app/config 的可写层;如需长期保留历史版本,建议同时在宿主机备份 server/config.json

Watchdog 表达式

rule 由 Go expr 引擎执行,并兼容旧版 Exprtk 的常用写法。Go 服务会把字符串外的单个操作符自动转换:

& -> &&
| -> ||
= -> ==

例如以下两种写法等价:

cpu>90&load_1>5&username!='s01'
cpu>90 && load_1>5 && username!='s01'

字符串值支持中文、Emoji 和其他 Unicode 字符,例如:

username='节点一号'&name='上海节点'&location='中国 🇨🇳'&type='云主机'

字段名必须使用系统定义的英文名称。可用字段包括:usernamenametypehostlocationload_1load_5load_15cpumemory_totalmemory_usedswap_totalswap_usedhdd_totalhdd_usednetwork_rxnetwork_txnetwork_innetwork_outlast_network_inlast_network_outping_10010ping_189ping_10086time_10010time_189time_10086tcp_countudp_countprocess_countthread_countio_readio_writeonline4online6

客户端断开 25 秒后仍未重连,服务端才计算离线规则,避免短暂网络波动触发告警。每个节点、每条规则分别记录冷却时间。

SSL 证书

证书检查使用 Go crypto/tls,不再调用外部 openssl。服务端记录到期时间、剩余天数和域名匹配状态,并保留原来的 7/3/1 天通知档位与冷却时间。

回调默认校验 HTTPS 证书。仅在必须兼容自签名回调服务时设置:

INSECURE_CALLBACK_TLS=true

源码编译和运行

需要 Go 1.25 或更高版本:

cd server
go mod download
go test ./...
go build -trimpath -ldflags='-s -w' -o serverstatus .

server/ 目录启动:

ADMIN_TOKEN='请替换为高强度随机字符串' \
./serverstatus \
--config=config.json \
--stats=../web/json/stats.json \
--web-dir=../web \
--http=:8080 \
--agent=:35601

访问 http://127.0.0.1:8080/。发送SIGHUP 可以重新读取配置:

kill -HUP "$(pgrep -x serverstatus)"

Systemd 示例位于 service/status-server.service。一键脚本 status.sh 也已切换到 Go 构建,但 Docker 仍是推荐部署方式。

构建和测试

Go 测试需要 Go 1.25+;WebUI 行为测试需要 Node.js 20+ 和 pnpm。

# Go 单元、协议、API、TLS 和回调测试cd server
go test ./...
go test -race ./...
go vet ./...
# Python 客户端指标、参数与平台识别测试cd ..
python3 -m unittest discover -s clients -p 'test_*.py'# WebUI Chromium 行为测试
pnpm install --frozen-lockfile
pnpm exec playwright install chromium
pnpm test:webui
# Docker 镜像
docker build -f Dockerfile.server -t cppla/serverstatus:server .
docker build -f Dockerfile.client -t cppla/serverstatus:client .# 服务端与客户端真实连接、认证和指标上报
SERVER_IMAGE=cppla/serverstatus:server \
CLIENT_IMAGE=cppla/serverstatus:client \
tests/docker-smoke.sh
# Compose 配置
docker compose -f docker-compose-server.yml config
docker compose -f docker-compose-client.yml config

Docker 联通测试在 Linux 上覆盖客户端的 host 网络和 pid 模式;Docker Desktop 未启用 Host Networking 时会明确提示并使用隔离 bridge 完成本地协议测试。

CI 还会运行 Chromium 行为测试、Docker 服务端/客户端联通测试,并验证客户端镜像可同时构建为 AMD64 和 ARM64。

从旧服务端迁移

  1. 备份原来的 config.jsonweb/json/stats.json
  2. 原配置结构和客户端账号无需转换。
  3. Docker 挂载目标改为 /app/config/config.json/app/data
  4. 删除旧的 nginx、manage_api.pysergate 启动或监督配置。
  5. 启动 Go 服务端后检查 /api/health,再观察客户端自动重连。

stats.json 会按节点的 name/type/host/location 恢复月流量基线。修改这些身份字段会被视为新节点。

致谢

About

云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/

Resources

Stars

4.7k stars

Watchers

48 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - cppla/ServerStatus: 云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/ · GitHub
Skip to content

Repository files navigation

ServerStatus 中文版

ServerStatus 是一个轻量的服务器探针和云监控面板,支持多节点在线状态、资源占用、三网延迟、服务监测、SSL 证书检查、Watchdog 告警、HTTP API 和 Web 配置管理。

在线演示:https://tz.cloudcpp.com

GoCILicenseVersion

ServerStatus WebUI

一、服务端

# Docker Compose,本地构建加:--build
ADMIN_TOKEN='your-strong-token' docker compose -f docker-compose-server.yml up -d 
# Docker Run
wget -qO ~/serverstatus-config.json \
--header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/server/config.json?ref=master'
mkdir -p ~/serverstatus-data
docker run -d --restart=always --name=serverstatus-server \
-e ADMIN_TOKEN='your-strong-token' \
-v ~/serverstatus-config.json:/app/config/config.json \
-v ~/serverstatus-data:/app/data \
-p 8080:80 -p 35601:35601 \
cppla/serverstatus:server

启动后访问:

ADMIN_TOKEN 不设置时,监控页面仍可读取,管理 API 返回 503,WebUI 的“配置”页不能修改数据。

二、客户端

# Docker Compose,本地构建加:--build
SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD \
docker compose -f docker-compose-client.yml up -d --force-recreate
# Docker Run
docker run -d --restart=always --name=serverstatus-client \
--network=host --pid=host \
-e SERVER=127.0.0.1 \
-e USER=s01 \
-e PASSWORD=USER_DEFAULT_PASSWORD \
cppla/serverstatus:client
# Shell Run
wget -qO client-linux.py --header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/clients/client-linux.py?ref=master'
nohup python3 client-linux.py SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD >/dev/null 2>&1&

USER 是常见的宿主机环境变量名。如果没有显式传递或传递方式错误,Compose 可能会把系统中的 $USER 解析成本机用户名,而不是默认的 s01。推荐优先级:

  1. 运行命令显式传递 USER=s01
  2. 修改 docker-compose-client.yml 中的 USER 默认值
  3. Docker 或系统环境中的 USER
变量默认值说明
SERVER127.0.0.1Go 服务端地址
USERs01客户端用户名,必须匹配服务端配置
PORT35601Agent TCP 上报端口
PASSWORDUSER_DEFAULT_PASSWORD客户端密码,必须匹配服务端配置
INTERVAL1状态上报间隔,单位秒
PROBEPORT80三网 TCP 探测端口
PROBE_PROTOCOL_PREFERipv4探测协议偏好,可选 ipv4ipv6
PING_PACKET_HISTORY_LEN100丢包历史窗口
CUcu.tz.cloudcpp.com联通探测地址
CTct.tz.cloudcpp.com电信探测地址
CMcm.tz.cloudcpp.com移动探测地址
CLIENTpsutil客户端实现,可选 psutillinux

服务端参数

Docker 镜像中的默认路径为:

环境变量默认值说明
CONFIG_PATH/app/config/config.json主配置文件
STATS_PATH/app/data/stats.json月流量与状态持久化文件;每 60 秒写入,关键操作与正常退出时立即写入
WEB_DIR/app/webWebUI 静态文件目录
HTTP_ADDR:80WebUI 与 HTTP API 监听地址
AGENT_ADDR:35601客户端 TCP 上报监听地址
ADMIN_TOKEN管理 API Bearer Token;为空时禁用管理接口
ADMIN_CORS_ORIGIN可选的 API CORS Origin
INSECURE_CALLBACK_TLSfalse是否允许 Watchdog/证书回调使用不可信 TLS 证书
VERBOSEfalse输出 Gin HTTP 请求日志
TZAsia/Shanghai容器时区

对应命令行参数:

--config, -c config.json 路径
--stats stats.json 路径
--web-dir, -d WebUI 目录
--http HTTP 监听地址
--agent Agent TCP 监听地址
--verbose, -v 详细请求日志
--version 输出构建版本

旧参数 --bind/-b--port/-p 仍可用于设置 Agent TCP 监听地址。

HTTP 管理 API

管理接口使用 Bearer Token:

Authorization: Bearer <ADMIN_TOKEN>

无需认证:

方法路径用途
GET/api/health进程、Agent TCP、版本和配置路径状态
GET/api/schema机器可读的端点与配置集合描述
GET/api/openapi.json可供 AI Agent 直接导入的 OpenAPI 3.1 文档
GET/json/stats.jsonWebUI 使用的实时状态快照

需要认证:

方法路径用途
GET/PUT/api/config读取或整体替换配置
GET/POST/api/servers查询或新增节点
PUT/DELETE/api/servers/{username}修改或删除节点
POST/api/servers/{username}/reset-traffic将当前流量设为本月基线
GET/POST/api/monitors查询或新增服务监测
PUT/DELETE/api/monitors/{index-or-name}修改或删除服务监测
GET/POST/api/sslcerts查询或新增证书监测
PUT/DELETE/api/sslcerts/{index-or-name}修改或删除证书监测
GET/POST/api/watchdog查询或新增 Watchdog
PUT/DELETE/api/watchdog/{index-or-name}修改或删除 Watchdog
POST/api/reload从磁盘重新读取配置
POST/api/restart在进程内重启采集运行时

配置修改采用“校验 → 备份 → 持久化 → 原子切换”的顺序。成功后现有 Agent 连接会被关闭,Python 客户端约 3 秒后自动重连并获取新的 monitors/api/restart 不退出 Go 进程,因此 Docker 和手动运行方式具有一致语义。

常用调用:

TOKEN='请替换为 ADMIN_TOKEN'
curl http://127.0.0.1:8080/api/health
curl -H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/config
curl -X POST http://127.0.0.1:8080/api/servers \
-H "Authorization: Bearer ${TOKEN}" \
-H 'Content-Type: application/json' \
-d '{"username":"s05","name":"node5","type":"kvm","host":"host5","location":"SG","password":"change-me","monthstart":1}'
curl -X DELETE \
-H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/servers/s05

请求体最大为 1 MiB。AI Agent 可直接导入 /api/openapi.json;轻量客户端也可以先读取 /api/schema,再根据返回的集合字段调用 CRUD 接口。

配置文件

{
"servers": [
{
"username": "s01",
"name": "node1",
"type": "kvm",
"host": "host1",
"location": "CN",
"password": "USER_DEFAULT_PASSWORD",
"monthstart": 1,
"disabled": false
}
],
"monitors": [
{
"name": "example",
"host": "https://example.com",
"interval": 600,
"type": "https"
}
],
"sslcerts": [
{
"name": "example",
"domain": "https://example.com",
"port": 443,
"interval": 7200,
"callback": "https://example.net/push?message="
}
],
"watchdog": [
{
"name": "offline warning",
"rule": "online4=0&online6=0",
"interval": 600,
"callback": "https://example.net/push?message="
}
]
}

约束:

  • servers.username 必须唯一。
  • monthstart 自动限制在 1-28
  • port 自动限制在 1-65535
  • interval 最小为 1 秒;Watchdog 中表示通知冷却时间,不是客户端采集间隔。
  • 配置写入前会创建 config.json.bak-*,最多保留 10 份。
  • Docker 单文件 bind mount 无法被 rename 覆盖时,服务端会在完成备份后安全地写回原 inode。

使用 Docker 单文件挂载时,配置备份位于容器 /app/config 的可写层;如需长期保留历史版本,建议同时在宿主机备份 server/config.json

Watchdog 表达式

rule 由 Go expr 引擎执行,并兼容旧版 Exprtk 的常用写法。Go 服务会把字符串外的单个操作符自动转换:

& -> &&
| -> ||
= -> ==

例如以下两种写法等价:

cpu>90&load_1>5&username!='s01'
cpu>90 && load_1>5 && username!='s01'

字符串值支持中文、Emoji 和其他 Unicode 字符,例如:

username='节点一号'&name='上海节点'&location='中国 🇨🇳'&type='云主机'

字段名必须使用系统定义的英文名称。可用字段包括:usernamenametypehostlocationload_1load_5load_15cpumemory_totalmemory_usedswap_totalswap_usedhdd_totalhdd_usednetwork_rxnetwork_txnetwork_innetwork_outlast_network_inlast_network_outping_10010ping_189ping_10086time_10010time_189time_10086tcp_countudp_countprocess_countthread_countio_readio_writeonline4online6

客户端断开 25 秒后仍未重连,服务端才计算离线规则,避免短暂网络波动触发告警。每个节点、每条规则分别记录冷却时间。

SSL 证书

证书检查使用 Go crypto/tls,不再调用外部 openssl。服务端记录到期时间、剩余天数和域名匹配状态,并保留原来的 7/3/1 天通知档位与冷却时间。

回调默认校验 HTTPS 证书。仅在必须兼容自签名回调服务时设置:

INSECURE_CALLBACK_TLS=true

源码编译和运行

需要 Go 1.25 或更高版本:

cd server
go mod download
go test ./...
go build -trimpath -ldflags='-s -w' -o serverstatus .

server/ 目录启动:

ADMIN_TOKEN='请替换为高强度随机字符串' \
./serverstatus \
--config=config.json \
--stats=../web/json/stats.json \
--web-dir=../web \
--http=:8080 \
--agent=:35601

访问 http://127.0.0.1:8080/。发送SIGHUP 可以重新读取配置:

kill -HUP "$(pgrep -x serverstatus)"

Systemd 示例位于 service/status-server.service。一键脚本 status.sh 也已切换到 Go 构建,但 Docker 仍是推荐部署方式。

构建和测试

Go 测试需要 Go 1.25+;WebUI 行为测试需要 Node.js 20+ 和 pnpm。

# Go 单元、协议、API、TLS 和回调测试cd server
go test ./...
go test -race ./...
go vet ./...
# Python 客户端指标、参数与平台识别测试cd ..
python3 -m unittest discover -s clients -p 'test_*.py'# WebUI Chromium 行为测试
pnpm install --frozen-lockfile
pnpm exec playwright install chromium
pnpm test:webui
# Docker 镜像
docker build -f Dockerfile.server -t cppla/serverstatus:server .
docker build -f Dockerfile.client -t cppla/serverstatus:client .# 服务端与客户端真实连接、认证和指标上报
SERVER_IMAGE=cppla/serverstatus:server \
CLIENT_IMAGE=cppla/serverstatus:client \
tests/docker-smoke.sh
# Compose 配置
docker compose -f docker-compose-server.yml config
docker compose -f docker-compose-client.yml config

Docker 联通测试在 Linux 上覆盖客户端的 host 网络和 pid 模式;Docker Desktop 未启用 Host Networking 时会明确提示并使用隔离 bridge 完成本地协议测试。

CI 还会运行 Chromium 行为测试、Docker 服务端/客户端联通测试,并验证客户端镜像可同时构建为 AMD64 和 ARM64。

从旧服务端迁移

  1. 备份原来的 config.jsonweb/json/stats.json
  2. 原配置结构和客户端账号无需转换。
  3. Docker 挂载目标改为 /app/config/config.json/app/data
  4. 删除旧的 nginx、manage_api.pysergate 启动或监督配置。
  5. 启动 Go 服务端后检查 /api/health,再观察客户端自动重连。

stats.json 会按节点的 name/type/host/location 恢复月流量基线。修改这些身份字段会被视为新节点。

致谢

About

云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/

Resources

Stars

4.7k stars

Watchers

48 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - cppla/ServerStatus: 云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/ · GitHub
Skip to content

Repository files navigation

ServerStatus 中文版

ServerStatus 是一个轻量的服务器探针和云监控面板,支持多节点在线状态、资源占用、三网延迟、服务监测、SSL 证书检查、Watchdog 告警、HTTP API 和 Web 配置管理。

在线演示:https://tz.cloudcpp.com

GoCILicenseVersion

ServerStatus WebUI

一、服务端

# Docker Compose,本地构建加:--build
ADMIN_TOKEN='your-strong-token' docker compose -f docker-compose-server.yml up -d 
# Docker Run
wget -qO ~/serverstatus-config.json \
--header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/server/config.json?ref=master'
mkdir -p ~/serverstatus-data
docker run -d --restart=always --name=serverstatus-server \
-e ADMIN_TOKEN='your-strong-token' \
-v ~/serverstatus-config.json:/app/config/config.json \
-v ~/serverstatus-data:/app/data \
-p 8080:80 -p 35601:35601 \
cppla/serverstatus:server

启动后访问:

ADMIN_TOKEN 不设置时,监控页面仍可读取,管理 API 返回 503,WebUI 的“配置”页不能修改数据。

二、客户端

# Docker Compose,本地构建加:--build
SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD \
docker compose -f docker-compose-client.yml up -d --force-recreate
# Docker Run
docker run -d --restart=always --name=serverstatus-client \
--network=host --pid=host \
-e SERVER=127.0.0.1 \
-e USER=s01 \
-e PASSWORD=USER_DEFAULT_PASSWORD \
cppla/serverstatus:client
# Shell Run
wget -qO client-linux.py --header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/clients/client-linux.py?ref=master'
nohup python3 client-linux.py SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD >/dev/null 2>&1&

USER 是常见的宿主机环境变量名。如果没有显式传递或传递方式错误,Compose 可能会把系统中的 $USER 解析成本机用户名,而不是默认的 s01。推荐优先级:

  1. 运行命令显式传递 USER=s01
  2. 修改 docker-compose-client.yml 中的 USER 默认值
  3. Docker 或系统环境中的 USER
变量默认值说明
SERVER127.0.0.1Go 服务端地址
USERs01客户端用户名,必须匹配服务端配置
PORT35601Agent TCP 上报端口
PASSWORDUSER_DEFAULT_PASSWORD客户端密码,必须匹配服务端配置
INTERVAL1状态上报间隔,单位秒
PROBEPORT80三网 TCP 探测端口
PROBE_PROTOCOL_PREFERipv4探测协议偏好,可选 ipv4ipv6
PING_PACKET_HISTORY_LEN100丢包历史窗口
CUcu.tz.cloudcpp.com联通探测地址
CTct.tz.cloudcpp.com电信探测地址
CMcm.tz.cloudcpp.com移动探测地址
CLIENTpsutil客户端实现,可选 psutillinux

服务端参数

Docker 镜像中的默认路径为:

环境变量默认值说明
CONFIG_PATH/app/config/config.json主配置文件
STATS_PATH/app/data/stats.json月流量与状态持久化文件;每 60 秒写入,关键操作与正常退出时立即写入
WEB_DIR/app/webWebUI 静态文件目录
HTTP_ADDR:80WebUI 与 HTTP API 监听地址
AGENT_ADDR:35601客户端 TCP 上报监听地址
ADMIN_TOKEN管理 API Bearer Token;为空时禁用管理接口
ADMIN_CORS_ORIGIN可选的 API CORS Origin
INSECURE_CALLBACK_TLSfalse是否允许 Watchdog/证书回调使用不可信 TLS 证书
VERBOSEfalse输出 Gin HTTP 请求日志
TZAsia/Shanghai容器时区

对应命令行参数:

--config, -c config.json 路径
--stats stats.json 路径
--web-dir, -d WebUI 目录
--http HTTP 监听地址
--agent Agent TCP 监听地址
--verbose, -v 详细请求日志
--version 输出构建版本

旧参数 --bind/-b--port/-p 仍可用于设置 Agent TCP 监听地址。

HTTP 管理 API

管理接口使用 Bearer Token:

Authorization: Bearer <ADMIN_TOKEN>

无需认证:

方法路径用途
GET/api/health进程、Agent TCP、版本和配置路径状态
GET/api/schema机器可读的端点与配置集合描述
GET/api/openapi.json可供 AI Agent 直接导入的 OpenAPI 3.1 文档
GET/json/stats.jsonWebUI 使用的实时状态快照

需要认证:

方法路径用途
GET/PUT/api/config读取或整体替换配置
GET/POST/api/servers查询或新增节点
PUT/DELETE/api/servers/{username}修改或删除节点
POST/api/servers/{username}/reset-traffic将当前流量设为本月基线
GET/POST/api/monitors查询或新增服务监测
PUT/DELETE/api/monitors/{index-or-name}修改或删除服务监测
GET/POST/api/sslcerts查询或新增证书监测
PUT/DELETE/api/sslcerts/{index-or-name}修改或删除证书监测
GET/POST/api/watchdog查询或新增 Watchdog
PUT/DELETE/api/watchdog/{index-or-name}修改或删除 Watchdog
POST/api/reload从磁盘重新读取配置
POST/api/restart在进程内重启采集运行时

配置修改采用“校验 → 备份 → 持久化 → 原子切换”的顺序。成功后现有 Agent 连接会被关闭,Python 客户端约 3 秒后自动重连并获取新的 monitors/api/restart 不退出 Go 进程,因此 Docker 和手动运行方式具有一致语义。

常用调用:

TOKEN='请替换为 ADMIN_TOKEN'
curl http://127.0.0.1:8080/api/health
curl -H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/config
curl -X POST http://127.0.0.1:8080/api/servers \
-H "Authorization: Bearer ${TOKEN}" \
-H 'Content-Type: application/json' \
-d '{"username":"s05","name":"node5","type":"kvm","host":"host5","location":"SG","password":"change-me","monthstart":1}'
curl -X DELETE \
-H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/servers/s05

请求体最大为 1 MiB。AI Agent 可直接导入 /api/openapi.json;轻量客户端也可以先读取 /api/schema,再根据返回的集合字段调用 CRUD 接口。

配置文件

{
"servers": [
{
"username": "s01",
"name": "node1",
"type": "kvm",
"host": "host1",
"location": "CN",
"password": "USER_DEFAULT_PASSWORD",
"monthstart": 1,
"disabled": false
}
],
"monitors": [
{
"name": "example",
"host": "https://example.com",
"interval": 600,
"type": "https"
}
],
"sslcerts": [
{
"name": "example",
"domain": "https://example.com",
"port": 443,
"interval": 7200,
"callback": "https://example.net/push?message="
}
],
"watchdog": [
{
"name": "offline warning",
"rule": "online4=0&online6=0",
"interval": 600,
"callback": "https://example.net/push?message="
}
]
}

约束:

  • servers.username 必须唯一。
  • monthstart 自动限制在 1-28
  • port 自动限制在 1-65535
  • interval 最小为 1 秒;Watchdog 中表示通知冷却时间,不是客户端采集间隔。
  • 配置写入前会创建 config.json.bak-*,最多保留 10 份。
  • Docker 单文件 bind mount 无法被 rename 覆盖时,服务端会在完成备份后安全地写回原 inode。

使用 Docker 单文件挂载时,配置备份位于容器 /app/config 的可写层;如需长期保留历史版本,建议同时在宿主机备份 server/config.json

Watchdog 表达式

rule 由 Go expr 引擎执行,并兼容旧版 Exprtk 的常用写法。Go 服务会把字符串外的单个操作符自动转换:

& -> &&
| -> ||
= -> ==

例如以下两种写法等价:

cpu>90&load_1>5&username!='s01'
cpu>90 && load_1>5 && username!='s01'

字符串值支持中文、Emoji 和其他 Unicode 字符,例如:

username='节点一号'&name='上海节点'&location='中国 🇨🇳'&type='云主机'

字段名必须使用系统定义的英文名称。可用字段包括:usernamenametypehostlocationload_1load_5load_15cpumemory_totalmemory_usedswap_totalswap_usedhdd_totalhdd_usednetwork_rxnetwork_txnetwork_innetwork_outlast_network_inlast_network_outping_10010ping_189ping_10086time_10010time_189time_10086tcp_countudp_countprocess_countthread_countio_readio_writeonline4online6

客户端断开 25 秒后仍未重连,服务端才计算离线规则,避免短暂网络波动触发告警。每个节点、每条规则分别记录冷却时间。

SSL 证书

证书检查使用 Go crypto/tls,不再调用外部 openssl。服务端记录到期时间、剩余天数和域名匹配状态,并保留原来的 7/3/1 天通知档位与冷却时间。

回调默认校验 HTTPS 证书。仅在必须兼容自签名回调服务时设置:

INSECURE_CALLBACK_TLS=true

源码编译和运行

需要 Go 1.25 或更高版本:

cd server
go mod download
go test ./...
go build -trimpath -ldflags='-s -w' -o serverstatus .

server/ 目录启动:

ADMIN_TOKEN='请替换为高强度随机字符串' \
./serverstatus \
--config=config.json \
--stats=../web/json/stats.json \
--web-dir=../web \
--http=:8080 \
--agent=:35601

访问 http://127.0.0.1:8080/。发送SIGHUP 可以重新读取配置:

kill -HUP "$(pgrep -x serverstatus)"

Systemd 示例位于 service/status-server.service。一键脚本 status.sh 也已切换到 Go 构建,但 Docker 仍是推荐部署方式。

构建和测试

Go 测试需要 Go 1.25+;WebUI 行为测试需要 Node.js 20+ 和 pnpm。

# Go 单元、协议、API、TLS 和回调测试cd server
go test ./...
go test -race ./...
go vet ./...
# Python 客户端指标、参数与平台识别测试cd ..
python3 -m unittest discover -s clients -p 'test_*.py'# WebUI Chromium 行为测试
pnpm install --frozen-lockfile
pnpm exec playwright install chromium
pnpm test:webui
# Docker 镜像
docker build -f Dockerfile.server -t cppla/serverstatus:server .
docker build -f Dockerfile.client -t cppla/serverstatus:client .# 服务端与客户端真实连接、认证和指标上报
SERVER_IMAGE=cppla/serverstatus:server \
CLIENT_IMAGE=cppla/serverstatus:client \
tests/docker-smoke.sh
# Compose 配置
docker compose -f docker-compose-server.yml config
docker compose -f docker-compose-client.yml config

Docker 联通测试在 Linux 上覆盖客户端的 host 网络和 pid 模式;Docker Desktop 未启用 Host Networking 时会明确提示并使用隔离 bridge 完成本地协议测试。

CI 还会运行 Chromium 行为测试、Docker 服务端/客户端联通测试,并验证客户端镜像可同时构建为 AMD64 和 ARM64。

从旧服务端迁移

  1. 备份原来的 config.jsonweb/json/stats.json
  2. 原配置结构和客户端账号无需转换。
  3. Docker 挂载目标改为 /app/config/config.json/app/data
  4. 删除旧的 nginx、manage_api.pysergate 启动或监督配置。
  5. 启动 Go 服务端后检查 /api/health,再观察客户端自动重连。

stats.json 会按节点的 name/type/host/location 恢复月流量基线。修改这些身份字段会被视为新节点。

致谢

About

云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/

Resources

Stars

4.7k stars

Watchers

48 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' GitHub - cppla/ServerStatus: 云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/ · GitHub
Skip to content

Repository files navigation

ServerStatus 中文版

ServerStatus 是一个轻量的服务器探针和云监控面板,支持多节点在线状态、资源占用、三网延迟、服务监测、SSL 证书检查、Watchdog 告警、HTTP API 和 Web 配置管理。

在线演示:https://tz.cloudcpp.com

GoCILicenseVersion

ServerStatus WebUI

一、服务端

# Docker Compose,本地构建加:--build
ADMIN_TOKEN='your-strong-token' docker compose -f docker-compose-server.yml up -d 
# Docker Run
wget -qO ~/serverstatus-config.json \
--header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/server/config.json?ref=master'
mkdir -p ~/serverstatus-data
docker run -d --restart=always --name=serverstatus-server \
-e ADMIN_TOKEN='your-strong-token' \
-v ~/serverstatus-config.json:/app/config/config.json \
-v ~/serverstatus-data:/app/data \
-p 8080:80 -p 35601:35601 \
cppla/serverstatus:server

启动后访问:

ADMIN_TOKEN 不设置时,监控页面仍可读取,管理 API 返回 503,WebUI 的“配置”页不能修改数据。

二、客户端

# Docker Compose,本地构建加:--build
SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD \
docker compose -f docker-compose-client.yml up -d --force-recreate
# Docker Run
docker run -d --restart=always --name=serverstatus-client \
--network=host --pid=host \
-e SERVER=127.0.0.1 \
-e USER=s01 \
-e PASSWORD=USER_DEFAULT_PASSWORD \
cppla/serverstatus:client
# Shell Run
wget -qO client-linux.py --header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/clients/client-linux.py?ref=master'
nohup python3 client-linux.py SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD >/dev/null 2>&1&

USER 是常见的宿主机环境变量名。如果没有显式传递或传递方式错误,Compose 可能会把系统中的 $USER 解析成本机用户名,而不是默认的 s01。推荐优先级:

  1. 运行命令显式传递 USER=s01
  2. 修改 docker-compose-client.yml 中的 USER 默认值
  3. Docker 或系统环境中的 USER
变量默认值说明
SERVER127.0.0.1Go 服务端地址
USERs01客户端用户名,必须匹配服务端配置
PORT35601Agent TCP 上报端口
PASSWORDUSER_DEFAULT_PASSWORD客户端密码,必须匹配服务端配置
INTERVAL1状态上报间隔,单位秒
PROBEPORT80三网 TCP 探测端口
PROBE_PROTOCOL_PREFERipv4探测协议偏好,可选 ipv4ipv6
PING_PACKET_HISTORY_LEN100丢包历史窗口
CUcu.tz.cloudcpp.com联通探测地址
CTct.tz.cloudcpp.com电信探测地址
CMcm.tz.cloudcpp.com移动探测地址
CLIENTpsutil客户端实现,可选 psutillinux

服务端参数

Docker 镜像中的默认路径为:

环境变量默认值说明
CONFIG_PATH/app/config/config.json主配置文件
STATS_PATH/app/data/stats.json月流量与状态持久化文件;每 60 秒写入,关键操作与正常退出时立即写入
WEB_DIR/app/webWebUI 静态文件目录
HTTP_ADDR:80WebUI 与 HTTP API 监听地址
AGENT_ADDR:35601客户端 TCP 上报监听地址
ADMIN_TOKEN管理 API Bearer Token;为空时禁用管理接口
ADMIN_CORS_ORIGIN可选的 API CORS Origin
INSECURE_CALLBACK_TLSfalse是否允许 Watchdog/证书回调使用不可信 TLS 证书
VERBOSEfalse输出 Gin HTTP 请求日志
TZAsia/Shanghai容器时区

对应命令行参数:

--config, -c config.json 路径
--stats stats.json 路径
--web-dir, -d WebUI 目录
--http HTTP 监听地址
--agent Agent TCP 监听地址
--verbose, -v 详细请求日志
--version 输出构建版本

旧参数 --bind/-b--port/-p 仍可用于设置 Agent TCP 监听地址。

HTTP 管理 API

管理接口使用 Bearer Token:

Authorization: Bearer <ADMIN_TOKEN>

无需认证:

方法路径用途
GET/api/health进程、Agent TCP、版本和配置路径状态
GET/api/schema机器可读的端点与配置集合描述
GET/api/openapi.json可供 AI Agent 直接导入的 OpenAPI 3.1 文档
GET/json/stats.jsonWebUI 使用的实时状态快照

需要认证:

方法路径用途
GET/PUT/api/config读取或整体替换配置
GET/POST/api/servers查询或新增节点
PUT/DELETE/api/servers/{username}修改或删除节点
POST/api/servers/{username}/reset-traffic将当前流量设为本月基线
GET/POST/api/monitors查询或新增服务监测
PUT/DELETE/api/monitors/{index-or-name}修改或删除服务监测
GET/POST/api/sslcerts查询或新增证书监测
PUT/DELETE/api/sslcerts/{index-or-name}修改或删除证书监测
GET/POST/api/watchdog查询或新增 Watchdog
PUT/DELETE/api/watchdog/{index-or-name}修改或删除 Watchdog
POST/api/reload从磁盘重新读取配置
POST/api/restart在进程内重启采集运行时

配置修改采用“校验 → 备份 → 持久化 → 原子切换”的顺序。成功后现有 Agent 连接会被关闭,Python 客户端约 3 秒后自动重连并获取新的 monitors/api/restart 不退出 Go 进程,因此 Docker 和手动运行方式具有一致语义。

常用调用:

TOKEN='请替换为 ADMIN_TOKEN'
curl http://127.0.0.1:8080/api/health
curl -H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/config
curl -X POST http://127.0.0.1:8080/api/servers \
-H "Authorization: Bearer ${TOKEN}" \
-H 'Content-Type: application/json' \
-d '{"username":"s05","name":"node5","type":"kvm","host":"host5","location":"SG","password":"change-me","monthstart":1}'
curl -X DELETE \
-H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/servers/s05

请求体最大为 1 MiB。AI Agent 可直接导入 /api/openapi.json;轻量客户端也可以先读取 /api/schema,再根据返回的集合字段调用 CRUD 接口。

配置文件

{
"servers": [
{
"username": "s01",
"name": "node1",
"type": "kvm",
"host": "host1",
"location": "CN",
"password": "USER_DEFAULT_PASSWORD",
"monthstart": 1,
"disabled": false
}
],
"monitors": [
{
"name": "example",
"host": "https://example.com",
"interval": 600,
"type": "https"
}
],
"sslcerts": [
{
"name": "example",
"domain": "https://example.com",
"port": 443,
"interval": 7200,
"callback": "https://example.net/push?message="
}
],
"watchdog": [
{
"name": "offline warning",
"rule": "online4=0&online6=0",
"interval": 600,
"callback": "https://example.net/push?message="
}
]
}

约束:

  • servers.username 必须唯一。
  • monthstart 自动限制在 1-28
  • port 自动限制在 1-65535
  • interval 最小为 1 秒;Watchdog 中表示通知冷却时间,不是客户端采集间隔。
  • 配置写入前会创建 config.json.bak-*,最多保留 10 份。
  • Docker 单文件 bind mount 无法被 rename 覆盖时,服务端会在完成备份后安全地写回原 inode。

使用 Docker 单文件挂载时,配置备份位于容器 /app/config 的可写层;如需长期保留历史版本,建议同时在宿主机备份 server/config.json

Watchdog 表达式

rule 由 Go expr 引擎执行,并兼容旧版 Exprtk 的常用写法。Go 服务会把字符串外的单个操作符自动转换:

& -> &&
| -> ||
= -> ==

例如以下两种写法等价:

cpu>90&load_1>5&username!='s01'
cpu>90 && load_1>5 && username!='s01'

字符串值支持中文、Emoji 和其他 Unicode 字符,例如:

username='节点一号'&name='上海节点'&location='中国 🇨🇳'&type='云主机'

字段名必须使用系统定义的英文名称。可用字段包括:usernamenametypehostlocationload_1load_5load_15cpumemory_totalmemory_usedswap_totalswap_usedhdd_totalhdd_usednetwork_rxnetwork_txnetwork_innetwork_outlast_network_inlast_network_outping_10010ping_189ping_10086time_10010time_189time_10086tcp_countudp_countprocess_countthread_countio_readio_writeonline4online6

客户端断开 25 秒后仍未重连,服务端才计算离线规则,避免短暂网络波动触发告警。每个节点、每条规则分别记录冷却时间。

SSL 证书

证书检查使用 Go crypto/tls,不再调用外部 openssl。服务端记录到期时间、剩余天数和域名匹配状态,并保留原来的 7/3/1 天通知档位与冷却时间。

回调默认校验 HTTPS 证书。仅在必须兼容自签名回调服务时设置:

INSECURE_CALLBACK_TLS=true

源码编译和运行

需要 Go 1.25 或更高版本:

cd server
go mod download
go test ./...
go build -trimpath -ldflags='-s -w' -o serverstatus .

server/ 目录启动:

ADMIN_TOKEN='请替换为高强度随机字符串' \
./serverstatus \
--config=config.json \
--stats=../web/json/stats.json \
--web-dir=../web \
--http=:8080 \
--agent=:35601

访问 http://127.0.0.1:8080/。发送SIGHUP 可以重新读取配置:

kill -HUP "$(pgrep -x serverstatus)"

Systemd 示例位于 service/status-server.service。一键脚本 status.sh 也已切换到 Go 构建,但 Docker 仍是推荐部署方式。

构建和测试

Go 测试需要 Go 1.25+;WebUI 行为测试需要 Node.js 20+ 和 pnpm。

# Go 单元、协议、API、TLS 和回调测试cd server
go test ./...
go test -race ./...
go vet ./...
# Python 客户端指标、参数与平台识别测试cd ..
python3 -m unittest discover -s clients -p 'test_*.py'# WebUI Chromium 行为测试
pnpm install --frozen-lockfile
pnpm exec playwright install chromium
pnpm test:webui
# Docker 镜像
docker build -f Dockerfile.server -t cppla/serverstatus:server .
docker build -f Dockerfile.client -t cppla/serverstatus:client .# 服务端与客户端真实连接、认证和指标上报
SERVER_IMAGE=cppla/serverstatus:server \
CLIENT_IMAGE=cppla/serverstatus:client \
tests/docker-smoke.sh
# Compose 配置
docker compose -f docker-compose-server.yml config
docker compose -f docker-compose-client.yml config

Docker 联通测试在 Linux 上覆盖客户端的 host 网络和 pid 模式;Docker Desktop 未启用 Host Networking 时会明确提示并使用隔离 bridge 完成本地协议测试。

CI 还会运行 Chromium 行为测试、Docker 服务端/客户端联通测试,并验证客户端镜像可同时构建为 AMD64 和 ARM64。

从旧服务端迁移

  1. 备份原来的 config.jsonweb/json/stats.json
  2. 原配置结构和客户端账号无需转换。
  3. Docker 挂载目标改为 /app/config/config.json/app/data
  4. 删除旧的 nginx、manage_api.pysergate 启动或监督配置。
  5. 启动 Go 服务端后检查 /api/health,再观察客户端自动重连。

stats.json 会按节点的 name/type/host/location 恢复月流量基线。修改这些身份字段会被视为新节点。

致谢

About

云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/

Resources

Stars

4.7k stars

Watchers

48 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - cppla/ServerStatus: 云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/ · GitHub
Skip to content

Repository files navigation

ServerStatus 中文版

ServerStatus 是一个轻量的服务器探针和云监控面板,支持多节点在线状态、资源占用、三网延迟、服务监测、SSL 证书检查、Watchdog 告警、HTTP API 和 Web 配置管理。

在线演示:https://tz.cloudcpp.com

GoCILicenseVersion

ServerStatus WebUI

一、服务端

# Docker Compose,本地构建加:--build
ADMIN_TOKEN='your-strong-token' docker compose -f docker-compose-server.yml up -d 
# Docker Run
wget -qO ~/serverstatus-config.json \
--header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/server/config.json?ref=master'
mkdir -p ~/serverstatus-data
docker run -d --restart=always --name=serverstatus-server \
-e ADMIN_TOKEN='your-strong-token' \
-v ~/serverstatus-config.json:/app/config/config.json \
-v ~/serverstatus-data:/app/data \
-p 8080:80 -p 35601:35601 \
cppla/serverstatus:server

启动后访问:

ADMIN_TOKEN 不设置时,监控页面仍可读取,管理 API 返回 503,WebUI 的“配置”页不能修改数据。

二、客户端

# Docker Compose,本地构建加:--build
SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD \
docker compose -f docker-compose-client.yml up -d --force-recreate
# Docker Run
docker run -d --restart=always --name=serverstatus-client \
--network=host --pid=host \
-e SERVER=127.0.0.1 \
-e USER=s01 \
-e PASSWORD=USER_DEFAULT_PASSWORD \
cppla/serverstatus:client
# Shell Run
wget -qO client-linux.py --header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/clients/client-linux.py?ref=master'
nohup python3 client-linux.py SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD >/dev/null 2>&1&

USER 是常见的宿主机环境变量名。如果没有显式传递或传递方式错误,Compose 可能会把系统中的 $USER 解析成本机用户名,而不是默认的 s01。推荐优先级:

  1. 运行命令显式传递 USER=s01
  2. 修改 docker-compose-client.yml 中的 USER 默认值
  3. Docker 或系统环境中的 USER
变量默认值说明
SERVER127.0.0.1Go 服务端地址
USERs01客户端用户名,必须匹配服务端配置
PORT35601Agent TCP 上报端口
PASSWORDUSER_DEFAULT_PASSWORD客户端密码,必须匹配服务端配置
INTERVAL1状态上报间隔,单位秒
PROBEPORT80三网 TCP 探测端口
PROBE_PROTOCOL_PREFERipv4探测协议偏好,可选 ipv4ipv6
PING_PACKET_HISTORY_LEN100丢包历史窗口
CUcu.tz.cloudcpp.com联通探测地址
CTct.tz.cloudcpp.com电信探测地址
CMcm.tz.cloudcpp.com移动探测地址
CLIENTpsutil客户端实现,可选 psutillinux

服务端参数

Docker 镜像中的默认路径为:

环境变量默认值说明
CONFIG_PATH/app/config/config.json主配置文件
STATS_PATH/app/data/stats.json月流量与状态持久化文件;每 60 秒写入,关键操作与正常退出时立即写入
WEB_DIR/app/webWebUI 静态文件目录
HTTP_ADDR:80WebUI 与 HTTP API 监听地址
AGENT_ADDR:35601客户端 TCP 上报监听地址
ADMIN_TOKEN管理 API Bearer Token;为空时禁用管理接口
ADMIN_CORS_ORIGIN可选的 API CORS Origin
INSECURE_CALLBACK_TLSfalse是否允许 Watchdog/证书回调使用不可信 TLS 证书
VERBOSEfalse输出 Gin HTTP 请求日志
TZAsia/Shanghai容器时区

对应命令行参数:

--config, -c config.json 路径
--stats stats.json 路径
--web-dir, -d WebUI 目录
--http HTTP 监听地址
--agent Agent TCP 监听地址
--verbose, -v 详细请求日志
--version 输出构建版本

旧参数 --bind/-b--port/-p 仍可用于设置 Agent TCP 监听地址。

HTTP 管理 API

管理接口使用 Bearer Token:

Authorization: Bearer <ADMIN_TOKEN>

无需认证:

方法路径用途
GET/api/health进程、Agent TCP、版本和配置路径状态
GET/api/schema机器可读的端点与配置集合描述
GET/api/openapi.json可供 AI Agent 直接导入的 OpenAPI 3.1 文档
GET/json/stats.jsonWebUI 使用的实时状态快照

需要认证:

方法路径用途
GET/PUT/api/config读取或整体替换配置
GET/POST/api/servers查询或新增节点
PUT/DELETE/api/servers/{username}修改或删除节点
POST/api/servers/{username}/reset-traffic将当前流量设为本月基线
GET/POST/api/monitors查询或新增服务监测
PUT/DELETE/api/monitors/{index-or-name}修改或删除服务监测
GET/POST/api/sslcerts查询或新增证书监测
PUT/DELETE/api/sslcerts/{index-or-name}修改或删除证书监测
GET/POST/api/watchdog查询或新增 Watchdog
PUT/DELETE/api/watchdog/{index-or-name}修改或删除 Watchdog
POST/api/reload从磁盘重新读取配置
POST/api/restart在进程内重启采集运行时

配置修改采用“校验 → 备份 → 持久化 → 原子切换”的顺序。成功后现有 Agent 连接会被关闭,Python 客户端约 3 秒后自动重连并获取新的 monitors/api/restart 不退出 Go 进程,因此 Docker 和手动运行方式具有一致语义。

常用调用:

TOKEN='请替换为 ADMIN_TOKEN'
curl http://127.0.0.1:8080/api/health
curl -H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/config
curl -X POST http://127.0.0.1:8080/api/servers \
-H "Authorization: Bearer ${TOKEN}" \
-H 'Content-Type: application/json' \
-d '{"username":"s05","name":"node5","type":"kvm","host":"host5","location":"SG","password":"change-me","monthstart":1}'
curl -X DELETE \
-H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/servers/s05

请求体最大为 1 MiB。AI Agent 可直接导入 /api/openapi.json;轻量客户端也可以先读取 /api/schema,再根据返回的集合字段调用 CRUD 接口。

配置文件

{
"servers": [
{
"username": "s01",
"name": "node1",
"type": "kvm",
"host": "host1",
"location": "CN",
"password": "USER_DEFAULT_PASSWORD",
"monthstart": 1,
"disabled": false
}
],
"monitors": [
{
"name": "example",
"host": "https://example.com",
"interval": 600,
"type": "https"
}
],
"sslcerts": [
{
"name": "example",
"domain": "https://example.com",
"port": 443,
"interval": 7200,
"callback": "https://example.net/push?message="
}
],
"watchdog": [
{
"name": "offline warning",
"rule": "online4=0&online6=0",
"interval": 600,
"callback": "https://example.net/push?message="
}
]
}

约束:

  • servers.username 必须唯一。
  • monthstart 自动限制在 1-28
  • port 自动限制在 1-65535
  • interval 最小为 1 秒;Watchdog 中表示通知冷却时间,不是客户端采集间隔。
  • 配置写入前会创建 config.json.bak-*,最多保留 10 份。
  • Docker 单文件 bind mount 无法被 rename 覆盖时,服务端会在完成备份后安全地写回原 inode。

使用 Docker 单文件挂载时,配置备份位于容器 /app/config 的可写层;如需长期保留历史版本,建议同时在宿主机备份 server/config.json

Watchdog 表达式

rule 由 Go expr 引擎执行,并兼容旧版 Exprtk 的常用写法。Go 服务会把字符串外的单个操作符自动转换:

& -> &&
| -> ||
= -> ==

例如以下两种写法等价:

cpu>90&load_1>5&username!='s01'
cpu>90 && load_1>5 && username!='s01'

字符串值支持中文、Emoji 和其他 Unicode 字符,例如:

username='节点一号'&name='上海节点'&location='中国 🇨🇳'&type='云主机'

字段名必须使用系统定义的英文名称。可用字段包括:usernamenametypehostlocationload_1load_5load_15cpumemory_totalmemory_usedswap_totalswap_usedhdd_totalhdd_usednetwork_rxnetwork_txnetwork_innetwork_outlast_network_inlast_network_outping_10010ping_189ping_10086time_10010time_189time_10086tcp_countudp_countprocess_countthread_countio_readio_writeonline4online6

客户端断开 25 秒后仍未重连,服务端才计算离线规则,避免短暂网络波动触发告警。每个节点、每条规则分别记录冷却时间。

SSL 证书

证书检查使用 Go crypto/tls,不再调用外部 openssl。服务端记录到期时间、剩余天数和域名匹配状态,并保留原来的 7/3/1 天通知档位与冷却时间。

回调默认校验 HTTPS 证书。仅在必须兼容自签名回调服务时设置:

INSECURE_CALLBACK_TLS=true

源码编译和运行

需要 Go 1.25 或更高版本:

cd server
go mod download
go test ./...
go build -trimpath -ldflags='-s -w' -o serverstatus .

server/ 目录启动:

ADMIN_TOKEN='请替换为高强度随机字符串' \
./serverstatus \
--config=config.json \
--stats=../web/json/stats.json \
--web-dir=../web \
--http=:8080 \
--agent=:35601

访问 http://127.0.0.1:8080/。发送SIGHUP 可以重新读取配置:

kill -HUP "$(pgrep -x serverstatus)"

Systemd 示例位于 service/status-server.service。一键脚本 status.sh 也已切换到 Go 构建,但 Docker 仍是推荐部署方式。

构建和测试

Go 测试需要 Go 1.25+;WebUI 行为测试需要 Node.js 20+ 和 pnpm。

# Go 单元、协议、API、TLS 和回调测试cd server
go test ./...
go test -race ./...
go vet ./...
# Python 客户端指标、参数与平台识别测试cd ..
python3 -m unittest discover -s clients -p 'test_*.py'# WebUI Chromium 行为测试
pnpm install --frozen-lockfile
pnpm exec playwright install chromium
pnpm test:webui
# Docker 镜像
docker build -f Dockerfile.server -t cppla/serverstatus:server .
docker build -f Dockerfile.client -t cppla/serverstatus:client .# 服务端与客户端真实连接、认证和指标上报
SERVER_IMAGE=cppla/serverstatus:server \
CLIENT_IMAGE=cppla/serverstatus:client \
tests/docker-smoke.sh
# Compose 配置
docker compose -f docker-compose-server.yml config
docker compose -f docker-compose-client.yml config

Docker 联通测试在 Linux 上覆盖客户端的 host 网络和 pid 模式;Docker Desktop 未启用 Host Networking 时会明确提示并使用隔离 bridge 完成本地协议测试。

CI 还会运行 Chromium 行为测试、Docker 服务端/客户端联通测试,并验证客户端镜像可同时构建为 AMD64 和 ARM64。

从旧服务端迁移

  1. 备份原来的 config.jsonweb/json/stats.json
  2. 原配置结构和客户端账号无需转换。
  3. Docker 挂载目标改为 /app/config/config.json/app/data
  4. 删除旧的 nginx、manage_api.pysergate 启动或监督配置。
  5. 启动 Go 服务端后检查 /api/health,再观察客户端自动重连。

stats.json 会按节点的 name/type/host/location 恢复月流量基线。修改这些身份字段会被视为新节点。

致谢

About

云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/

Resources

Stars

4.7k stars

Watchers

48 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - cppla/ServerStatus: 云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/ · GitHub
Skip to content

Repository files navigation

ServerStatus 中文版

ServerStatus 是一个轻量的服务器探针和云监控面板,支持多节点在线状态、资源占用、三网延迟、服务监测、SSL 证书检查、Watchdog 告警、HTTP API 和 Web 配置管理。

在线演示:https://tz.cloudcpp.com

GoCILicenseVersion

ServerStatus WebUI

一、服务端

# Docker Compose,本地构建加:--build
ADMIN_TOKEN='your-strong-token' docker compose -f docker-compose-server.yml up -d 
# Docker Run
wget -qO ~/serverstatus-config.json \
--header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/server/config.json?ref=master'
mkdir -p ~/serverstatus-data
docker run -d --restart=always --name=serverstatus-server \
-e ADMIN_TOKEN='your-strong-token' \
-v ~/serverstatus-config.json:/app/config/config.json \
-v ~/serverstatus-data:/app/data \
-p 8080:80 -p 35601:35601 \
cppla/serverstatus:server

启动后访问:

ADMIN_TOKEN 不设置时,监控页面仍可读取,管理 API 返回 503,WebUI 的“配置”页不能修改数据。

二、客户端

# Docker Compose,本地构建加:--build
SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD \
docker compose -f docker-compose-client.yml up -d --force-recreate
# Docker Run
docker run -d --restart=always --name=serverstatus-client \
--network=host --pid=host \
-e SERVER=127.0.0.1 \
-e USER=s01 \
-e PASSWORD=USER_DEFAULT_PASSWORD \
cppla/serverstatus:client
# Shell Run
wget -qO client-linux.py --header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/clients/client-linux.py?ref=master'
nohup python3 client-linux.py SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD >/dev/null 2>&1&

USER 是常见的宿主机环境变量名。如果没有显式传递或传递方式错误,Compose 可能会把系统中的 $USER 解析成本机用户名,而不是默认的 s01。推荐优先级:

  1. 运行命令显式传递 USER=s01
  2. 修改 docker-compose-client.yml 中的 USER 默认值
  3. Docker 或系统环境中的 USER
变量默认值说明
SERVER127.0.0.1Go 服务端地址
USERs01客户端用户名,必须匹配服务端配置
PORT35601Agent TCP 上报端口
PASSWORDUSER_DEFAULT_PASSWORD客户端密码,必须匹配服务端配置
INTERVAL1状态上报间隔,单位秒
PROBEPORT80三网 TCP 探测端口
PROBE_PROTOCOL_PREFERipv4探测协议偏好,可选 ipv4ipv6
PING_PACKET_HISTORY_LEN100丢包历史窗口
CUcu.tz.cloudcpp.com联通探测地址
CTct.tz.cloudcpp.com电信探测地址
CMcm.tz.cloudcpp.com移动探测地址
CLIENTpsutil客户端实现,可选 psutillinux

服务端参数

Docker 镜像中的默认路径为:

环境变量默认值说明
CONFIG_PATH/app/config/config.json主配置文件
STATS_PATH/app/data/stats.json月流量与状态持久化文件;每 60 秒写入,关键操作与正常退出时立即写入
WEB_DIR/app/webWebUI 静态文件目录
HTTP_ADDR:80WebUI 与 HTTP API 监听地址
AGENT_ADDR:35601客户端 TCP 上报监听地址
ADMIN_TOKEN管理 API Bearer Token;为空时禁用管理接口
ADMIN_CORS_ORIGIN可选的 API CORS Origin
INSECURE_CALLBACK_TLSfalse是否允许 Watchdog/证书回调使用不可信 TLS 证书
VERBOSEfalse输出 Gin HTTP 请求日志
TZAsia/Shanghai容器时区

对应命令行参数:

--config, -c config.json 路径
--stats stats.json 路径
--web-dir, -d WebUI 目录
--http HTTP 监听地址
--agent Agent TCP 监听地址
--verbose, -v 详细请求日志
--version 输出构建版本

旧参数 --bind/-b--port/-p 仍可用于设置 Agent TCP 监听地址。

HTTP 管理 API

管理接口使用 Bearer Token:

Authorization: Bearer <ADMIN_TOKEN>

无需认证:

方法路径用途
GET/api/health进程、Agent TCP、版本和配置路径状态
GET/api/schema机器可读的端点与配置集合描述
GET/api/openapi.json可供 AI Agent 直接导入的 OpenAPI 3.1 文档
GET/json/stats.jsonWebUI 使用的实时状态快照

需要认证:

方法路径用途
GET/PUT/api/config读取或整体替换配置
GET/POST/api/servers查询或新增节点
PUT/DELETE/api/servers/{username}修改或删除节点
POST/api/servers/{username}/reset-traffic将当前流量设为本月基线
GET/POST/api/monitors查询或新增服务监测
PUT/DELETE/api/monitors/{index-or-name}修改或删除服务监测
GET/POST/api/sslcerts查询或新增证书监测
PUT/DELETE/api/sslcerts/{index-or-name}修改或删除证书监测
GET/POST/api/watchdog查询或新增 Watchdog
PUT/DELETE/api/watchdog/{index-or-name}修改或删除 Watchdog
POST/api/reload从磁盘重新读取配置
POST/api/restart在进程内重启采集运行时

配置修改采用“校验 → 备份 → 持久化 → 原子切换”的顺序。成功后现有 Agent 连接会被关闭,Python 客户端约 3 秒后自动重连并获取新的 monitors/api/restart 不退出 Go 进程,因此 Docker 和手动运行方式具有一致语义。

常用调用:

TOKEN='请替换为 ADMIN_TOKEN'
curl http://127.0.0.1:8080/api/health
curl -H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/config
curl -X POST http://127.0.0.1:8080/api/servers \
-H "Authorization: Bearer ${TOKEN}" \
-H 'Content-Type: application/json' \
-d '{"username":"s05","name":"node5","type":"kvm","host":"host5","location":"SG","password":"change-me","monthstart":1}'
curl -X DELETE \
-H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/servers/s05

请求体最大为 1 MiB。AI Agent 可直接导入 /api/openapi.json;轻量客户端也可以先读取 /api/schema,再根据返回的集合字段调用 CRUD 接口。

配置文件

{
"servers": [
{
"username": "s01",
"name": "node1",
"type": "kvm",
"host": "host1",
"location": "CN",
"password": "USER_DEFAULT_PASSWORD",
"monthstart": 1,
"disabled": false
}
],
"monitors": [
{
"name": "example",
"host": "https://example.com",
"interval": 600,
"type": "https"
}
],
"sslcerts": [
{
"name": "example",
"domain": "https://example.com",
"port": 443,
"interval": 7200,
"callback": "https://example.net/push?message="
}
],
"watchdog": [
{
"name": "offline warning",
"rule": "online4=0&online6=0",
"interval": 600,
"callback": "https://example.net/push?message="
}
]
}

约束:

  • servers.username 必须唯一。
  • monthstart 自动限制在 1-28
  • port 自动限制在 1-65535
  • interval 最小为 1 秒;Watchdog 中表示通知冷却时间,不是客户端采集间隔。
  • 配置写入前会创建 config.json.bak-*,最多保留 10 份。
  • Docker 单文件 bind mount 无法被 rename 覆盖时,服务端会在完成备份后安全地写回原 inode。

使用 Docker 单文件挂载时,配置备份位于容器 /app/config 的可写层;如需长期保留历史版本,建议同时在宿主机备份 server/config.json

Watchdog 表达式

rule 由 Go expr 引擎执行,并兼容旧版 Exprtk 的常用写法。Go 服务会把字符串外的单个操作符自动转换:

& -> &&
| -> ||
= -> ==

例如以下两种写法等价:

cpu>90&load_1>5&username!='s01'
cpu>90 && load_1>5 && username!='s01'

字符串值支持中文、Emoji 和其他 Unicode 字符,例如:

username='节点一号'&name='上海节点'&location='中国 🇨🇳'&type='云主机'

字段名必须使用系统定义的英文名称。可用字段包括:usernamenametypehostlocationload_1load_5load_15cpumemory_totalmemory_usedswap_totalswap_usedhdd_totalhdd_usednetwork_rxnetwork_txnetwork_innetwork_outlast_network_inlast_network_outping_10010ping_189ping_10086time_10010time_189time_10086tcp_countudp_countprocess_countthread_countio_readio_writeonline4online6

客户端断开 25 秒后仍未重连,服务端才计算离线规则,避免短暂网络波动触发告警。每个节点、每条规则分别记录冷却时间。

SSL 证书

证书检查使用 Go crypto/tls,不再调用外部 openssl。服务端记录到期时间、剩余天数和域名匹配状态,并保留原来的 7/3/1 天通知档位与冷却时间。

回调默认校验 HTTPS 证书。仅在必须兼容自签名回调服务时设置:

INSECURE_CALLBACK_TLS=true

源码编译和运行

需要 Go 1.25 或更高版本:

cd server
go mod download
go test ./...
go build -trimpath -ldflags='-s -w' -o serverstatus .

server/ 目录启动:

ADMIN_TOKEN='请替换为高强度随机字符串' \
./serverstatus \
--config=config.json \
--stats=../web/json/stats.json \
--web-dir=../web \
--http=:8080 \
--agent=:35601

访问 http://127.0.0.1:8080/。发送SIGHUP 可以重新读取配置:

kill -HUP "$(pgrep -x serverstatus)"

Systemd 示例位于 service/status-server.service。一键脚本 status.sh 也已切换到 Go 构建,但 Docker 仍是推荐部署方式。

构建和测试

Go 测试需要 Go 1.25+;WebUI 行为测试需要 Node.js 20+ 和 pnpm。

# Go 单元、协议、API、TLS 和回调测试cd server
go test ./...
go test -race ./...
go vet ./...
# Python 客户端指标、参数与平台识别测试cd ..
python3 -m unittest discover -s clients -p 'test_*.py'# WebUI Chromium 行为测试
pnpm install --frozen-lockfile
pnpm exec playwright install chromium
pnpm test:webui
# Docker 镜像
docker build -f Dockerfile.server -t cppla/serverstatus:server .
docker build -f Dockerfile.client -t cppla/serverstatus:client .# 服务端与客户端真实连接、认证和指标上报
SERVER_IMAGE=cppla/serverstatus:server \
CLIENT_IMAGE=cppla/serverstatus:client \
tests/docker-smoke.sh
# Compose 配置
docker compose -f docker-compose-server.yml config
docker compose -f docker-compose-client.yml config

Docker 联通测试在 Linux 上覆盖客户端的 host 网络和 pid 模式;Docker Desktop 未启用 Host Networking 时会明确提示并使用隔离 bridge 完成本地协议测试。

CI 还会运行 Chromium 行为测试、Docker 服务端/客户端联通测试,并验证客户端镜像可同时构建为 AMD64 和 ARM64。

从旧服务端迁移

  1. 备份原来的 config.jsonweb/json/stats.json
  2. 原配置结构和客户端账号无需转换。
  3. Docker 挂载目标改为 /app/config/config.json/app/data
  4. 删除旧的 nginx、manage_api.pysergate 启动或监督配置。
  5. 启动 Go 服务端后检查 /api/health,再观察客户端自动重连。

stats.json 会按节点的 name/type/host/location 恢复月流量基线。修改这些身份字段会被视为新节点。

致谢

About

云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/

Resources

Stars

4.7k stars

Watchers

48 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); GitHub - cppla/ServerStatus: 云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/ · GitHub
Skip to content

Repository files navigation

ServerStatus 中文版

ServerStatus 是一个轻量的服务器探针和云监控面板,支持多节点在线状态、资源占用、三网延迟、服务监测、SSL 证书检查、Watchdog 告警、HTTP API 和 Web 配置管理。

在线演示:https://tz.cloudcpp.com

GoCILicenseVersion

ServerStatus WebUI

一、服务端

# Docker Compose,本地构建加:--build
ADMIN_TOKEN='your-strong-token' docker compose -f docker-compose-server.yml up -d 
# Docker Run
wget -qO ~/serverstatus-config.json \
--header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/server/config.json?ref=master'
mkdir -p ~/serverstatus-data
docker run -d --restart=always --name=serverstatus-server \
-e ADMIN_TOKEN='your-strong-token' \
-v ~/serverstatus-config.json:/app/config/config.json \
-v ~/serverstatus-data:/app/data \
-p 8080:80 -p 35601:35601 \
cppla/serverstatus:server

启动后访问:

ADMIN_TOKEN 不设置时,监控页面仍可读取,管理 API 返回 503,WebUI 的“配置”页不能修改数据。

二、客户端

# Docker Compose,本地构建加:--build
SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD \
docker compose -f docker-compose-client.yml up -d --force-recreate
# Docker Run
docker run -d --restart=always --name=serverstatus-client \
--network=host --pid=host \
-e SERVER=127.0.0.1 \
-e USER=s01 \
-e PASSWORD=USER_DEFAULT_PASSWORD \
cppla/serverstatus:client
# Shell Run
wget -qO client-linux.py --header='Accept: application/vnd.github.raw' \
'https://api.github.com/repos/cppla/ServerStatus/contents/clients/client-linux.py?ref=master'
nohup python3 client-linux.py SERVER=127.0.0.1 USER=s01 PASSWORD=USER_DEFAULT_PASSWORD >/dev/null 2>&1&

USER 是常见的宿主机环境变量名。如果没有显式传递或传递方式错误,Compose 可能会把系统中的 $USER 解析成本机用户名,而不是默认的 s01。推荐优先级:

  1. 运行命令显式传递 USER=s01
  2. 修改 docker-compose-client.yml 中的 USER 默认值
  3. Docker 或系统环境中的 USER
变量默认值说明
SERVER127.0.0.1Go 服务端地址
USERs01客户端用户名,必须匹配服务端配置
PORT35601Agent TCP 上报端口
PASSWORDUSER_DEFAULT_PASSWORD客户端密码,必须匹配服务端配置
INTERVAL1状态上报间隔,单位秒
PROBEPORT80三网 TCP 探测端口
PROBE_PROTOCOL_PREFERipv4探测协议偏好,可选 ipv4ipv6
PING_PACKET_HISTORY_LEN100丢包历史窗口
CUcu.tz.cloudcpp.com联通探测地址
CTct.tz.cloudcpp.com电信探测地址
CMcm.tz.cloudcpp.com移动探测地址
CLIENTpsutil客户端实现,可选 psutillinux

服务端参数

Docker 镜像中的默认路径为:

环境变量默认值说明
CONFIG_PATH/app/config/config.json主配置文件
STATS_PATH/app/data/stats.json月流量与状态持久化文件;每 60 秒写入,关键操作与正常退出时立即写入
WEB_DIR/app/webWebUI 静态文件目录
HTTP_ADDR:80WebUI 与 HTTP API 监听地址
AGENT_ADDR:35601客户端 TCP 上报监听地址
ADMIN_TOKEN管理 API Bearer Token;为空时禁用管理接口
ADMIN_CORS_ORIGIN可选的 API CORS Origin
INSECURE_CALLBACK_TLSfalse是否允许 Watchdog/证书回调使用不可信 TLS 证书
VERBOSEfalse输出 Gin HTTP 请求日志
TZAsia/Shanghai容器时区

对应命令行参数:

--config, -c config.json 路径
--stats stats.json 路径
--web-dir, -d WebUI 目录
--http HTTP 监听地址
--agent Agent TCP 监听地址
--verbose, -v 详细请求日志
--version 输出构建版本

旧参数 --bind/-b--port/-p 仍可用于设置 Agent TCP 监听地址。

HTTP 管理 API

管理接口使用 Bearer Token:

Authorization: Bearer <ADMIN_TOKEN>

无需认证:

方法路径用途
GET/api/health进程、Agent TCP、版本和配置路径状态
GET/api/schema机器可读的端点与配置集合描述
GET/api/openapi.json可供 AI Agent 直接导入的 OpenAPI 3.1 文档
GET/json/stats.jsonWebUI 使用的实时状态快照

需要认证:

方法路径用途
GET/PUT/api/config读取或整体替换配置
GET/POST/api/servers查询或新增节点
PUT/DELETE/api/servers/{username}修改或删除节点
POST/api/servers/{username}/reset-traffic将当前流量设为本月基线
GET/POST/api/monitors查询或新增服务监测
PUT/DELETE/api/monitors/{index-or-name}修改或删除服务监测
GET/POST/api/sslcerts查询或新增证书监测
PUT/DELETE/api/sslcerts/{index-or-name}修改或删除证书监测
GET/POST/api/watchdog查询或新增 Watchdog
PUT/DELETE/api/watchdog/{index-or-name}修改或删除 Watchdog
POST/api/reload从磁盘重新读取配置
POST/api/restart在进程内重启采集运行时

配置修改采用“校验 → 备份 → 持久化 → 原子切换”的顺序。成功后现有 Agent 连接会被关闭,Python 客户端约 3 秒后自动重连并获取新的 monitors/api/restart 不退出 Go 进程,因此 Docker 和手动运行方式具有一致语义。

常用调用:

TOKEN='请替换为 ADMIN_TOKEN'
curl http://127.0.0.1:8080/api/health
curl -H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/config
curl -X POST http://127.0.0.1:8080/api/servers \
-H "Authorization: Bearer ${TOKEN}" \
-H 'Content-Type: application/json' \
-d '{"username":"s05","name":"node5","type":"kvm","host":"host5","location":"SG","password":"change-me","monthstart":1}'
curl -X DELETE \
-H "Authorization: Bearer ${TOKEN}" \
http://127.0.0.1:8080/api/servers/s05

请求体最大为 1 MiB。AI Agent 可直接导入 /api/openapi.json;轻量客户端也可以先读取 /api/schema,再根据返回的集合字段调用 CRUD 接口。

配置文件

{
"servers": [
{
"username": "s01",
"name": "node1",
"type": "kvm",
"host": "host1",
"location": "CN",
"password": "USER_DEFAULT_PASSWORD",
"monthstart": 1,
"disabled": false
}
],
"monitors": [
{
"name": "example",
"host": "https://example.com",
"interval": 600,
"type": "https"
}
],
"sslcerts": [
{
"name": "example",
"domain": "https://example.com",
"port": 443,
"interval": 7200,
"callback": "https://example.net/push?message="
}
],
"watchdog": [
{
"name": "offline warning",
"rule": "online4=0&online6=0",
"interval": 600,
"callback": "https://example.net/push?message="
}
]
}

约束:

  • servers.username 必须唯一。
  • monthstart 自动限制在 1-28
  • port 自动限制在 1-65535
  • interval 最小为 1 秒;Watchdog 中表示通知冷却时间,不是客户端采集间隔。
  • 配置写入前会创建 config.json.bak-*,最多保留 10 份。
  • Docker 单文件 bind mount 无法被 rename 覆盖时,服务端会在完成备份后安全地写回原 inode。

使用 Docker 单文件挂载时,配置备份位于容器 /app/config 的可写层;如需长期保留历史版本,建议同时在宿主机备份 server/config.json

Watchdog 表达式

rule 由 Go expr 引擎执行,并兼容旧版 Exprtk 的常用写法。Go 服务会把字符串外的单个操作符自动转换:

& -> &&
| -> ||
= -> ==

例如以下两种写法等价:

cpu>90&load_1>5&username!='s01'
cpu>90 && load_1>5 && username!='s01'

字符串值支持中文、Emoji 和其他 Unicode 字符,例如:

username='节点一号'&name='上海节点'&location='中国 🇨🇳'&type='云主机'

字段名必须使用系统定义的英文名称。可用字段包括:usernamenametypehostlocationload_1load_5load_15cpumemory_totalmemory_usedswap_totalswap_usedhdd_totalhdd_usednetwork_rxnetwork_txnetwork_innetwork_outlast_network_inlast_network_outping_10010ping_189ping_10086time_10010time_189time_10086tcp_countudp_countprocess_countthread_countio_readio_writeonline4online6

客户端断开 25 秒后仍未重连,服务端才计算离线规则,避免短暂网络波动触发告警。每个节点、每条规则分别记录冷却时间。

SSL 证书

证书检查使用 Go crypto/tls,不再调用外部 openssl。服务端记录到期时间、剩余天数和域名匹配状态,并保留原来的 7/3/1 天通知档位与冷却时间。

回调默认校验 HTTPS 证书。仅在必须兼容自签名回调服务时设置:

INSECURE_CALLBACK_TLS=true

源码编译和运行

需要 Go 1.25 或更高版本:

cd server
go mod download
go test ./...
go build -trimpath -ldflags='-s -w' -o serverstatus .

server/ 目录启动:

ADMIN_TOKEN='请替换为高强度随机字符串' \
./serverstatus \
--config=config.json \
--stats=../web/json/stats.json \
--web-dir=../web \
--http=:8080 \
--agent=:35601

访问 http://127.0.0.1:8080/。发送SIGHUP 可以重新读取配置:

kill -HUP "$(pgrep -x serverstatus)"

Systemd 示例位于 service/status-server.service。一键脚本 status.sh 也已切换到 Go 构建,但 Docker 仍是推荐部署方式。

构建和测试

Go 测试需要 Go 1.25+;WebUI 行为测试需要 Node.js 20+ 和 pnpm。

# Go 单元、协议、API、TLS 和回调测试cd server
go test ./...
go test -race ./...
go vet ./...
# Python 客户端指标、参数与平台识别测试cd ..
python3 -m unittest discover -s clients -p 'test_*.py'# WebUI Chromium 行为测试
pnpm install --frozen-lockfile
pnpm exec playwright install chromium
pnpm test:webui
# Docker 镜像
docker build -f Dockerfile.server -t cppla/serverstatus:server .
docker build -f Dockerfile.client -t cppla/serverstatus:client .# 服务端与客户端真实连接、认证和指标上报
SERVER_IMAGE=cppla/serverstatus:server \
CLIENT_IMAGE=cppla/serverstatus:client \
tests/docker-smoke.sh
# Compose 配置
docker compose -f docker-compose-server.yml config
docker compose -f docker-compose-client.yml config

Docker 联通测试在 Linux 上覆盖客户端的 host 网络和 pid 模式;Docker Desktop 未启用 Host Networking 时会明确提示并使用隔离 bridge 完成本地协议测试。

CI 还会运行 Chromium 行为测试、Docker 服务端/客户端联通测试,并验证客户端镜像可同时构建为 AMD64 和 ARM64。

从旧服务端迁移

  1. 备份原来的 config.jsonweb/json/stats.json
  2. 原配置结构和客户端账号无需转换。
  3. Docker 挂载目标改为 /app/config/config.json/app/data
  4. 删除旧的 nginx、manage_api.pysergate 启动或监督配置。
  5. 启动 Go 服务端后检查 /api/health,再观察客户端自动重连。

stats.json 会按节点的 name/type/host/location 恢复月流量基线。修改这些身份字段会被视为新节点。

致谢

About

云探针、多服务器探针、云监控、多服务器云监控,演示: https://tz.cloudcpp.com/

Resources

Stars

4.7k stars

Watchers

48 watching

Forks

Releases

Packages

Used by

Contributors

Languages