標記 aiops-core 為歷史草稿
This commit is contained in:
@@ -1,200 +1,16 @@
|
|||||||
# WOOO AIOps Core
|
# WOOO AIOps Core
|
||||||
|
|
||||||
智慧雲端運維平台核心模組
|
> Historical stub only. Do not install dependencies or deploy services from this
|
||||||
|
> directory.
|
||||||
|
|
||||||
## 架構概覽
|
This directory originally sketched a standalone AIOps SaaS module, but the
|
||||||
|
actual production implementation now lives in the main momo-pro-system codebase:
|
||||||
|
|
||||||
```
|
- Current AutoHeal service: `services/auto_heal_service.py`
|
||||||
aiops-core/
|
- Current Aider heal executor: `services/aider_heal_executor.py`
|
||||||
├── deploy_engine/ # 部署引擎
|
- Architecture decision: `docs/adr/ADR-013-aiops-autoheal.md`
|
||||||
│ ├── deploy_service.py # 主部署服務
|
- Full-auto code-heal decision: `docs/adr/ADR-020-code-review-full-autoheal.md`
|
||||||
│ ├── template_renderer.py # Jinja2 模板渲染
|
|
||||||
│ └── k8s_client.py # Kubernetes 客戶端
|
|
||||||
│
|
|
||||||
├── monitor_engine/ # 監控引擎
|
|
||||||
│ ├── monitor_service.py # 監控服務
|
|
||||||
│ ├── prometheus_client.py # Prometheus API
|
|
||||||
│ └── alert_manager.py # Alertmanager API
|
|
||||||
│
|
|
||||||
├── repair_engine/ # 自動修復引擎
|
|
||||||
│ ├── repair_service.py # 修復決策引擎
|
|
||||||
│ ├── repair_executor.py # 修復執行器
|
|
||||||
│ └── repair_strategies.py # 修復策略
|
|
||||||
│
|
|
||||||
├── templates/ # K8s 部署模板
|
|
||||||
│ ├── base/ # 基礎模板
|
|
||||||
│ │ ├── namespace.yaml.j2
|
|
||||||
│ │ ├── service.yaml.j2
|
|
||||||
│ │ └── ingress.yaml.j2
|
|
||||||
│ └── frameworks/ # 框架專用模板
|
|
||||||
│ ├── fastapi/
|
|
||||||
│ ├── flask/
|
|
||||||
│ ├── express/
|
|
||||||
│ └── nextjs/
|
|
||||||
│
|
|
||||||
├── api/ # FastAPI 後端
|
|
||||||
│ ├── main.py # 應用入口
|
|
||||||
│ └── routers/ # API 路由
|
|
||||||
│ ├── auth.py # 認證
|
|
||||||
│ ├── apps.py # 應用管理
|
|
||||||
│ ├── deployments.py # 部署管理
|
|
||||||
│ ├── monitoring.py # 監控
|
|
||||||
│ ├── repairs.py # 自動修復
|
|
||||||
│ └── users.py # 用戶管理
|
|
||||||
│
|
|
||||||
└── web/ # React 前端
|
|
||||||
├── src/
|
|
||||||
│ ├── pages/ # 頁面
|
|
||||||
│ ├── components/ # 組件
|
|
||||||
│ └── lib/ # 工具庫
|
|
||||||
└── package.json
|
|
||||||
```
|
|
||||||
|
|
||||||
## 核心功能
|
The previous `aiops-core/requirements.txt` listed dependencies for non-existent
|
||||||
|
FastAPI, React, Kubernetes, Redis, and Celery modules. It was removed to avoid
|
||||||
### 1. Deploy Engine - 一鍵部署
|
dependency drift and accidental installation in CI or local setup scripts.
|
||||||
|
|
||||||
```python
|
|
||||||
from aiops_core.deploy_engine import DeployService
|
|
||||||
|
|
||||||
deploy_service = DeployService()
|
|
||||||
|
|
||||||
# 部署新應用
|
|
||||||
result = deploy_service.deploy(
|
|
||||||
app=AppConfig(
|
|
||||||
name="my-api",
|
|
||||||
framework="fastapi",
|
|
||||||
git_repo="https://github.com/user/repo.git",
|
|
||||||
branch="main"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Monitor Engine - 智能監控
|
|
||||||
|
|
||||||
```python
|
|
||||||
from aiops_core.monitor_engine import MonitorService
|
|
||||||
|
|
||||||
monitor_service = MonitorService()
|
|
||||||
|
|
||||||
# 設置監控
|
|
||||||
monitor_service.setup_monitoring(
|
|
||||||
config=MonitorConfig(
|
|
||||||
app_name="my-api",
|
|
||||||
namespace="default",
|
|
||||||
telegram_chat_id="123456789"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# 取得健康狀態
|
|
||||||
health = monitor_service.get_app_health("my-api", "default")
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. Repair Engine - 自動修復
|
|
||||||
|
|
||||||
```python
|
|
||||||
from aiops_core.repair_engine import RepairService
|
|
||||||
|
|
||||||
repair_service = RepairService()
|
|
||||||
|
|
||||||
# 處理告警,自動決定並執行修復
|
|
||||||
repair_service.process_alert({
|
|
||||||
"labels": {
|
|
||||||
"alertname": "HighMemoryUsage",
|
|
||||||
"app": "my-api",
|
|
||||||
"namespace": "default"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
## 支援的框架
|
|
||||||
|
|
||||||
| 框架 | 狀態 | 預設端口 |
|
|
||||||
|------|------|---------|
|
|
||||||
| FastAPI | ✅ | 8000 |
|
|
||||||
| Flask | ✅ | 5000 |
|
|
||||||
| Express.js | ✅ | 3000 |
|
|
||||||
| Next.js | ✅ | 3000 |
|
|
||||||
| Django | 🚧 | 8000 |
|
|
||||||
| NestJS | 🚧 | 3000 |
|
|
||||||
|
|
||||||
## 自動修復策略
|
|
||||||
|
|
||||||
| 告警類型 | 修復動作 |
|
|
||||||
|---------|---------|
|
|
||||||
| AppDown | 重啟 Pod |
|
|
||||||
| HighMemoryUsage | 重啟 Pod |
|
|
||||||
| PodOOMKilled | 增加記憶體限制 +50% |
|
|
||||||
| HighCPUUsage | 擴容 +50% |
|
|
||||||
| HighHTTP5xxRate | 回滾到上一版本 |
|
|
||||||
| PostgresHighConnections | VACUUM ANALYZE |
|
|
||||||
| DiskSpaceLow | 清理快取 |
|
|
||||||
|
|
||||||
## API 端點
|
|
||||||
|
|
||||||
### 認證
|
|
||||||
- `POST /api/auth/login` - 登入
|
|
||||||
- `POST /api/auth/register` - 註冊
|
|
||||||
- `GET /api/auth/me` - 取得當前用戶
|
|
||||||
|
|
||||||
### 應用管理
|
|
||||||
- `GET /api/apps` - 列出應用
|
|
||||||
- `POST /api/apps` - 創建應用
|
|
||||||
- `GET /api/apps/{id}` - 取得應用詳情
|
|
||||||
- `PUT /api/apps/{id}` - 更新應用
|
|
||||||
- `DELETE /api/apps/{id}` - 刪除應用
|
|
||||||
- `POST /api/apps/{id}/start` - 啟動應用
|
|
||||||
- `POST /api/apps/{id}/stop` - 停止應用
|
|
||||||
- `POST /api/apps/{id}/restart` - 重啟應用
|
|
||||||
|
|
||||||
### 部署
|
|
||||||
- `GET /api/deployments` - 列出部署記錄
|
|
||||||
- `POST /api/deployments` - 創建部署
|
|
||||||
- `POST /api/deployments/{id}/cancel` - 取消部署
|
|
||||||
- `POST /api/deployments/{id}/rollback` - 回滾部署
|
|
||||||
|
|
||||||
### 監控
|
|
||||||
- `GET /api/monitoring/dashboard` - 儀表板概覽
|
|
||||||
- `GET /api/monitoring/apps/{id}/metrics` - 應用指標
|
|
||||||
- `GET /api/monitoring/apps/{id}/health` - 健康狀態
|
|
||||||
- `GET /api/monitoring/alerts` - 告警列表
|
|
||||||
|
|
||||||
### 自動修復
|
|
||||||
- `GET /api/repairs` - 修復記錄
|
|
||||||
- `GET /api/repairs/stats` - 修復統計
|
|
||||||
- `POST /api/repairs/apps/{id}/trigger` - 手動觸發修復
|
|
||||||
|
|
||||||
## 快速開始
|
|
||||||
|
|
||||||
### 啟動 API 服務
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd aiops-core/api
|
|
||||||
pip install -r requirements.txt
|
|
||||||
uvicorn main:app --reload --port 8000
|
|
||||||
```
|
|
||||||
|
|
||||||
### 啟動 Web 前端
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd aiops-core/web
|
|
||||||
npm install
|
|
||||||
npm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
## 環境變數
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# API
|
|
||||||
JWT_SECRET=your-secret-key
|
|
||||||
PROMETHEUS_URL=http://prometheus:9090
|
|
||||||
ALERTMANAGER_URL=http://alertmanager:9093
|
|
||||||
TELEGRAM_BOT_TOKEN=your-bot-token
|
|
||||||
|
|
||||||
# Web
|
|
||||||
NEXT_PUBLIC_API_URL=http://localhost:8000/api
|
|
||||||
```
|
|
||||||
|
|
||||||
## 授權
|
|
||||||
|
|
||||||
© 2026 WOOO TECH. All rights reserved.
|
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
# =============================================================================
|
|
||||||
# WOOO AIOps - Python Dependencies
|
|
||||||
# =============================================================================
|
|
||||||
|
|
||||||
# Web Framework
|
|
||||||
fastapi>=0.109.0
|
|
||||||
uvicorn[standard]>=0.27.0
|
|
||||||
python-multipart>=0.0.6
|
|
||||||
|
|
||||||
# Database
|
|
||||||
sqlalchemy>=2.0.0
|
|
||||||
psycopg2-binary>=2.9.9
|
|
||||||
alembic>=1.13.0
|
|
||||||
|
|
||||||
# Authentication
|
|
||||||
pyjwt>=2.8.0
|
|
||||||
passlib[bcrypt]>=1.7.4
|
|
||||||
|
|
||||||
# Template Rendering
|
|
||||||
jinja2>=3.1.2
|
|
||||||
pyyaml>=6.0.1
|
|
||||||
|
|
||||||
# HTTP Client
|
|
||||||
requests>=2.31.0
|
|
||||||
httpx>=0.26.0
|
|
||||||
|
|
||||||
# Kubernetes
|
|
||||||
kubernetes>=29.0.0
|
|
||||||
|
|
||||||
# Monitoring & Alerting
|
|
||||||
prometheus-client>=0.19.0
|
|
||||||
|
|
||||||
# Caching
|
|
||||||
redis>=5.0.0
|
|
||||||
|
|
||||||
# Task Queue (可選)
|
|
||||||
celery>=5.3.0
|
|
||||||
|
|
||||||
# Utilities
|
|
||||||
python-dotenv>=1.0.0
|
|
||||||
pydantic>=2.5.0
|
|
||||||
pydantic-settings>=2.1.0
|
|
||||||
|
|
||||||
# Logging
|
|
||||||
structlog>=24.1.0
|
|
||||||
|
|
||||||
# Testing
|
|
||||||
pytest>=7.4.0
|
|
||||||
pytest-asyncio>=0.23.0
|
|
||||||
httpx>=0.26.0
|
|
||||||
|
|
||||||
# Security
|
|
||||||
cryptography>=41.0.0
|
|
||||||
|
|
||||||
# Date/Time
|
|
||||||
python-dateutil>=2.8.2
|
|
||||||
Reference in New Issue
Block a user