feat: add Go-based HarborForge monitor client
- collect CPU, memory, disk, swap, load, and uptime telemetry - detect nginx and list /etc/nginx/sites-enabled entries - send heartbeat-v2 payload with API key auth - provide install script, config example, and systemd unit
This commit is contained in:
88
README.md
Normal file
88
README.md
Normal file
@@ -0,0 +1,88 @@
|
||||
# HarborForge.Monitor
|
||||
|
||||
轻量级 Go 遥测客户端,用于把服务器硬件状态上报到 HarborForge Monitor。
|
||||
|
||||
它**不依赖 OpenClaw**,适合普通 Linux 主机、VPS、Nginx 机器等。
|
||||
|
||||
## 采集内容
|
||||
|
||||
- CPU 使用率
|
||||
- 内存使用率
|
||||
- 磁盘使用率
|
||||
- Swap 使用率
|
||||
- Load Average
|
||||
- Uptime
|
||||
- Nginx 是否安装
|
||||
- `/etc/nginx/sites-enabled` 列表
|
||||
|
||||
## 上报接口
|
||||
|
||||
客户端调用:
|
||||
|
||||
- `POST /monitor/server/heartbeat-v2`
|
||||
- Header: `X-API-Key`
|
||||
|
||||
## 项目结构
|
||||
|
||||
```text
|
||||
HarborForge.Monitor/
|
||||
├── cmd/harborforge-monitor/ # 程序入口
|
||||
├── internal/config/ # 配置加载
|
||||
├── internal/telemetry/ # 指标采集与上报
|
||||
├── scripts/install.sh # 安装脚本
|
||||
├── systemd/harborforge-monitor.service
|
||||
├── config.example.json
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## 配置
|
||||
|
||||
先在 HarborForge Monitor 中注册服务器并生成 API Key。
|
||||
|
||||
然后准备配置文件,例如 `/etc/harborforge-monitor/config.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"backendUrl": "https://monitor.hangman-lab.top",
|
||||
"identifier": "vps-nginx-01",
|
||||
"apiKey": "your-api-key",
|
||||
"reportIntervalSec": 30,
|
||||
"logLevel": "info"
|
||||
}
|
||||
```
|
||||
|
||||
也支持环境变量覆盖:
|
||||
|
||||
- `HF_MONITOR_BACKEND_URL`
|
||||
- `HF_MONITOR_IDENTIFIER`
|
||||
- `HF_MONITOR_API_KEY`
|
||||
- `HF_MONITOR_REPORT_INTERVAL`
|
||||
- `HF_MONITOR_LOG_LEVEL`
|
||||
|
||||
## 本地开发
|
||||
|
||||
```bash
|
||||
go mod tidy
|
||||
go build ./cmd/harborforge-monitor
|
||||
./harborforge-monitor -config ./config.example.json -dry-run -once
|
||||
```
|
||||
|
||||
## 安装
|
||||
|
||||
```bash
|
||||
sudo ./scripts/install.sh
|
||||
```
|
||||
|
||||
安装脚本会:
|
||||
|
||||
- 构建二进制 `harborforge-monitor`
|
||||
- 安装到 `/usr/local/bin/`
|
||||
- 安装 systemd service
|
||||
- 初始化 `/etc/harborforge-monitor/config.json`
|
||||
- 自动启用并启动服务
|
||||
|
||||
## 注意
|
||||
|
||||
- 当前 Nginx site 列表读取的是 `/etc/nginx/sites-enabled`
|
||||
- 如果机器没有安装 Nginx,会回报 `nginx_installed = false`
|
||||
- 该客户端不会尝试读取 OpenClaw 信息,`agents` 默认为空,`openclaw_version` 不上报
|
||||
Reference in New Issue
Block a user