feat(alerts): 添加微信告警、WebSocket实时推送和地图功能
- 新增微信告警服务(wechat_service)和告警任务(alert_tasks) - 新增 WebSocket 实时推送端点 - 新增监控管理模块(monitor) - 增强统计仪表板:趋势图、区域分布、光功率历史 - 设备管理:添加坐标信息、标签系统、复合索引优化 - 前端:重构Dashboard/Charts页面,新增业务组件 - 新增5个数据库迁移(坐标、复合索引、标签、光功率历史、显示名) - 更新部署配置和脚本 - 新增测试框架基础结构
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""Celery 任务监控 API"""
|
||||
import time
|
||||
import redis as redis_lib
|
||||
from fastapi import APIRouter, Depends
|
||||
from app.core.celery_app import celery_app
|
||||
from app.core.config import settings
|
||||
from app.middleware.permission_middleware import require_permission
|
||||
|
||||
router = APIRouter(prefix="/api/monitor", tags=["任务监控"])
|
||||
|
||||
|
||||
def _get_redis():
|
||||
return redis_lib.from_url(settings.REDIS_URL, decode_responses=True)
|
||||
|
||||
|
||||
@router.get("/tasks")
|
||||
def get_task_status(_: dict = Depends(require_permission('*'))):
|
||||
"""获取 Celery 任务状态概览"""
|
||||
try:
|
||||
insp = celery_app.control.inspect()
|
||||
active = insp.active() or {}
|
||||
scheduled = insp.scheduled() or {}
|
||||
reserved = insp.reserved() or {}
|
||||
|
||||
r = _get_redis()
|
||||
last_run = r.get("check_all_devices:last_run")
|
||||
is_running = bool(r.get("check_all_devices:running"))
|
||||
interval_str = r.get("system:check_interval_seconds")
|
||||
|
||||
interval = int(interval_str) if interval_str else 1800
|
||||
next_run = None
|
||||
if last_run and not is_running:
|
||||
next_run = float(last_run) + interval
|
||||
|
||||
return {
|
||||
"workers": list(active.keys()),
|
||||
"active_count": sum(len(v) for v in active.values()),
|
||||
"scheduled_count": sum(len(v) for v in scheduled.values()),
|
||||
"check_running": is_running,
|
||||
"last_check": float(last_run) if last_run else None,
|
||||
"next_check": next_run,
|
||||
"check_interval_seconds": interval,
|
||||
}
|
||||
except Exception as e:
|
||||
return {"error": str(e)}
|
||||
Reference in New Issue
Block a user