* 默认监听调整为 0.0.0.0:8080,并要求查询参数 token * 支持首次 run 自动生成含随机 token 的配置文件 * 补充 HTTP 鉴权、配置校验和相关测试 * 完善代码注释,覆盖缓存、上报、服务和平台采集路径 * 新增架构与开发流程文档,补充一键构建脚本
123 lines
3.1 KiB
Markdown
123 lines
3.1 KiB
Markdown
# MFD Monitor Agent
|
|
|
|
Single-binary host status agent implemented in Go.
|
|
|
|
## Features
|
|
|
|
- `GET /health?token=...` returns process liveness and latest snapshot metadata.
|
|
- `GET /status?token=...` returns the cached full host snapshot.
|
|
- On first `agent run`, creates `config.json` in the working directory if missing (with a random token).
|
|
- Periodic background collection keeps HTTP responses fast.
|
|
- Optional periodic HTTP POST reporting reuses the same `HostStatus` JSON.
|
|
- Linux collectors read host, network, CPU, memory, disk, process, and TCP listener data from the OS.
|
|
- Windows and Linux service lifecycle commands are exposed through the CLI.
|
|
|
|
**完整部署说明(中文):** [docs/DEPLOYMENT.md](docs/DEPLOYMENT.md)
|
|
|
|
**架构与流程说明:** [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md)
|
|
|
|
**开发与构建流程:** [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md)
|
|
|
|
## Quick Start
|
|
|
|
```bash
|
|
go test ./...
|
|
go run ./cmd/agent run
|
|
```
|
|
|
|
首次运行会在当前目录生成 `config.json`,其中包含随机 `http.token`。使用该 token 访问:
|
|
|
|
```text
|
|
http://127.0.0.1:8080/health?token=<http.token>
|
|
http://127.0.0.1:8080/status?token=<http.token>
|
|
```
|
|
|
|
## Commands
|
|
|
|
```bash
|
|
agent run [-config config.json]
|
|
agent install [-config config.json] [-exe /path/to/agent]
|
|
agent uninstall [-config config.json]
|
|
agent start [-config config.json]
|
|
agent stop [-config config.json]
|
|
agent version
|
|
```
|
|
|
|
## Build
|
|
|
|
All default targets:
|
|
|
|
```bash
|
|
./scripts/build-all.sh
|
|
```
|
|
|
|
Linux:
|
|
|
|
```bash
|
|
./scripts/build-linux.sh
|
|
```
|
|
|
|
Windows PowerShell:
|
|
|
|
```powershell
|
|
.\scripts\build-windows.ps1
|
|
```
|
|
|
|
Cross-compile Windows from Linux:
|
|
|
|
```bash
|
|
GOOS_TARGET=windows GOARCH_TARGET=amd64 OUTPUT_NAME=agent-windows-amd64.exe ./scripts/build-linux.sh
|
|
```
|
|
|
|
Build outputs are written to `dist/`, which is intentionally ignored by Git.
|
|
|
|
## Configuration
|
|
|
|
Example config: [configs/example.json](configs/example.json). See [docs/DEPLOYMENT.md](docs/DEPLOYMENT.md) for defaults, environment variables, and production deployment steps.
|
|
|
|
```json
|
|
{
|
|
"host_id": "host-a",
|
|
"http": {
|
|
"listen_address": "0.0.0.0:8080",
|
|
"token": "replace-with-a-strong-random-value"
|
|
},
|
|
"collect": {
|
|
"interval": "30s",
|
|
"timeout": "10s"
|
|
},
|
|
"report": {
|
|
"enabled": true,
|
|
"endpoint": "http://center.example.internal/agent/status",
|
|
"interval": "60s",
|
|
"timeout": "5s"
|
|
}
|
|
}
|
|
```
|
|
|
|
API access (browser-friendly query parameter):
|
|
|
|
```text
|
|
http://<host>:8080/health?token=<http.token>
|
|
http://<host>:8080/status?token=<http.token>
|
|
```
|
|
|
|
Environment overrides:
|
|
|
|
- `MFD_AGENT_HOST_ID`
|
|
- `MFD_AGENT_LISTEN`
|
|
- `MFD_AGENT_TOKEN`
|
|
- `MFD_AGENT_COLLECT_INTERVAL`
|
|
- `MFD_AGENT_COLLECT_TIMEOUT`
|
|
- `MFD_AGENT_REPORT_ENABLED`
|
|
- `MFD_AGENT_REPORT_ENDPOINT`
|
|
- `MFD_AGENT_REPORT_INTERVAL`
|
|
- `MFD_AGENT_REPORT_TIMEOUT`
|
|
|
|
## Documentation Map
|
|
|
|
- [docs/DEPLOYMENT.md](docs/DEPLOYMENT.md): production deployment, validation, upgrade, rollback, troubleshooting.
|
|
- [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md): runtime workflow, cache behavior, partial-success model, platform differences.
|
|
- [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md): tests, build scripts, cross-platform verification.
|
|
- [AGENTS.md](AGENTS.md): repository rules and first-version scope.
|