wiki4012/Hire-Challenge

GitHub: wiki4012/Hire-Challenge

一个基于 Python 的智能可观测性平台,通过异步 API 摄入日志、统计与 AI 辅助检测异常,实现告警生成、健康可视化及事件响应模拟。

Stars: 0 | Forks: 0

# 智能可观测性与事件监控 企业级 Python MVP,用于摄入日志、检测异常、生成警报、可视化健康状况以及模拟事件响应。 ## 功能 - FastAPI 异步 API,支持 JWT 身份验证和基于角色的访问控制。 - 默认使用 SQLite 作为备选;通过 Docker Compose 支持 PostgreSQL。 - 支持 CSV、JSON 以及模拟流式日志摄入。 - 统计异常检测,包含 z-score、移动平均线、错误激增、服务故障、流量激增、延迟峰值,以及可选的 Isolation Forest。 - 警报和事件生成,包含用于生成事件摘要的本地 LLM 抽象。 - Streamlit 仪表盘,提供健康评分、趋势、严重性分布、警报时间轴和事件查看。 - SQLAlchemy 模型、repository 模式、服务层、Alembic 迁移、测试、Docker 部署、示例数据集和审计日志。 ## 架构优先交付物 - 架构图:`docs/architecture.md` - API 契约:`docs/api_contract.md` - SQL schema:`docs/database_schema.sql` - 线框图:`docs/wireframes.md` - 部署计划:`docs/deployment_plan.md` - 路线图:`docs/roadmap.md` ## 本地运行 ``` py -3.12 -m venv .venv .\.venv\Scripts\Activate.ps1 python -m pip install --upgrade pip pip install -e ".[dev,ai]" uvicorn app.main:app --reload ``` 默认管理员: ``` username: admin password: admin12345 ``` 在第二个终端启动仪表盘: ``` .\.venv\Scripts\Activate.ps1 streamlit run dashboard/app.py ``` API:`http://localhost:8000` 仪表盘:`http://localhost:8501` OpenAPI 文档:`http://localhost:8000/docs` ## Docker 运行 ``` docker compose up --build ``` 服务: - API:`http://localhost:8000` - 仪表盘:`http://localhost:8501` - PostgreSQL:`localhost:5432` ## 上传示例日志 ``` $token = (Invoke-RestMethod -Method Post -Uri http://localhost:8000/auth/token -Body @{username='admin'; password='admin12345'}).access_token Invoke-RestMethod -Method Post -Uri http://localhost:8000/logs/upload -Headers @{Authorization="Bearer $token"} -Form @{file=Get-Item .\data\sample_logs.csv} ``` JSON 上传格式: ``` { "records": [ { "timestamp": "2025-06-20T12:00:00", "service": "auth-service", "severity": "ERROR", "message": "Database timeout", "response_time": 4500 } ] } ``` ## 测试 ``` pytest ``` 如果您的本地 Python 环境无法安装 SciPy/scikit-learn wheels,请使用 `pip install -e ".[dev]"`。 Isolation Forest 的实现仍然保留,当可选的 AI 扩展不可用时,应用会回退到确定性的统计检测。 ## 阶段总结 | 阶段 | 目标 | 关键文件 | 验证 | | --- | --- | --- | --- | | 1 | 架构图 | `docs/architecture.md` | 审查 Mermaid 图表 | | 2 | 文件夹结构 | `app/`, `dashboard/`, `tests/` | `Get-ChildItem -Recurse` | | 3 | 后端 API | `app/api/*.py`, `app/main.py` | `GET /health`, `/docs` | | 4 | 数据库模型 | `app/models/*.py`, `alembic/` | 应用启动时创建 schema | | 5 | 异常引擎 | `app/ai/anomaly_detector.py` | 上传错误密集的批次 | | 6 | 警报管理器 | `app/services/alert_service.py` | `GET /alerts`, `GET /incidents` | | 7 | 仪表盘 | `dashboard/app.py` | Streamlit 加载指标 | | 8 | Docker | `Dockerfile`, `docker-compose.yml` | `docker compose up --build` | | 9 | 测试 | `tests/test_api.py` | `pytest` | | 10 | 演示文稿 | `ppt.md` | 从 Markdown 进行展示 | ## 环境变量 有关完整的部署矩阵,请参阅 `docs/deployment_plan.md`。
标签:API集成, AV绕过, FastAPI, Kubernetes, Streamlit, 可观测性, 告警系统, 异常检测, 测试用例, 访问控制, 请求拦截, 逆向工具