codex de3fd88948 ✨ feat(agent): 添加 token 鉴权和流程文档
* 默认监听调整为 0.0.0.0:8080,并要求查询参数 token
* 支持首次 run 自动生成含随机 token 的配置文件
* 补充 HTTP 鉴权、配置校验和相关测试
* 完善代码注释,覆盖缓存、上报、服务和平台采集路径
* 新增架构与开发流程文档,补充一键构建脚本
2026-05-22 06:46:21 +00:00
2026-05-18 15:25:51 +00:00

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/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_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

Description
No description provided
Readme 170 KiB
Languages
Go 97%
Shell 1.8%
PowerShell 1.2%