* 默认监听调整为 0.0.0.0:8080,并要求查询参数 token * 支持首次 run 自动生成含随机 token 的配置文件 * 补充 HTTP 鉴权、配置校验和相关测试 * 完善代码注释,覆盖缓存、上报、服务和平台采集路径 * 新增架构与开发流程文档,补充一键构建脚本
3.1 KiB
3.1 KiB
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, createsconfig.jsonin the working directory if missing (with a random token). - Periodic background collection keeps HTTP responses fast.
- Optional periodic HTTP POST reporting reuses the same
HostStatusJSON. - 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/ARCHITECTURE.md
开发与构建流程: docs/DEVELOPMENT.md
Quick Start
go test ./...
go run ./cmd/agent run
首次运行会在当前目录生成 config.json,其中包含随机 http.token。使用该 token 访问:
http://127.0.0.1:8080/health?token=<http.token>
http://127.0.0.1:8080/status?token=<http.token>
Commands
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:
./scripts/build-all.sh
Linux:
./scripts/build-linux.sh
Windows PowerShell:
.\scripts\build-windows.ps1
Cross-compile Windows from Linux:
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. See docs/DEPLOYMENT.md for defaults, environment variables, and production deployment steps.
{
"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):
http://<host>:8080/health?token=<http.token>
http://<host>:8080/status?token=<http.token>
Environment overrides:
MFD_AGENT_HOST_IDMFD_AGENT_LISTENMFD_AGENT_TOKENMFD_AGENT_COLLECT_INTERVALMFD_AGENT_COLLECT_TIMEOUTMFD_AGENT_REPORT_ENABLEDMFD_AGENT_REPORT_ENDPOINTMFD_AGENT_REPORT_INTERVALMFD_AGENT_REPORT_TIMEOUT
Documentation Map
- docs/DEPLOYMENT.md: production deployment, validation, upgrade, rollback, troubleshooting.
- docs/ARCHITECTURE.md: runtime workflow, cache behavior, partial-success model, platform differences.
- docs/DEVELOPMENT.md: tests, build scripts, cross-platform verification.
- AGENTS.md: repository rules and first-version scope.