💥 feat(agent)!: 添加主机监控代理首版

* 实现周期采集、快照缓存、本地 HTTP API 和主动上报

* 补齐 Linux 和 Windows 主机、网络、资源、进程和 TCP 采集

* 添加服务生命周期管理、配置加载、构建脚本和测试覆盖

BREAKING CHANGE: network.ips 拆分为 network.ipv4s 和 network.ipv6s。
This commit is contained in:
codex
2026-05-18 15:25:51 +00:00
commit 89d5e27874
33 changed files with 4205 additions and 0 deletions

79
README.md Normal file
View File

@@ -0,0 +1,79 @@
# MFD Monitor Agent
Single-binary host status agent implemented in Go.
## Features
- `GET /health` returns process liveness and latest snapshot metadata.
- `GET /status` returns the cached full host snapshot.
- 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.
## 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
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
All settings have safe defaults. The HTTP API listens on `127.0.0.1:8080` by default.
```json
{
"host_id": "host-a",
"http": {
"listen_address": "127.0.0.1:8080"
},
"collect": {
"interval": "30s",
"timeout": "10s"
},
"report": {
"enabled": true,
"endpoint": "http://center.example.internal/agent/status",
"interval": "60s",
"timeout": "5s"
}
}
```
Environment overrides:
- `MFD_AGENT_HOST_ID`
- `MFD_AGENT_LISTEN`
- `MFD_AGENT_COLLECT_INTERVAL`
- `MFD_AGENT_COLLECT_TIMEOUT`
- `MFD_AGENT_REPORT_ENABLED`
- `MFD_AGENT_REPORT_ENDPOINT`
- `MFD_AGENT_REPORT_INTERVAL`
- `MFD_AGENT_REPORT_TIMEOUT`