Skip to main content

AI-powered log monitoring and auto-fix SDK

Project description

AI-Ops Monitor SDK

PyPI version Python License: MIT

🚀 AI 驱动的日志监控与自动修复 SDK

自动捕获应用错误,AI 分析根因并生成修复方案,让运维更智能!

✨ 特性

  • 🎯 零侵入集成 - 3 行代码接入监控
  • 异步上报 - 不影响应用性能
  • 🤖 AI 分析 - 自动分析错误根因
  • 🔧 自动修复 - AI 生成修复代码
  • 📊 可视化面板 - 实时查看错误趋势
  • 🔔 智能告警 - Telegram 通知
  • 🌐 多框架支持 - Django / Flask / FastAPI

📦 安装

pip install aiops-monitor

# Django 项目
pip install aiops-monitor[django]

# Flask 项目
pip install aiops-monitor[flask]

# FastAPI 项目
pip install aiops-monitor[fastapi]

🚀 快速开始

Django 集成

# settings.py

# 1. 添加到 INSTALLED_APPS
INSTALLED_APPS = [
    # ...
    'aiops_monitor.integrations.django',
]

# 2. 配置监控
AIOPS_MONITOR = {
    'api_url': 'http://your-monitor-server:8000/api/v1',
    'api_key': 'your-api-key',
    'project_name': 'My Django Project',
    'log_levels': ['ERROR', 'CRITICAL'],
    'async': True,
}

Flask 集成

from flask import Flask
from aiops_monitor import init_monitor

app = Flask(__name__)

# 初始化监控
init_monitor(
    app,
    api_url='http://your-monitor-server:8000/api/v1',
    api_key='your-api-key',
    project_name='My Flask App'
)

@app.route('/')
def index():
    # 错误会自动上报
    result = 1 / 0
    return 'Hello'

FastAPI 集成

from fastapi import FastAPI
from aiops_monitor import init_monitor

app = FastAPI()

init_monitor(
    app,
    api_url='http://your-monitor-server:8000/api/v1',
    api_key='your-api-key',
    project_name='My FastAPI App'
)

@app.get("/")
def read_root():
    # 错误会自动上报
    result = 1 / 0
    return {"Hello": "World"}

独立使用

from aiops_monitor import MonitorClient, MonitorConfig
import logging

# 创建配置
config = MonitorConfig(
    api_url='http://your-monitor-server:8000/api/v1',
    api_key='your-api-key',
    project_name='My Script'
)

# 创建客户端
client = MonitorClient(config)

# 添加 handler
handler = client.get_handler(level=logging.ERROR)
logging.root.addHandler(handler)

# 使用
try:
    result = 1 / 0
except Exception:
    logging.error("发生错误", exc_info=True)  # 自动上报

⚙️ 配置选项

参数 类型 必需 默认值 说明
api_url str - 监控服务地址
api_key str - API 密钥
project_name str None 项目名称
log_levels list ['ERROR', 'CRITICAL'] 上报的日志级别
timeout int 5 请求超时时间(秒)
async_mode bool True 异步上报模式
max_retries int 3 最大重试次数
enabled bool True 是否启用监控

🔍 工作流程

应用错误 → SDK 捕获 → 异步上报 → AI 分析
    ↓
修复代码 ← AI 生成 ← 根因定位

📊 监控面板

SDK 配合监控服务器使用,提供:

  • 📈 实时监控 - 错误统计和趋势分析
  • 🔎 智能聚合 - 相同错误自动归类
  • 🤖 AI 分析 - GPT-4 分析错误根因
  • 💊 自动修复 - 生成修复代码和 diff
  • 📱 Telegram 通知 - 实时告警推送

🛠️ 开发

# 克隆仓库
git clone https://github.com/SunshineList/aiops-monitor
cd aiops-monitor

# 安装开发依赖
pip install -e ".[dev]"

# 运行测试
pytest

# 代码格式化
black aiops_monitor

# 类型检查
mypy aiops_monitor

📝 License

MIT License - 详见 LICENSE 文件

📮 联系


Made with ❤️ by Tuple

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiops_monitor-0.1.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiops_monitor-0.1.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file aiops_monitor-0.1.0.tar.gz.

File metadata

  • Download URL: aiops_monitor-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for aiops_monitor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 046123e36aff9e11848c89b01eb63ffcccea6a13024cd3ba9af45e85a606ee0f
MD5 d29d2c5ca411c452755c0776b20448d0
BLAKE2b-256 345d7dccab93850f1ad5d172b4251f3e3c4b2f486369418c41211662dee5e096

See more details on using hashes here.

File details

Details for the file aiops_monitor-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aiops_monitor-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for aiops_monitor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3e13b2c0fa5d653e14675d04fccaed1b792d4cddcdd5e6636e2472284ebccea
MD5 eacb06e9b8f51db25dad7025c613ec1e
BLAKE2b-256 78dab36c8be300e078a69aefbe63d84c4dca929cedaf01b573277c73503fbbb7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page