Files
im_server/docs/requirement/监控需求.md
T

36 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
**1. `/healthz`接口**
现在的健康检查(`nc -z localhost 6060`/`8000`)只能证明端口开着,测不出"连接池耗尽、死锁"这种进程还活着但已经不干活的情况。
要求:`GET /healthz`,不需要鉴权,正常200/异常503,body统一格式:
```json
{"status": "ok", "checks": {"mysql": "ok", "redis": "ok", "kafka": "ok"}}
```
异常时把出问题的依赖写清楚原因,其他正常的照样标ok:
```json
{"status": "error", "checks": {"mysql": "ok", "kafka": "timeout: dial tcp kafka:9092: i/o timeout"}}
```
各服务测什么:
- **im-server**:MySQL(唯一确认在用的外部依赖)。Redis代码里还没真正接入,先不用测
- **im-manager**:MySQL、Redis(`REDIS_DB=2`在用)、Kafka(崩溃日志能看到它真的在跑queue consumer,是真实依赖)
检测建议用真实操作确认能用(MySQL `SELECT 1`/`Ping()`,Redis `PING`,Kafka查broker元数据),不要只判断连接对象是不是nil。
顺手把两个服务Dockerfile里的`HEALTHCHECK`换成打这个接口,`deploy.sh`的探测逻辑也建议一起换。
---
**2. `/metrics`业务指标接口**(不急,可以往后放)
`im-server`加`GET /metrics`,标准Prometheus文本格式,Go生态直接用官方库`prometheus/client_golang/promhttp`,几行代码接完。
按价值排序,可以只做第一个:
| 指标 | 类型 | 说明 |
|---|---|---|
| `ws_connections_active` | Gauge | 当前WS连接数,**优先级最高**——直接对应之前"WS总掉线"那次排查,有曲线就不用再靠人工连测 |
| `http_requests_total{method,path,status}` | Counter | 按路径/状态码分的请求量,看5xx占比 |
| `http_request_duration_seconds` | Histogram | 接口延迟分布 |
| `db_query_duration_seconds` | Histogram | 数据库查询延迟 |