Donhadley22/incident-response-platform
GitHub: Donhadley22/incident-response-platform
一个基于 Docker Compose 的七服务事件响应平台,帮助 DevOps 团队模拟生产级运维事件管理工作流。
Stars: 0 | Forks: 0
# 事件响应平台







一个包含七个服务的 Docker Compose 应用程序,为 DevOps、SRE 和平台工程团队模拟了生产级别的事件响应工作流。

## 概述
本项目演示了如何使用 Docker Compose 运行一个小巧但贴近实际的运维平台。它包括基于浏览器的事件控制台、FastAPI 后端、异步后台处理、持久化存储、缓存、反向代理路由、健康检查以及 Prometheus 指标。
该平台可帮助团队捕获和管理各种运维事件,例如 API 延迟、部署失败、服务中断和数据库问题。
## 架构

```
Browser
-> Nginx edge service
-> Frontend web UI
-> FastAPI backend
-> PostgreSQL
-> Redis
-> Worker
-> Prometheus metrics endpoint
```
## 服务
| 服务 | 技术 | 用途 |
| --- | --- | --- |
| `edge` | Nginx | 运行在端口 `8081` 上的公共反向代理;负责路由 UI 和 API 流量。 |
| `frontend` | Nginx 静态站点 | 用于创建、确认和解决事件的浏览器 UI。 |
| `api` | FastAPI | 验证请求、存储事件,并提供健康检查和指标。 |
| `worker` | Python | 异步处理排队的事件任务。 |
| `postgres` | PostgreSQL 16 | 存储持久化的事件记录。 |
| `redis` | Redis 7 | 提供短期缓存和后台任务队列。 |
| `prometheus` | Prometheus | 抓取 API 指标以实现可观测性。 |
## 功能
- 包含七个服务的 Docker Compose 技术栈
- 通过 Nginx 提供单一的公共应用程序入口
- 带有自动 Swagger 文档的 FastAPI 后端
- 使用 Docker volumes 实现的 PostgreSQL 持久化
- 基于 Redis 的缓存和后台队列
- 用于异步事件处理的 worker 服务
- 兼容 Prometheus 的指标 endpoint
- 针对 API、PostgreSQL 和 Redis 的健康检查
- 用于服务间通信的私有 Docker 网络
- 适配 GitHub 的文档和 Dev.to 文章草稿
## 快速开始
克隆代码库:
```
git clone https://github.com/Donhadley22/incident-response-platform.git
cd incident-response-platform
```
创建本地环境文件:
```
cp .env.example .env
```
在 Windows PowerShell 中:
```
Copy-Item .env.example .env
```
启动技术栈:
```
docker compose up --build
```
打开应用程序:
| URL | 用途 |
| --- | --- |
| http://localhost:8081 | 事件响应 Web UI |
| http://localhost:8081/api/health | API 健康检查 |
| http://localhost:8081/api/docs | FastAPI Swagger 文档 |
| http://localhost:9090 | Prometheus |
## 常用命令
在后台分离模式下运行:
```
docker compose up -d --build
```
列出服务:
```
docker compose ps
```
查看所有日志:
```
docker compose logs -f
```
查看 API 日志:
```
docker compose logs -f api
```
查看 worker 日志:
```
docker compose logs -f worker
```
停止技术栈:
```
docker compose down
```
停止技术栈并移除本地 volumes:
```
docker compose down -v
```
## API Endpoints
| 方法 | Endpoint | 描述 |
| --- | --- | --- |
| `GET` | `/api/health` | 返回 API 健康状态。 |
| `GET` | `/api/incidents` | 列出近期事件。 |
| `POST` | `/api/incidents` | 创建新事件。 |
| `PATCH` | `/api/incidents/{incident_id}` | 更新事件状态。 |
| `GET` | `/api/metrics` | 暴露 Prometheus 指标。 |

## 监控
Prometheus 在 Docker 网络内部抓取 API 指标 endpoint:
```
http://api:8000/metrics
```
指标示例:
```
incidents_created_total
incidents_resolved_total
open_incidents
```
## 项目结构
```
incident-response-platform
├── assets
│ └── devto-images
├── infra
│ ├── nginx
│ └── prometheus
├── services
│ ├── api
│ └── frontend
├── .env.example
├── docker-compose.yml
├── DEVTO_ARTICLE.md
└── README.md
```

## 为什么这种模式很重要
本项目采用了与真实生产系统相同的理念:
- 将公共边缘层与内部服务分离开来。
- 拆分 UI、API、worker、数据库、缓存和监控的职责。
- 使用健康检查,以便编排器能够检测到不健康的服务。
- 将状态存储在 volumes 中,而不是容器文件系统中。
- 对于不应阻塞 Web 请求的任务,使用后台 worker 处理。
- 暴露指标,以便对系统进行观测,而不是靠猜测。
## 博客草稿
Dev.to 的文章草稿包含在 [DEVTO_ARTICLE.md](./DEVTO_ARTICLE.md) 中。
文章图片存储在 [assets/devto-images](./assets/devto-images) 中。
## 路线图
- 添加 Grafana dashboards
- 添加身份验证和授权
- 添加 Slack 或 Microsoft Teams 通知
- 添加 GitHub Actions CI/CD
- 添加自动化测试
- 添加容器镜像扫描
- 添加 Nginx 速率限制
- 添加 TLS 支持
- 部署到云环境
## 许可证
本项目旨在用于 DevOps 学习、教程和作品集展示。
标签:AV绕过, Docker Compose, FastAPI, 事件管理, 微服务架构, 搜索引擎查询, 测试用例, 版权保护, 自定义请求头, 运维监控, 逆向工具