mirror of
https://github.com/andrey271192/vps_monitoring.git
synced 2026-09-20 11:55:34 +00:00
- Sectioned card layout: СЕРВЕРЫ, ДЕЙСТВИЯ, УВЕДОМЛЕНИЯ, СИСТЕМА - Expandable server cards with metrics detail + reboot/delete - Mute/unmute alerts (2h, 8h) with API support - Green/red pulsing status dots, colored badges - Toast notifications, loading spinner - Overview API endpoint for Mini App data - Mute integration with alerter system Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
import logging
|
|
from datetime import datetime
|
|
from typing import Dict
|
|
|
|
from server.config import load_settings, load_servers
|
|
from server.services.monitor import get_all_metrics
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
previous_states: Dict[str, bool] = {}
|
|
|
|
|
|
async def check_alerts():
|
|
"""Check metrics against thresholds and send alerts."""
|
|
from server.services.telegram_bot import send_alert
|
|
from server.api.auth_routes import mute_until
|
|
|
|
# Check mute
|
|
if mute_until and datetime.now() < mute_until:
|
|
return
|
|
|
|
settings = load_settings()
|
|
servers = load_servers()
|
|
metrics = get_all_metrics()
|
|
|
|
cpu_threshold = settings.get("alert_cpu_threshold", 90)
|
|
ram_threshold = settings.get("alert_ram_threshold", 90)
|
|
disk_threshold = settings.get("alert_disk_threshold", 90)
|
|
|
|
for srv in servers:
|
|
host = srv["host"]
|
|
m = metrics.get(host, {})
|
|
name = srv.get("name", host)
|
|
|
|
current_online = m.get("online", False)
|
|
prev_online = previous_states.get(host)
|
|
|
|
# Online/Offline state change
|
|
if prev_online is not None and prev_online != current_online:
|
|
if current_online:
|
|
await send_alert(f"🟢 **{name}** ({host}) — снова онлайн")
|
|
else:
|
|
await send_alert(f"🔴 **{name}** ({host}) — OFFLINE!")
|
|
|
|
previous_states[host] = current_online
|
|
|
|
if not current_online:
|
|
continue
|
|
|
|
# Threshold alerts
|
|
cpu = m.get("cpu_percent", 0)
|
|
if cpu >= cpu_threshold:
|
|
await send_alert(f"⚠️ **{name}** — CPU: {cpu}% (порог: {cpu_threshold}%)")
|
|
|
|
ram = m.get("ram_percent", 0)
|
|
if ram >= ram_threshold:
|
|
await send_alert(f"⚠️ **{name}** — RAM: {ram}% (порог: {ram_threshold}%)")
|
|
|
|
disk = m.get("disk_percent", 0)
|
|
if disk >= disk_threshold:
|
|
await send_alert(f"⚠️ **{name}** — Disk: {disk}% (порог: {disk_threshold}%)")
|