feat(monitor): M15 中间件监控 — Redis/MySQL 后端直连采集引擎
后端: - 新增 controller/middleware_monitor.go (500+ 行) — CRUD + 测试连接 + 采集引擎 - 后台 goroutine 每 30s 自动连接 Redis/MySQL 采集指标 - Redis: go-redis v9 INFO+DBSIZE 命令采集 12 项指标 - MySQL: database/sql SHOW GLOBAL STATUS 采集 12 项指标 - 指标写入 MetricHistory 表,7 天自动清理 - 8 个 RESTful 路由注册到 routes.go 前端: - MiddlewareMonitor.tsx 从只读卡片升级为完整管理页面 - 添加监控弹框(Redis/MySQL 类型选择+连接配置表单) - 实例卡片操作栏(测试/编辑/删除) + 工具栏(立即采集/刷新) - middlewareMonitorApi 8 个方法 验证: go build✅ npm build✅ 17/17 回归通过 Redis 12 指标✅ MySQL 12 指标✅
This commit is contained in:
1 parent
186ece6495
commit
ed7a5c07a7
8 files changed
+1211
-132
No files matched your search
+69
@@ -967,3 +967,72 @@ python3 tests/integration_test.py --host 127.0.0.1 --port 8080 | tail -3
|
||||
- [x] U6: 17/17 集成回归测试通过
|
||||
- [x] 引擎无 panic(无效 datasource_id 优雅跳过)
|
||||
- [x] 日志数据源支持 none/basic/bearer/custom 四种认证方式(round-trip 验证)
|
||||
|
||||
---
|
||||
|
||||
## M15: 中间件监控 (Redis/MySQL)
|
||||
|
||||
### 验证用例
|
||||
|
||||
```bash
|
||||
TOKEN=$(python3 -c "
|
||||
import urllib.request, json
|
||||
login_data = json.dumps({'username': 'admin', 'password': '123456'}).encode()
|
||||
req = urllib.request.Request('http://127.0.0.1:8080/api/v1/auth/login', data=login_data, method='POST')
|
||||
req.add_header('Content-Type', 'application/json')
|
||||
resp = urllib.request.urlopen(req)
|
||||
print(json.loads(resp.read())['data']['token'])
|
||||
")
|
||||
|
||||
# U1: 创建 Redis 监控目标
|
||||
curl -s -X POST http://127.0.0.1:8080/api/v1/middleware-monitors \
|
||||
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
|
||||
-d '{"name":"平台Redis","type":"redis","ip":"aiops-redis","port":6379}' | python3 -c "import json,sys; d=json.load(sys.stdin); assert d['code']==200; print('✅ create redis')"
|
||||
# 期望: code=200
|
||||
|
||||
# U2: 创建 MySQL 监控目标
|
||||
curl -s -X POST http://127.0.0.1:8080/api/v1/middleware-monitors \
|
||||
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
|
||||
-d '{"name":"平台MySQL","type":"mysql","ip":"aiops-mysql","port":3306,"username":"root","password":"xxx","database":"aiops"}' | python3 -c "import json,sys; d=json.load(sys.stdin); assert d['code']==200; print('✅ create mysql')"
|
||||
# 期望: code=200
|
||||
|
||||
# U3: 列表
|
||||
curl -s http://127.0.0.1:8080/api/v1/middleware-monitors -H "Authorization: Bearer $TOKEN" | python3 -c "import json,sys; d=json.load(sys.stdin); assert d['data']['total']>=2; print(f'✅ list: {d[\"data\"][\"total\"]} targets')"
|
||||
# 期望: total >= 2
|
||||
|
||||
# U4: 测试 Redis 连接(采集指标)
|
||||
curl -s -X POST http://127.0.0.1:8080/api/v1/middleware-monitors/REDIS_ID/test -H "Authorization: Bearer $TOKEN" | python3 -c "import json,sys; d=json.load(sys.stdin); assert d['data']['success']==True; print(f'✅ redis test: {len(d[\"data\"][\"metrics\"])} metrics')"
|
||||
# 期望: success=true, 12 metrics
|
||||
|
||||
# U5: 立即采集
|
||||
curl -s -X POST http://127.0.0.1:8080/api/v1/middleware-monitors/collect -H "Authorization: Bearer $TOKEN" | python3 -c "import json,sys; d=json.load(sys.stdin); assert d['data']['collected']>=1; print(f'✅ collect: {d[\"data\"][\"collected\"]} targets')"
|
||||
# 期望: collected >= 1
|
||||
|
||||
# U6: 指标历史
|
||||
curl -s "http://127.0.0.1:8080/api/v1/middleware-monitors/REDIS_ID/metrics" -H "Authorization: Bearer $TOKEN" | python3 -c "import json,sys; d=json.load(sys.stdin); assert d['data']['total']>0; print(f'✅ history: {d[\"data\"][\"total\"]} records')"
|
||||
# 期望: records > 0
|
||||
|
||||
# U7: 前端 middlewareMonitorApi 8 个方法
|
||||
grep -c 'http\.\(get\|post\|put\|delete\)' /srv/aiops/frontend/src/api/monitor/metrics.ts
|
||||
# 期望: >= 8
|
||||
|
||||
# U8: go build
|
||||
cd /srv/aiops/backend && go build ./...
|
||||
# 期望: 零错误
|
||||
|
||||
# U9: npm build
|
||||
cd /srv/aiops/frontend && npm run build
|
||||
# 期望: 零错误
|
||||
```
|
||||
|
||||
### 通过标准
|
||||
- [x] U1: 创建 Redis 监控目标返回 200
|
||||
- [x] U2: 创建 MySQL 监控目标返回 200
|
||||
- [x] U3: 列表返回 >= 2 个目标
|
||||
- [x] U4: Redis 连接测试成功(12 项指标:连接数/内存/命中率/QPS/Key总数等)
|
||||
- [x] U5: 立即采集成功(collected >= 1)
|
||||
- [x] U6: 指标历史有记录
|
||||
- [x] U7: 前端 API 屄 8 个方法
|
||||
- [x] U8: `go build` 零错误
|
||||
- [x] U9: `npm run build` 零错误(✓ built in 19.08s)
|
||||
- [x] 17/17 集成回归测试通过(零回归)
|
||||
Reference in new issue
Block a user