✨ feat(agent): 添加 token 鉴权和流程文档
* 默认监听调整为 0.0.0.0:8080,并要求查询参数 token * 支持首次 run 自动生成含随机 token 的配置文件 * 补充 HTTP 鉴权、配置校验和相关测试 * 完善代码注释,覆盖缓存、上报、服务和平台采集路径 * 新增架构与开发流程文档,补充一键构建脚本
This commit is contained in:
47
README.md
47
README.md
@@ -4,8 +4,9 @@ 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.
|
||||
- `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.
|
||||
@@ -13,6 +14,24 @@ Single-binary host status agent implemented in Go.
|
||||
|
||||
**完整部署说明(中文):** [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
|
||||
@@ -26,6 +45,12 @@ agent version
|
||||
|
||||
## Build
|
||||
|
||||
All default targets:
|
||||
|
||||
```bash
|
||||
./scripts/build-all.sh
|
||||
```
|
||||
|
||||
Linux:
|
||||
|
||||
```bash
|
||||
@@ -54,7 +79,8 @@ Example config: [configs/example.json](configs/example.json). See [docs/DEPLOYME
|
||||
{
|
||||
"host_id": "host-a",
|
||||
"http": {
|
||||
"listen_address": "127.0.0.1:8080"
|
||||
"listen_address": "0.0.0.0:8080",
|
||||
"token": "replace-with-a-strong-random-value"
|
||||
},
|
||||
"collect": {
|
||||
"interval": "30s",
|
||||
@@ -69,13 +95,28 @@ Example config: [configs/example.json](configs/example.json). See [docs/DEPLOYME
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user