Vijay-kumar2006/Monitoring-and-Incident-Response

GitHub: Vijay-kumar2006/Monitoring-and-Incident-Response

一个容器化的可观测性技术栈演示项目,集成分布式追踪、指标监控与告警,帮助开发者快速验证监控告警流程。

Stars: 0 | Forks: 0

# 分布式追踪与可观测性技术栈 本仓库包含一个容器化的 Node.js 应用,该应用集成了 **OpenTelemetry(分布式追踪)** 和 **Prometheus(指标/告警)**。整个技术栈完全运行在 Docker 中,并集成了 Jaeger、Prometheus、Alertmanager 和 Grafana。 ## 🛠 技术栈 * **运行时:** Node.js (Express) * **结构化日志:** Winston (JSON 格式) * **分布式追踪:** OpenTelemetry Node SDK, Auto-instrumentation, Jaeger Exporter * **指标引擎:** Prometheus & `prom-client` * **告警路由:** Alertmanager * **可视化:** Grafana(包含自动配置的仪表盘) * **编排:** Docker Compose ## 🚀 如何运行该技术栈 1. **启动 Docker Desktop:** 确保您的机器上正在运行 Docker Desktop。 2. **启动技术栈:** 在本项目的根目录下,运行: docker compose up --build 此命令将构建 Node.js 应用程序并在前台启动所有服务。您将看到来自 app 容器的 Winston 日志输出。 ## 🔗 可访问的端点与服务 | 服务 | 端口 / URL | 描述 | | :--- | :--- | :--- | | **Node.js App** | [http://localhost:3000](http://localhost:3000) | Express 应用程序入口 | | **Jaeger UI** | [http://localhost:16686](http://localhost:16686) | 查看分布式追踪和 span | | **Prometheus UI** | [http://localhost:9090](http://localhost:9090) | 查询指标并查看活动的告警规则 | | **Alertmanager UI** | [http://localhost:9093](http://localhost:9093) | 查看已触发/已静默的告警 | | **Grafana UI** | [http://localhost:3001](http://localhost:3001) | 主可视化仪表盘(自动配置,无需登录) | ## ⚙️ 应用程序端点与测试 ### 1. 生成分布式追踪 (任务 1) 要生成分布式追踪,请调用复杂操作路由: ``` curl "http://localhost:3000/complex-operation?key=my_custom_key" ``` * **工作原理:** 此端点按顺序执行 3 个内部函数(`validateInput`、`fetchDataFromCache` 和 `computeHeavyResult`)。 * **验证:** 打开 **Jaeger UI** (http://localhost:16686)。从 Service 下拉菜单中选择 **`orders-service`**,然后点击 **Find Traces**。您将看到包含 3 个按顺序嵌套的手动埋点子 span 的主请求 trace。 ### 2. 模拟高错误率与告警 (任务 2) 要触发错误率告警(在 1 分钟的时间窗口内错误率 > 2%): 1. 为应用程序生成一些后台流量: # 多次运行或在循环中运行 curl "http://localhost:3000/complex-operation?key=bg_traffic" 2. 通过请求 `/fail` 端点来触发错误: # 频繁请求此端点以生成 HTTP 500 错误 curl "http://localhost:3000/fail" 3. **验证:** * **Winston 日志:** 您将看到应用程序控制台为每次失败输出 JSON 格式的 stack trace。 * **Grafana:** 打开 [http://localhost:3001](http://localhost:3001) 处的仪表盘。您将看到 **Current Error Rate Status** 面板在超过 2% 的阈值时变为红色。 * **Alertmanager:** `HighErrorRate` 告警将被触发,并从 `PENDING` 状态转换为 `FIRING`(可在 http://localhost:9093 查看)。 * **Webhook 日志:** Alertmanager 将向应用程序的 `/alerts` 端点发送一个 webhook payload,该端点将在您的终端日志中以结构化 JSON 打印告警详情。 ## 📖 相关文档 * [analysis.md](file:///C:/Users/Vijay%20Kumar/.gemini/antigravity/scratch/Monitoring-and-Incident-Response/analysis.md):一篇 200 字的对比分析,比较了指标与追踪。 * [runbook.md](file:///C:/Users/Vijay%20Kumar/.gemini/antigravity/scratch/Monitoring-and-Incident-Response/runbook.md):详细的事件响应计划,说明了告警规则、3 种故障模式和缓解步骤。
标签:API集成, Docker Compose, GNU通用公共许可证, Grafana, MITM代理, Node.js, 可观测性, 版权保护, 用户代理, 自定义脚本, 自定义请求头, 链路追踪