name: bot-status-api
description: "部署一个轻量级状态 API,用于展示 OpenClaw 机器人的运行健康状况、服务连通性、定时任务、技能、系统指标等信息。适用于为 OpenClaw 智能体搭建监控仪表盘、健康检查端点或状态页面。支持通过配置对接任意服务(HTTP 检查、CLI 命令、文件检查)。零依赖——仅需 Node.js 环境。"
一个可配置的 HTTP 服务,以 JSON 格式展示 OpenClaw 机器人的运行状态。专为仪表盘集成、监控和状态透明化而设计。
cron/jobs.json 文件/proc 读取 CPU、内存、磁盘使用情况将 server.js、collectors/ 目录和 package.json 复制到目标位置。
复制 config.example.json 为 config.json 并自定义配置:
{
"port": 3200,
"name": "MyBot",
"workspace": "/path/to/.openclaw/workspace",
"openclawHome": "/path/to/.openclaw",
"cache": { "ttlMs": 10000 },
"model": "claude-sonnet-4-20250514",
"skillDirs": ["/path/to/openclaw/skills"],
"services": [
{ "name": "myservice", "type": "http", "url": "http://...", "healthPath": "/health" }
]
}
| 类型 | 说明 | 配置项 |
|---|---|---|
http |
请求 URL,检查 HTTP 200 状态 | url, healthPath, method, headers, body |
command |
执行 shell 命令,检查退出码 0 | command, timeout |
file-exists |
检查文件路径是否存在 | path |
node server.js
# ~/.config/systemd/user/bot-status.service
[Unit]
Description=Bot Status API
After=network.target
[Service]
Type=simple
WorkingDirectory=/path/to/bot-status
ExecStart=/usr/bin/node server.js
Restart=always
RestartSec=5
Environment=PORT=3200
Environment=HOME=/home/youruser
Environment=PATH=/usr/local/bin:/usr/bin:/bin
[Install]
WantedBy=default.target
systemctl --user daemon-reload
systemctl --user enable --now bot-status
loginctl enable-linger $USER # 保持服务在用户登出后继续运行
机器人应定期将核心指标写入工作空间的 heartbeat-state.json 文件:
{
"vitals": {
"contextPercent": 62,
"contextUsed": 124000,
"contextMax": 200000,
"model": "claude-opus-4-5",
"updatedAt": 1770304500000
}
}
将此功能添加到 HEARTBEAT.md 中,以便机器人在每次心跳周期更新该文件。
| 端点 | 说明 |
|---|---|
GET /status |
完整状态 JSON(缓存) |
GET /health |
简单健康检查 {"status":"ok"} |
http、fs、child_process)exec,避免 execSync 阻塞config.json 中,无硬编码值