Initialize observability stack with local monitoring and server134 deployment
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
# Windows 本地冒烟与 new-api 状态监控
|
||||
|
||||
第一次使用 Grafana,请阅读 [Grafana 中文使用手册](../../docs/Grafana使用手册-本地new-api监控.md),包含登录、切换中文、看板解读、指标/日志/链路查询和告警查看。
|
||||
|
||||
接入本机 MySQL 请阅读 [MySQL 采集器配置步骤](README.mysql.md)。该服务为可选项;创建工作区外的 `mysql-exporter.cnf` 后,启动脚本会启用它,并将 MySQL 检查加入完整冒烟。
|
||||
|
||||
适用于本工作机的 Docker Desktop(Linux containers)和已启动的 `http://127.0.0.1:3000` 应用。
|
||||
入口使用独立 Compose 项目 `observability-local`,全部发布端口绑定 `127.0.0.1`。
|
||||
Grafana 使用 **3001**,避免与应用的 3000 冲突;此入口不运行 Linux node_exporter。
|
||||
|
||||
## 启动、复测、停止
|
||||
|
||||
在项目根目录执行(需要 Python 3、Docker Desktop、Compose 2.24.4 或更新版本):
|
||||
|
||||
```powershell
|
||||
cd D:\project\weiyuan-observability
|
||||
docker desktop start
|
||||
py -3 deploy/monitoring/scripts/local.py check
|
||||
py -3 deploy/monitoring/scripts/local.py up
|
||||
py -3 deploy/monitoring/scripts/local.py smoke
|
||||
```
|
||||
|
||||
`up` 会读取合并后的 Compose 配置,检查全部发布端口的实际 TCP bind 及 Docker 映射归属。
|
||||
冲突会在拉取镜像或修改容器前报错退出,允许本项目对应服务原有的相同端口。
|
||||
端口检查与启动之间仍存在竞争窗口,Docker 启动失败时应按错误排查,不要终止未知进程。
|
||||
首次启动 Grafana 需下载约 78 MB 的日志数据源插件;镜像拉取完成不等于界面就绪。`smoke` 最长等待 Grafana 10 分钟,超时后查看 `logs` 中的下载错误。
|
||||
|
||||
```powershell
|
||||
py -3 deploy/monitoring/scripts/local.py ps
|
||||
py -3 deploy/monitoring/scripts/local.py logs
|
||||
py -3 deploy/monitoring/scripts/local.py down
|
||||
```
|
||||
|
||||
`down` 停止本地监控项目并保留命名卷。下次执行 `up` 恢复;不要加 `-v`。
|
||||
Docker Desktop 关闭时监控也会暂停。
|
||||
|
||||
## 打开看板
|
||||
|
||||
- Grafana:<http://127.0.0.1:3001/d/new-api-local>
|
||||
- Alertmanager:<http://127.0.0.1:9093>
|
||||
- vmagent 采集状态:<http://127.0.0.1:8429/targets>
|
||||
|
||||
Grafana 用户名:`admin`。随机密码保存在工作区外:
|
||||
|
||||
```powershell
|
||||
Get-Content "$env:LOCALAPPDATA\weiyuan-observability\grafana-admin-password.txt"
|
||||
```
|
||||
|
||||
不要把输出复制进聊天、源码或交接文件。密码由 Compose secret 挂载,不写入本工作区的 `.env`。
|
||||
如果之后在 Grafana 中更改了密码,需要同步更新外部文件,才能继续运行登录与数据源检查;不要删除数据卷来重置密码。
|
||||
|
||||
## 本阶段监控范围
|
||||
|
||||
每 15 秒从容器内访问 `http://host.docker.internal:3000/api/status`,要求 HTTP 200 且返回体包含 `"success": true`。
|
||||
看板显示状态接口可用性、HTTP 状态码和请求耗时。连续失败 2 分钟触发 `NewApiUnavailable`;采集失败 2 分钟触发 `LocalMonitoringTargetDown`。
|
||||
默认 Alertmanager 只在本地显示告警,没有对外通知。
|
||||
|
||||
这些指标**不能代表模型调用成功率、推理延迟、计费或真实用户流量**。
|
||||
应用业务 Metrics、应用日志及业务 Traces 尚未接入;Logs/Traces 当前只有冒烟脚本写入的合成数据。
|
||||
下一步应基于实际运行分支导出既有 `service/monitor` 数据,复用其结果分类,不能把 `master` 与 `weiyuan` 混为一谈。
|
||||
|
||||
修改目标地址:编辑 `config/local/prometheus.yml` 中的 `targets`,再执行:
|
||||
|
||||
```powershell
|
||||
# 只重启监控采集器,使修改后的配置生效。
|
||||
docker restart observability-local-vmagent-1
|
||||
py -3 deploy/monitoring/scripts/local.py smoke
|
||||
```
|
||||
|
||||
`host.docker.internal` 指向 Windows 宿主机。容器中的 `127.0.0.1` 指向容器自身。
|
||||
只有应用允许 Docker Desktop 访问时探测才会成功;不要为解决连通性随意关闭防火墙。
|
||||
|
||||
## 验证内容
|
||||
|
||||
`smoke` 先等待组件就绪,再完成以下实际读写:
|
||||
|
||||
1. 写入带本轮标识的 Prometheus 样本,轮询查询值为 1。
|
||||
2. 写入合成日志,根据唯一 trace_id 查回本轮消息。
|
||||
3. 经 OTLP HTTP 写入合成 span,再用精确 trace ID 查回本轮 span。
|
||||
4. 检查应用探测成功、HTTP 200、全部配置的采集目标正常。
|
||||
5. 使用外部密码验证 Grafana 三个数据源与预置应用看板。
|
||||
|
||||
最后应输出 `Local stack, application probe and Grafana checks all passed.`。
|
||||
这不等于业务链路接入、外部通知或跨组件跳转已经验收。当前未主动停止用户应用测试告警恢复。
|
||||
|
||||
2026-10-15 本机已完整通过以上检查:8 个监控容器运行,9 个采集目标正常,应用探测为 1、HTTP 状态为 200,3 个 Grafana 数据源正常。首次日志插件下载约耗时 8 分钟;之后插件保存在 Grafana 数据卷中。
|
||||
下载期间的 Grafana 采集失败告警已进入 Alertmanager,并在服务就绪后自动恢复;最终没有活动告警。
|
||||
|
||||
端口预检回归测试:
|
||||
|
||||
```powershell
|
||||
py -3 deploy/monitoring/tests/test_local_ports.py
|
||||
```
|
||||
|
||||
## 与 Ubuntu 部署的区别
|
||||
|
||||
本地入口合并 `docker-compose.yml` 与 `docker-compose.local.yml`,使用 Docker 命名卷和独立网络。
|
||||
Ubuntu 仍按 `README.md` 部署,使用原来的绑定目录与主机监控配置。
|
||||
共同修复:Tempo 3.0.3 使用 `overrides.defaults.compaction.block_retention` 设置保留期,已移除 2.x 的 `ingester/compactor` 字段;Grafana 在启动前同步安装固定版本日志插件。
|
||||
Ubuntu 冒烟入口也调用 `scripts/smoke.py`,不再依赖 telemetrygen 镜像。
|
||||
|
||||
迁移到另一台电脑时复制工作区,重新运行 `up` 会生成新的本机密码和空数据卷。
|
||||
工作区副本不包含 Docker 卷数据或外部密码;如需保留历史,需另行备份迁移。
|
||||
Reference in New Issue
Block a user