docs: update README, API reference, dev-log, project structure with Agent monitoring + quick-alarm + latest fixes
- README.md: React 19, default pwd 123456, Docker Compose deploy, correct module list - api-reference.md: add Agent monitoring section (report/latest/rules/quick-setup/alerts/tasks/kline) - dev-log.md: new entry documenting hostname/IP fix, system collector, offline detection, quick alarm - project-structure.md: add agent/ directory, dev-log.md link, React 19
This commit is contained in:
1 parent
c51d0b8b8b
commit
4e3f8cb306
20 files changed
+1315
-1344
No files matched your search
@@ -259,3 +259,404 @@
|
||||
"git_commit": "unknown"
|
||||
}
|
||||
```
|
||||
|
||||
## Agent 监控
|
||||
|
||||
### POST /agent/report — Agent 上报指标 (无需 JWT)
|
||||
|
||||
Agent 向服务端上报主机性能指标数据。
|
||||
|
||||
**请求体:**
|
||||
```json
|
||||
{
|
||||
"hostname": "web-server-01",
|
||||
"cpu": {
|
||||
"usage_percent": 45.2,
|
||||
"cores": 8
|
||||
},
|
||||
"memory": {
|
||||
"total_gb": 16,
|
||||
"used_gb": 8.5,
|
||||
"usage_percent": 53.1
|
||||
},
|
||||
"disk": [
|
||||
{
|
||||
"mount": "/",
|
||||
"total_gb": 100,
|
||||
"used_gb": 60,
|
||||
"usage_percent": 60.0
|
||||
}
|
||||
],
|
||||
"network": {
|
||||
"rx_bytes": 1024000,
|
||||
"tx_bytes": 512000
|
||||
},
|
||||
"uptime_seconds": 864000
|
||||
}
|
||||
```
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "上报成功",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
### GET /agent/latest — 各主机最新指标 (需 JWT)
|
||||
|
||||
获取所有在线主机的最近一次上报指标。仅返回 3 分钟内活跃且匹配 servers 表的主机。
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": [
|
||||
{
|
||||
"hostname": "web-server-01",
|
||||
"cpu": { "usage_percent": 45.2 },
|
||||
"memory": { "usage_percent": 53.1 },
|
||||
"disk": [{"usage_percent": 60.0}],
|
||||
"network": { "rx_bytes": 1024000, "tx_bytes": 512000 },
|
||||
"uptime_seconds": 864000,
|
||||
"reported_at": "2025-06-18T10:30:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### GET /agent/history/:hostname — 历史趋势 (?hours=N)
|
||||
|
||||
查询指定主机在最近 N 小时内的指标历史数据。
|
||||
|
||||
**查询参数:**
|
||||
|
||||
| 参数 | 类型 | 默认值 | 说明 |
|
||||
|------|------|--------|------|
|
||||
| `hours` | int | 24 | 查询最近多少小时的数据 |
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": [
|
||||
{
|
||||
"hostname": "web-server-01",
|
||||
"cpu": { "usage_percent": 45.2 },
|
||||
"memory": { "usage_percent": 53.1 },
|
||||
"reported_at": "2025-06-18T10:30:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Agent 告警规则
|
||||
|
||||
#### GET /agent/rules — 规则列表
|
||||
|
||||
获取所有 Agent 告警规则。
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "CPU 使用率过高",
|
||||
"metric": "cpu.usage_percent",
|
||||
"condition": ">",
|
||||
"threshold": 80,
|
||||
"hostname": "*",
|
||||
"enabled": true,
|
||||
"created_at": "2025-06-18T10:00:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### POST /agent/rules — 创建规则
|
||||
|
||||
创建一条 Agent 告警规则。
|
||||
|
||||
**请求体:**
|
||||
```json
|
||||
{
|
||||
"name": "CPU 使用率过高",
|
||||
"metric": "cpu.usage_percent",
|
||||
"condition": ">",
|
||||
"threshold": 80,
|
||||
"hostname": "*"
|
||||
}
|
||||
```
|
||||
|
||||
#### POST /agent/rules/quick-setup — 一键创建默认规则
|
||||
|
||||
一键创建默认告警规则(CPU / 内存 / 磁盘 / 网络,阈值 80%),作用于所有在线主机。
|
||||
|
||||
**请求体:** 无(可选传空 JSON `{}`)
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "默认规则创建成功",
|
||||
"data": {
|
||||
"created": 4
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
默认创建的规则包括:
|
||||
|
||||
| 规则名称 | 指标 | 条件 | 阈值 |
|
||||
|----------|------|------|------|
|
||||
| CPU 使用率过高 | `cpu.usage_percent` | `>` | 80 |
|
||||
| 内存使用率过高 | `memory.usage_percent` | `>` | 80 |
|
||||
| 磁盘使用率过高 | `disk.usage_percent` | `>` | 80 |
|
||||
| 网络带宽过高 | `network.total_bytes` | `>` | 80 |
|
||||
|
||||
#### PUT /agent/rules/:id — 更新规则
|
||||
|
||||
更新指定告警规则。
|
||||
|
||||
#### DELETE /agent/rules/:id — 删除规则
|
||||
|
||||
删除指定告警规则。
|
||||
|
||||
---
|
||||
|
||||
### Agent 告警事件
|
||||
|
||||
#### GET /agent/alerts — 告警事件列表
|
||||
|
||||
获取 Agent 触发的告警事件列表。
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"list": [
|
||||
{
|
||||
"id": 1,
|
||||
"rule_id": 1,
|
||||
"rule_name": "CPU 使用率过高",
|
||||
"hostname": "web-server-01",
|
||||
"metric": "cpu.usage_percent",
|
||||
"value": 92.5,
|
||||
"threshold": 80,
|
||||
"status": "firing",
|
||||
"fired_at": "2025-06-18T10:30:00Z",
|
||||
"resolved_at": null
|
||||
}
|
||||
],
|
||||
"total": 1
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### POST /agent/alerts/:id/resolve — 恢复告警
|
||||
|
||||
手动将指定告警事件标记为已恢复。
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "告警已恢复",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Agent 远程任务
|
||||
|
||||
#### POST /agent/tasks — 下发远程任务
|
||||
|
||||
向指定主机下发远程任务(如执行脚本、重启服务等)。
|
||||
|
||||
**请求体:**
|
||||
```json
|
||||
{
|
||||
"hostname": "web-server-01",
|
||||
"command": "systemctl restart nginx",
|
||||
"description": "重启 Nginx 服务",
|
||||
"timeout_seconds": 30
|
||||
}
|
||||
```
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "任务已下发",
|
||||
"data": {
|
||||
"task_id": "550e8400-e29b-41d4-a716-446655440000",
|
||||
"status": "pending"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### GET /agent/tasks — 任务列表
|
||||
|
||||
获取所有远程任务的列表(支持分页和筛选)。
|
||||
|
||||
**查询参数:**
|
||||
|
||||
| 参数 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| `hostname` | string | 按主机名筛选 |
|
||||
| `status` | string | 按状态筛选:`pending`、`running`、`success`、`failed` |
|
||||
| `page` | int | 页码 (默认 1) |
|
||||
| `page_size` | int | 每页数量 (默认 20) |
|
||||
|
||||
#### GET /agent/tasks/:id — 任务详情
|
||||
|
||||
获取指定远程任务的详细信息及执行结果。
|
||||
|
||||
#### GET /agent/tasks/poll?hostname=xx — Agent 拉取任务 (无需 JWT)
|
||||
|
||||
Agent 主动轮询拉取分配给自己的待执行任务。
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": [
|
||||
{
|
||||
"task_id": "550e8400-e29b-41d4-a716-446655440000",
|
||||
"command": "systemctl restart nginx",
|
||||
"timeout_seconds": 30
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### POST /agent/tasks/:task_id/result — Agent 回传结果 (无需 JWT)
|
||||
|
||||
Agent 执行完任务后,回传执行结果。
|
||||
|
||||
**请求体:**
|
||||
```json
|
||||
{
|
||||
"status": "success",
|
||||
"stdout": "nginx restarted successfully\n",
|
||||
"stderr": "",
|
||||
"exit_code": 0,
|
||||
"duration_ms": 2500
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Agent K线聚合
|
||||
|
||||
#### POST /agent/aggregate — 触发聚合
|
||||
|
||||
手动触发 K 线数据聚合任务(通常由定时任务自动执行)。
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "聚合任务已触发",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
#### GET /agent/kline — 查询 K 线
|
||||
|
||||
查询主机性能指标的 K 线(聚合)数据。
|
||||
|
||||
**查询参数:**
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| `hostname` | string | 否 | 主机名,不传则返回所有主机 |
|
||||
| `metric` | string | 否 | 指标名,如 `cpu.usage_percent` |
|
||||
| `interval` | string | 否 | 聚合间隔:`1m`、`5m`、`15m`、`1h`、`1d` |
|
||||
| `from` | string | 否 | 起始时间 (ISO 8601) |
|
||||
| `to` | string | 否 | 结束时间 (ISO 8601) |
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": [
|
||||
{
|
||||
"hostname": "web-server-01",
|
||||
"metric": "cpu.usage_percent",
|
||||
"timestamp": "2025-06-18T10:00:00Z",
|
||||
"open": 45.0,
|
||||
"high": 92.5,
|
||||
"low": 40.0,
|
||||
"close": 55.0,
|
||||
"avg": 53.2,
|
||||
"count": 60
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Agent 二进制分发 (无需 JWT)
|
||||
|
||||
提供 Agent 二进制文件及安装脚本的下载。
|
||||
|
||||
#### GET /agent/arch — 版本信息 + 下载链接
|
||||
|
||||
获取当前 Agent 版本信息及各架构对应的下载链接。
|
||||
|
||||
**响应:**
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"version": "v1.2.3",
|
||||
"released_at": "2025-06-18",
|
||||
"downloads": {
|
||||
"linux_amd64": "/api/v1/agent/aiops-agent-linux-amd64",
|
||||
"linux_arm64": "/api/v1/agent/aiops-agent-linux-arm64",
|
||||
"darwin_arm64": "/api/v1/agent/aiops-agent-darwin-arm64"
|
||||
},
|
||||
"install_script": "/api/v1/agent/install.sh"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### GET /agent/aiops-agent-linux-amd64 — x86_64 二进制
|
||||
|
||||
下载 Linux x86_64 架构的 Agent 二进制文件。
|
||||
|
||||
响应为二进制流 (`Content-Type: application/octet-stream`)。
|
||||
|
||||
#### GET /agent/aiops-agent-linux-arm64 — ARM64 二进制
|
||||
|
||||
下载 Linux ARM64 架构的 Agent 二进制文件。
|
||||
|
||||
响应为二进制流 (`Content-Type: application/octet-stream`)。
|
||||
|
||||
#### GET /agent/aiops-agent-darwin-arm64 — macOS 二进制
|
||||
|
||||
下载 macOS Apple Silicon (ARM64) 架构的 Agent 二进制文件。
|
||||
|
||||
响应为二进制流 (`Content-Type: application/octet-stream`)。
|
||||
|
||||
#### GET /agent/install.sh — 一键安装脚本
|
||||
|
||||
下载 Agent 一键安装脚本。
|
||||
|
||||
响应为 Shell 脚本文本 (`Content-Type: text/plain`)。
|
||||
Reference in new issue
Block a user