Niranjan12A/aisre-platform
GitHub: Niranjan12A/aisre-platform
一个将机器学习异常检测、统计容量预测与 LLM 事件分析整合在一起的端到端 SRE 平台,帮助运维团队更快诊断和响应基础设施事件。
Stars: 1 | Forks: 0
# AISRE 平台
**AI 驱动的站点可靠性工程,端到端。**
[](https://github.com/Niranjan12A/aisre-platform/actions/workflows/ci.yml)
[](LICENSE)
[](https://www.python.org/downloads/)
[](https://fastapi.tiangolo.com/)
[](https://www.anthropic.com/)
AISRE Platform 是一个统一、可自托管的 SRE 工具包,它将**基于机器学习的异常检测**、**统计容量预测**以及**基于 LLM 的事件副驾驶**结合到一个连贯的 pipeline 中——这正是现代 SRE/平台团队为了缩短事件发生时的诊断时间而真正会去构建的那种系统。它以四个独立的 FastAPI 微服务、一个轻量级仪表板、完整的可观测性(Prometheus + Grafana)以及面向生产的部署工具(Docker Compose、Kubernetes manifests 和 Helm chart)的形式发布——全部由 CI 提供支持。
## 目录
- [为什么做这个项目](#why-this-project)
- [架构](#architecture)
- [快速开始](#quick-start)
- [技术栈](#tech-stack)
- [服务](#services)
- [截图](#screenshots)
- [仓库结构](#repository-structure)
- [开发](#development)
- [部署](#deployment)
- [路线图](#roadmap)
- [贡献](#contributing)
- [许可证](#license)
## 为什么做这个项目
这个项目的存在是为了展示在日益重合的现代基础设施团队三大领域中的实际、端到端的能力:**DevOps/SRE、机器学习和应用 LLM 工程。**
- **异常检测** — 一个真实的 scikit-learn `IsolationForest` 模型,在生成的合成基础设施指标(CPU、内存、延迟、错误率、请求量)上进行训练,并带有标记的注入异常,最后通过强类型的 FastAPI 端点提供服务。
- **容量预测** — `statsmodels` Holt-Winters 指数平滑法预测未来的资源使用情况,并在容量耗尽/故障风险发生之前进行标记。
- **基于 LLM 的事件分析** — Anthropic Claude API(`claude-sonnet-5`)将告警、日志片段以及上述两个机器学习服务的输出关联起来,然后起草根因假设、确定优先级的修复步骤以及复盘报告——这种以前需要值班工程师花费 20 分钟才能完成的手工初筛工作。
- **可观测性** — 每个服务都暴露 Prometheus 指标;一个预配置的 Grafana 仪表板可以直接可视化异常率、预测风险标记和 pipeline 延迟。
- **面向生产的部署** — 提供用于本地/演示的 Docker Compose、原始 Kubernetes manifests 以及参数化的 Helm chart,因此相同的服务可以从笔记本电脑无缝过渡到集群,而无需重新设计架构。
- **切实运行的 CI** — GitHub Actions 会在每次推送/PR 时对每个服务进行 lint、测试和 Docker 构建。
- **优雅降级** — 当未配置 API 密钥时,基于 LLM 的服务会在功能完备的 `--mock` 模式下运行,因此任何人都可以克隆此仓库并查看整个 pipeline 的运行情况,而无需支付 API 访问费用。
## 架构
```
flowchart TB
Browser["Browser (dashboard)"] --> Orchestrator
subgraph Platform["AISRE Platform"]
Orchestrator["Orchestrator / Gateway :8000"]
Anomaly["Anomaly Detection :8001
scikit-learn IsolationForest"] Forecast["Forecasting :8002
statsmodels Holt-Winters"] Copilot["Incident Copilot :8003
Claude (claude-sonnet-5)"] end Orchestrator -->|1. predict| Anomaly Orchestrator -->|2. forecast| Forecast Orchestrator -->|3. analyze-incident| Copilot Copilot -.->|live mode| ClaudeAPI["Anthropic Claude API"] Anomaly & Forecast & Copilot & Orchestrator -->|/metrics| Prometheus[("Prometheus")] Prometheus --> Grafana["Grafana"] ``` 完整的系统设计、时序图以及设计决策的基本原理位于 [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) 中。 ## 快速开始 只需不到 5 条命令即可在本地运行整个技术栈: ``` git clone https://github.com/Niranjan12A/aisre-platform.git cd aisre-platform cp .env.example .env # optional: add ANTHROPIC_API_KEY for live LLM analysis make up # docker compose up --build -d open http://localhost:8000 ``` 大功告成——仪表板、所有四个服务、Prometheus 和 Grafana 现已运行。请参阅 [`docs/DEMO.md`](docs/DEMO.md) 获取包含截图建议的完整引导式演练。 要在新生成的合成数据上训练真实模型(否则异常检测服务会使用一个小型的启发式回退机制,以便在开箱即用时依然能正常工作): ``` make train ``` | URL | 内容 | |---|---| | http://localhost:8000 | 仪表板 — 触发演示事件场景 | | http://localhost:8001/docs | 异常检测 API 文档 | | http://localhost:8002/docs | 预测 API 文档 | | http://localhost:8003/docs | 事件副驾驶 API 文档 | | http://localhost:9090 | Prometheus | | http://localhost:3000 | Grafana (`admin` / `admin`) | ## 技术栈 | 层级 | 技术 | |---|---| | API 框架 | [FastAPI](https://fastapi.tiangolo.com/)(全部四个服务),[Pydantic v2](https://docs.pydantic.dev/) | | 异常检测 | [scikit-learn](https://scikit-learn.org/) `IsolationForest`,`pandas`,`numpy` | | 预测 | [statsmodels](https://www.statsmodels.org/) Holt-Winters 指数平滑法 | | LLM 事件分析 | [Anthropic Claude API](https://www.anthropic.com/)(`anthropic` Python SDK),模型 `claude-sonnet-5` | | 服务间 HTTP | [httpx](https://www.python-httpx.org/)(异步) | | 可观测性 | [prometheus-client](https://github.com/prometheus/client_python),[Prometheus](https://prometheus.io/),[Grafana](https://grafana.com/) | | 仪表板前端 | 原生 HTML/CSS/vanilla JS — 无构建步骤,无外部 CDN 依赖 | | 容器化 | Docker,Docker Compose | | 编排 | Kubernetes(原始 manifests),[Helm](https://helm.sh/) | | CI/CD | GitHub Actions(lint、测试、Docker 构建验证、Helm lint) | | Linting | [ruff](https://docs.astral.sh/ruff/) | | 测试 | [pytest](https://docs.pytest.org/),FastAPI `TestClient`,[respx](https://lundberg.github.io/respx/)(HTTP 模拟) | ## 服务 ### 1. 异常检测 (`services/anomaly-detection`, 端口 8001) 在合成的时间序列基础设施指标(CPU、内存、延迟、错误率、请求量)上训练并提供 scikit-learn `IsolationForest` 模型服务,其中包含真实注入的异常(峰值、漂移、平线、多指标关联事件)。 - `POST /predict` — 对一个或多个指标时间窗口进行评分,返回每个窗口的异常分数、判定结果以及促成异常的指标 - `GET /health` - `GET /metrics` — Prometheus 格式 ``` python scripts/generate_synthetic_data.py --out data/synthetic_metrics.csv python scripts/train_model.py --data data/synthetic_metrics.csv --out models/isolation_forest.joblib ``` ### 2. 预测 (`services/forecasting`, 端口 8002) 对提供的合成资源使用历史数据拟合 Holt-Winters 指数平滑模型,以预测未来值并在可配置的时间范围内标记容量耗尽/故障风险。 - `POST /forecast` — 给定指标历史数据,返回带有置信区间的预测值、风险标记以及预计突破阈值的步数 - `GET /health` - `GET /metrics` — Prometheus 格式 ### 3. 事件副驾驶 (`services/incident-copilot`, 端口 8003) 使用 Anthropic Claude API(模型 `claude-sonnet-5`)接收模拟告警、日志片段以及异常检测和预测服务的输出,然后将它们关联起来,总结可能的根因,建议优先执行的 runbook 修复步骤,并起草复盘报告。 - `POST /analyze-incident` — 完整的事件关联 + 基于 Claude 的分析 - `GET /health` — 报告服务是在 `live` 还是 `mock` 模式下运行 **需要 `ANTHROPIC_API_KEY` 才能在线运行。** 如果未设置密钥(或使用了 `--mock` / `?mock=true` / `COPILOT_MOCK_MODE=true`),服务将回退到确定的、明确标记的模拟响应,因此无需付费的 API 密钥即可完全演示平台的其余部分: ``` python scripts/demo_analyze.py --mock ``` ### 4. Orchestrator / 网关 (`services/orchestrator`, 端口 8000) 将上述三个服务整合为一个 pipeline,并为仪表板提供服务。 - `GET /api/scenarios` — 列出内置的合成演示场景 - `POST /api/run-scenario` — 为选定场景运行完整的 异常 -> 预测 -> 副驾驶 pipeline,并返回统一的 JSON 响应 - `GET /health`,`GET /metrics` - `GET /` — 提供静态仪表板服务(HTML/CSS/vanilla JS,支持暗黑模式,无外部 CDN 依赖) ## 截图 ## 仓库结构 ``` aisre-platform/ docs/ Architecture docs + demo script services/ anomaly-detection/ FastAPI + scikit-learn IsolationForest forecasting/ FastAPI + statsmodels Holt-Winters incident-copilot/ FastAPI + Anthropic Claude (claude-sonnet-5) orchestrator/ FastAPI gateway + static dashboard infra/ prometheus/ Prometheus scrape config grafana/ Provisioned datasource + dashboard JSON k8s/ Raw Kubernetes manifests helm/aisre-platform/ Helm chart .github/ workflows/ci.yml Lint + test + Docker build validation ISSUE_TEMPLATE/, PULL_REQUEST_TEMPLATE.md docker-compose.yml Makefile .env.example ``` `services/` 下的每个服务都遵循相同的内部布局: `app/`(FastAPI 应用程序代码),`scripts/`(合成数据生成 + 训练),`tests/`(pytest 测试套件),`Dockerfile`,`requirements.txt`。 ## 开发 ``` make setup # create a venv + install deps for every service make train # generate synthetic data and train the ML models make test # run pytest for every service make lint # run ruff for every service make up # docker compose up --build -d make down # docker compose down make demo # run the incident-copilot demo script in mock mode ``` 或者直接在单个服务上进行开发: ``` cd services/anomaly-detection python3.12 -m venv .venv && source .venv/bin/activate pip install -r requirements.txt pytest -v uvicorn app.main:app --reload --port 8001 ``` ## 部署 ### Docker Compose(本地 / 演示) ``` make up ``` ### Kubernetes(原始 manifests) ``` kubectl apply -f infra/k8s/ ``` ### Kubernetes (Helm) ``` helm install aisre-platform infra/helm/aisre-platform \ --namespace aisre-platform --create-namespace # 要启用实时 incident 分析,请首先创建 secret: kubectl create secret generic aisre-anthropic-secret \ --namespace aisre-platform \ --from-literal=ANTHROPIC_API_KEY=sk-ant-... ``` 有关所有可配置参数(image registry、副本数量、资源限制、Ingress),请参阅 `infra/helm/aisre-platform/values.yaml`。 ## 路线图 - [ ] 添加用于海量指标摄入的 `/predict/batch` 流式端点 - [ ] 扩展异常检测模型以支持基于服务的模型注册表 - [ ] 添加 SARIMA / Prophet 作为可选的预测后端,与 Holt-Winters 并存 - [ ] 持久化场景运行历史并在仪表板中展示 - [ ] 在 orchestrator pipeline 中添加 OpenTelemetry 链路追踪 - [ ] 添加真实的告警集成(PagerDuty/Opsgenie webhook 模拟) - [ ] 在 CI 中将预构建的 Docker 镜像发布到 GHCR 以用于标记的发布版本 - [ ] 为多租户部署模式添加身份验证/RBAC ## 贡献 欢迎贡献、提 issue 和功能请求。请参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 了解设置说明、代码风格以及合成数据策略(永远不使用真实的基础设施/客户数据)。 ## 许可证 基于 [MIT License](LICENSE) 授权。
scikit-learn IsolationForest"] Forecast["Forecasting :8002
statsmodels Holt-Winters"] Copilot["Incident Copilot :8003
Claude (claude-sonnet-5)"] end Orchestrator -->|1. predict| Anomaly Orchestrator -->|2. forecast| Forecast Orchestrator -->|3. analyze-incident| Copilot Copilot -.->|live mode| ClaudeAPI["Anthropic Claude API"] Anomaly & Forecast & Copilot & Orchestrator -->|/metrics| Prometheus[("Prometheus")] Prometheus --> Grafana["Grafana"] ``` 完整的系统设计、时序图以及设计决策的基本原理位于 [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) 中。 ## 快速开始 只需不到 5 条命令即可在本地运行整个技术栈: ``` git clone https://github.com/Niranjan12A/aisre-platform.git cd aisre-platform cp .env.example .env # optional: add ANTHROPIC_API_KEY for live LLM analysis make up # docker compose up --build -d open http://localhost:8000 ``` 大功告成——仪表板、所有四个服务、Prometheus 和 Grafana 现已运行。请参阅 [`docs/DEMO.md`](docs/DEMO.md) 获取包含截图建议的完整引导式演练。 要在新生成的合成数据上训练真实模型(否则异常检测服务会使用一个小型的启发式回退机制,以便在开箱即用时依然能正常工作): ``` make train ``` | URL | 内容 | |---|---| | http://localhost:8000 | 仪表板 — 触发演示事件场景 | | http://localhost:8001/docs | 异常检测 API 文档 | | http://localhost:8002/docs | 预测 API 文档 | | http://localhost:8003/docs | 事件副驾驶 API 文档 | | http://localhost:9090 | Prometheus | | http://localhost:3000 | Grafana (`admin` / `admin`) | ## 技术栈 | 层级 | 技术 | |---|---| | API 框架 | [FastAPI](https://fastapi.tiangolo.com/)(全部四个服务),[Pydantic v2](https://docs.pydantic.dev/) | | 异常检测 | [scikit-learn](https://scikit-learn.org/) `IsolationForest`,`pandas`,`numpy` | | 预测 | [statsmodels](https://www.statsmodels.org/) Holt-Winters 指数平滑法 | | LLM 事件分析 | [Anthropic Claude API](https://www.anthropic.com/)(`anthropic` Python SDK),模型 `claude-sonnet-5` | | 服务间 HTTP | [httpx](https://www.python-httpx.org/)(异步) | | 可观测性 | [prometheus-client](https://github.com/prometheus/client_python),[Prometheus](https://prometheus.io/),[Grafana](https://grafana.com/) | | 仪表板前端 | 原生 HTML/CSS/vanilla JS — 无构建步骤,无外部 CDN 依赖 | | 容器化 | Docker,Docker Compose | | 编排 | Kubernetes(原始 manifests),[Helm](https://helm.sh/) | | CI/CD | GitHub Actions(lint、测试、Docker 构建验证、Helm lint) | | Linting | [ruff](https://docs.astral.sh/ruff/) | | 测试 | [pytest](https://docs.pytest.org/),FastAPI `TestClient`,[respx](https://lundberg.github.io/respx/)(HTTP 模拟) | ## 服务 ### 1. 异常检测 (`services/anomaly-detection`, 端口 8001) 在合成的时间序列基础设施指标(CPU、内存、延迟、错误率、请求量)上训练并提供 scikit-learn `IsolationForest` 模型服务,其中包含真实注入的异常(峰值、漂移、平线、多指标关联事件)。 - `POST /predict` — 对一个或多个指标时间窗口进行评分,返回每个窗口的异常分数、判定结果以及促成异常的指标 - `GET /health` - `GET /metrics` — Prometheus 格式 ``` python scripts/generate_synthetic_data.py --out data/synthetic_metrics.csv python scripts/train_model.py --data data/synthetic_metrics.csv --out models/isolation_forest.joblib ``` ### 2. 预测 (`services/forecasting`, 端口 8002) 对提供的合成资源使用历史数据拟合 Holt-Winters 指数平滑模型,以预测未来值并在可配置的时间范围内标记容量耗尽/故障风险。 - `POST /forecast` — 给定指标历史数据,返回带有置信区间的预测值、风险标记以及预计突破阈值的步数 - `GET /health` - `GET /metrics` — Prometheus 格式 ### 3. 事件副驾驶 (`services/incident-copilot`, 端口 8003) 使用 Anthropic Claude API(模型 `claude-sonnet-5`)接收模拟告警、日志片段以及异常检测和预测服务的输出,然后将它们关联起来,总结可能的根因,建议优先执行的 runbook 修复步骤,并起草复盘报告。 - `POST /analyze-incident` — 完整的事件关联 + 基于 Claude 的分析 - `GET /health` — 报告服务是在 `live` 还是 `mock` 模式下运行 **需要 `ANTHROPIC_API_KEY` 才能在线运行。** 如果未设置密钥(或使用了 `--mock` / `?mock=true` / `COPILOT_MOCK_MODE=true`),服务将回退到确定的、明确标记的模拟响应,因此无需付费的 API 密钥即可完全演示平台的其余部分: ``` python scripts/demo_analyze.py --mock ``` ### 4. Orchestrator / 网关 (`services/orchestrator`, 端口 8000) 将上述三个服务整合为一个 pipeline,并为仪表板提供服务。 - `GET /api/scenarios` — 列出内置的合成演示场景 - `POST /api/run-scenario` — 为选定场景运行完整的 异常 -> 预测 -> 副驾驶 pipeline,并返回统一的 JSON 响应 - `GET /health`,`GET /metrics` - `GET /` — 提供静态仪表板服务(HTML/CSS/vanilla JS,支持暗黑模式,无外部 CDN 依赖) ## 截图 ## 仓库结构 ``` aisre-platform/ docs/ Architecture docs + demo script services/ anomaly-detection/ FastAPI + scikit-learn IsolationForest forecasting/ FastAPI + statsmodels Holt-Winters incident-copilot/ FastAPI + Anthropic Claude (claude-sonnet-5) orchestrator/ FastAPI gateway + static dashboard infra/ prometheus/ Prometheus scrape config grafana/ Provisioned datasource + dashboard JSON k8s/ Raw Kubernetes manifests helm/aisre-platform/ Helm chart .github/ workflows/ci.yml Lint + test + Docker build validation ISSUE_TEMPLATE/, PULL_REQUEST_TEMPLATE.md docker-compose.yml Makefile .env.example ``` `services/` 下的每个服务都遵循相同的内部布局: `app/`(FastAPI 应用程序代码),`scripts/`(合成数据生成 + 训练),`tests/`(pytest 测试套件),`Dockerfile`,`requirements.txt`。 ## 开发 ``` make setup # create a venv + install deps for every service make train # generate synthetic data and train the ML models make test # run pytest for every service make lint # run ruff for every service make up # docker compose up --build -d make down # docker compose down make demo # run the incident-copilot demo script in mock mode ``` 或者直接在单个服务上进行开发: ``` cd services/anomaly-detection python3.12 -m venv .venv && source .venv/bin/activate pip install -r requirements.txt pytest -v uvicorn app.main:app --reload --port 8001 ``` ## 部署 ### Docker Compose(本地 / 演示) ``` make up ``` ### Kubernetes(原始 manifests) ``` kubectl apply -f infra/k8s/ ``` ### Kubernetes (Helm) ``` helm install aisre-platform infra/helm/aisre-platform \ --namespace aisre-platform --create-namespace # 要启用实时 incident 分析,请首先创建 secret: kubectl create secret generic aisre-anthropic-secret \ --namespace aisre-platform \ --from-literal=ANTHROPIC_API_KEY=sk-ant-... ``` 有关所有可配置参数(image registry、副本数量、资源限制、Ingress),请参阅 `infra/helm/aisre-platform/values.yaml`。 ## 路线图 - [ ] 添加用于海量指标摄入的 `/predict/batch` 流式端点 - [ ] 扩展异常检测模型以支持基于服务的模型注册表 - [ ] 添加 SARIMA / Prophet 作为可选的预测后端,与 Holt-Winters 并存 - [ ] 持久化场景运行历史并在仪表板中展示 - [ ] 在 orchestrator pipeline 中添加 OpenTelemetry 链路追踪 - [ ] 添加真实的告警集成(PagerDuty/Opsgenie webhook 模拟) - [ ] 在 CI 中将预构建的 Docker 镜像发布到 GHCR 以用于标记的发布版本 - [ ] 为多租户部署模式添加身份验证/RBAC ## 贡献 欢迎贡献、提 issue 和功能请求。请参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 了解设置说明、代码风格以及合成数据策略(永远不使用真实的基础设施/客户数据)。 ## 许可证 基于 [MIT License](LICENSE) 授权。
标签:AIOps, API集成, AV绕过, FastAPI, LLM, SRE, Unmanaged PE, 偏差过滤, 可观测性, 子域名突变, 安全规则引擎, 异常检测, 版权保护, 自定义请求头, 请求拦截, 运维, 运行时操纵