mirror of
https://github.com/andrey271192/vps_monitoring.git
synced 2026-09-20 11:55:34 +00:00
feat: redesign Telegram Mini App in keenetichome style
- 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>
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from fastapi import APIRouter, HTTPException, Request
|
from fastapi import APIRouter, HTTPException, Request
|
||||||
from fastapi.responses import RedirectResponse, JSONResponse
|
from fastapi.responses import RedirectResponse, JSONResponse
|
||||||
|
|
||||||
@@ -49,3 +51,74 @@ async def update_settings(update: SettingsUpdate, request: Request):
|
|||||||
settings[key] = val
|
settings[key] = val
|
||||||
save_settings(settings)
|
save_settings(settings)
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
|
# Mute alerts
|
||||||
|
mute_until: datetime | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/api/mute")
|
||||||
|
async def mute_alerts(request: Request):
|
||||||
|
global mute_until
|
||||||
|
require_auth(request)
|
||||||
|
body = await request.json()
|
||||||
|
hours = body.get("hours", 2)
|
||||||
|
mute_until = datetime.now() + timedelta(hours=hours)
|
||||||
|
return {"status": "ok", "muted_until": mute_until.isoformat()}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/api/unmute")
|
||||||
|
async def unmute_alerts(request: Request):
|
||||||
|
global mute_until
|
||||||
|
require_auth(request)
|
||||||
|
mute_until = None
|
||||||
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/api/mute/status")
|
||||||
|
async def mute_status(request: Request):
|
||||||
|
require_auth(request)
|
||||||
|
if mute_until and datetime.now() < mute_until:
|
||||||
|
return {"muted": True, "until": mute_until.isoformat()}
|
||||||
|
return {"muted": False}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/api/overview")
|
||||||
|
async def overview(request: Request):
|
||||||
|
"""Full overview for Telegram Mini App."""
|
||||||
|
require_auth(request)
|
||||||
|
from server.config import load_servers
|
||||||
|
from server.services.monitor import get_all_metrics
|
||||||
|
|
||||||
|
servers = load_servers()
|
||||||
|
metrics = get_all_metrics()
|
||||||
|
|
||||||
|
srv_list = []
|
||||||
|
online_count = 0
|
||||||
|
for s in servers:
|
||||||
|
m = metrics.get(s["host"], {})
|
||||||
|
is_online = m.get("online", False)
|
||||||
|
if is_online:
|
||||||
|
online_count += 1
|
||||||
|
srv_list.append({
|
||||||
|
"id": s.get("id", ""),
|
||||||
|
"name": s["name"],
|
||||||
|
"host": s["host"],
|
||||||
|
"online": is_online,
|
||||||
|
"cpu": m.get("cpu_percent", 0),
|
||||||
|
"ram": m.get("ram_percent", 0),
|
||||||
|
"disk": m.get("disk_percent", 0),
|
||||||
|
"uptime": m.get("uptime", ""),
|
||||||
|
"load": m.get("load_average", ""),
|
||||||
|
})
|
||||||
|
|
||||||
|
is_muted = mute_until and datetime.now() < mute_until
|
||||||
|
|
||||||
|
return {
|
||||||
|
"servers": srv_list,
|
||||||
|
"total": len(servers),
|
||||||
|
"online": online_count,
|
||||||
|
"offline": len(servers) - online_count,
|
||||||
|
"muted": is_muted,
|
||||||
|
"muted_until": mute_until.isoformat() if is_muted else None,
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ previous_states: Dict[str, bool] = {}
|
|||||||
async def check_alerts():
|
async def check_alerts():
|
||||||
"""Check metrics against thresholds and send alerts."""
|
"""Check metrics against thresholds and send alerts."""
|
||||||
from server.services.telegram_bot import send_alert
|
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()
|
settings = load_settings()
|
||||||
servers = load_servers()
|
servers = load_servers()
|
||||||
|
|||||||
@@ -2,254 +2,543 @@
|
|||||||
<html lang="ru">
|
<html lang="ru">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
<title>VPS Monitor</title>
|
<title>VPS Monitor</title>
|
||||||
<script src="https://telegram.org/js/telegram-web-app.js"></script>
|
<script src="https://telegram.org/js/telegram-web-app.js"></script>
|
||||||
<style>
|
<style>
|
||||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
|
||||||
background: var(--tg-theme-bg-color, #1a1a2e);
|
background: var(--tg-theme-bg-color, #0f172a);
|
||||||
color: var(--tg-theme-text-color, #eee);
|
color: var(--tg-theme-text-color, #e2e8f0);
|
||||||
padding: 16px;
|
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
|
padding: 0 0 24px 0;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
}
|
}
|
||||||
.header {
|
|
||||||
text-align: center;
|
/* Header */
|
||||||
margin-bottom: 20px;
|
.app-header {
|
||||||
padding: 16px;
|
padding: 20px 16px 16px;
|
||||||
background: var(--tg-theme-secondary-bg-color, #16213e);
|
|
||||||
border-radius: 12px;
|
|
||||||
}
|
|
||||||
.header h1 { font-size: 20px; margin-bottom: 4px; }
|
|
||||||
.header .subtitle { opacity: 0.7; font-size: 13px; }
|
|
||||||
.stats {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(3, 1fr);
|
|
||||||
gap: 8px;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
.stat-card {
|
|
||||||
background: var(--tg-theme-secondary-bg-color, #16213e);
|
|
||||||
border-radius: 10px;
|
|
||||||
padding: 12px;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.stat-card .value { font-size: 24px; font-weight: bold; }
|
.app-header h1 {
|
||||||
.stat-card .label { font-size: 11px; opacity: 0.7; margin-top: 4px; }
|
font-size: 22px;
|
||||||
.stat-card.online .value { color: #4ade80; }
|
font-weight: 700;
|
||||||
.stat-card.offline .value { color: #f87171; }
|
letter-spacing: -0.3px;
|
||||||
.server-list { list-style: none; }
|
}
|
||||||
.server-item {
|
.app-header .stats-row {
|
||||||
background: var(--tg-theme-secondary-bg-color, #16213e);
|
display: flex;
|
||||||
border-radius: 12px;
|
justify-content: center;
|
||||||
padding: 14px 16px;
|
gap: 16px;
|
||||||
margin-bottom: 10px;
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
.stat-pill {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
gap: 6px;
|
||||||
cursor: pointer;
|
padding: 6px 14px;
|
||||||
transition: transform 0.1s;
|
border-radius: 20px;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
background: var(--tg-theme-secondary-bg-color, #1e293b);
|
||||||
}
|
}
|
||||||
.server-item:active { transform: scale(0.98); }
|
.stat-pill .dot {
|
||||||
.server-info { flex: 1; }
|
width: 8px; height: 8px;
|
||||||
.server-name { font-weight: 600; font-size: 15px; }
|
border-radius: 50%;
|
||||||
.server-host { font-size: 12px; opacity: 0.6; margin-top: 2px; }
|
|
||||||
.server-metrics {
|
|
||||||
display: flex;
|
|
||||||
gap: 8px;
|
|
||||||
margin-top: 8px;
|
|
||||||
}
|
}
|
||||||
.metric-badge {
|
.stat-pill .dot.green { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
|
||||||
|
.stat-pill .dot.red { background: #ef4444; box-shadow: 0 0 6px #ef4444; }
|
||||||
|
.stat-pill .dot.gray { background: #64748b; }
|
||||||
|
|
||||||
|
/* Sections */
|
||||||
|
.section {
|
||||||
|
padding: 0 16px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
.section-title {
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 1.5px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: var(--tg-theme-hint-color, #64748b);
|
||||||
|
padding: 16px 4px 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cards */
|
||||||
|
.card {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
background: var(--tg-theme-secondary-bg-color, #1e293b);
|
||||||
|
border: 1px solid rgba(255,255,255,0.06);
|
||||||
|
border-radius: 14px;
|
||||||
|
padding: 14px 16px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 0.1s, opacity 0.1s;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.card:active {
|
||||||
|
transform: scale(0.98);
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-icon {
|
||||||
|
width: 42px;
|
||||||
|
height: 42px;
|
||||||
|
border-radius: 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 20px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
margin-right: 14px;
|
||||||
|
}
|
||||||
|
.card-icon.green { background: rgba(34, 197, 94, 0.15); }
|
||||||
|
.card-icon.red { background: rgba(239, 68, 68, 0.15); }
|
||||||
|
.card-icon.blue { background: rgba(59, 130, 246, 0.15); }
|
||||||
|
.card-icon.yellow { background: rgba(245, 158, 11, 0.15); }
|
||||||
|
.card-icon.purple { background: rgba(168, 85, 247, 0.15); }
|
||||||
|
.card-icon.cyan { background: rgba(34, 211, 238, 0.15); }
|
||||||
|
|
||||||
|
.card-body { flex: 1; min-width: 0; }
|
||||||
|
.card-title {
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.3;
|
||||||
|
}
|
||||||
|
.card-sub {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--tg-theme-hint-color, #64748b);
|
||||||
|
margin-top: 2px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-badge {
|
||||||
padding: 3px 8px;
|
padding: 3px 8px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
background: rgba(255,255,255,0.1);
|
font-size: 11px;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-right: 10px;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
.metric-badge.warn { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
|
.card-badge.online { background: rgba(34,197,94,0.15); color: #22c55e; }
|
||||||
.metric-badge.crit { background: rgba(248, 113, 113, 0.2); color: #f87171; }
|
.card-badge.offline { background: rgba(239,68,68,0.15); color: #ef4444; }
|
||||||
.status-dot {
|
.card-badge.warn { background: rgba(245,158,11,0.15); color: #f59e0b; }
|
||||||
width: 10px;
|
.card-badge.num {
|
||||||
height: 10px;
|
background: rgba(99,102,241,0.15);
|
||||||
border-radius: 50%;
|
color: #818cf8;
|
||||||
margin-left: 12px;
|
font-size: 13px;
|
||||||
|
font-weight: 700;
|
||||||
|
padding: 4px 10px;
|
||||||
|
border-radius: 8px;
|
||||||
|
min-width: 32px;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
.status-dot.online { background: #4ade80; box-shadow: 0 0 6px #4ade80; }
|
|
||||||
.status-dot.offline { background: #f87171; box-shadow: 0 0 6px #f87171; }
|
.card-chevron {
|
||||||
|
color: var(--tg-theme-hint-color, #475569);
|
||||||
|
font-size: 18px;
|
||||||
|
margin-left: 8px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Server detail (expandable) */
|
||||||
.server-detail {
|
.server-detail {
|
||||||
display: none;
|
max-height: 0;
|
||||||
background: var(--tg-theme-secondary-bg-color, #16213e);
|
overflow: hidden;
|
||||||
border-radius: 12px;
|
transition: max-height 0.3s ease;
|
||||||
|
background: var(--tg-theme-secondary-bg-color, #1e293b);
|
||||||
|
border-radius: 0 0 14px 14px;
|
||||||
|
margin-top: -22px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
border: 1px solid rgba(255,255,255,0.06);
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
.server-detail.open {
|
||||||
|
max-height: 400px;
|
||||||
|
}
|
||||||
|
.server-detail-inner {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
}
|
||||||
.server-detail.active { display: block; }
|
.detail-grid {
|
||||||
.detail-row {
|
display: grid;
|
||||||
display: flex;
|
grid-template-columns: 1fr 1fr;
|
||||||
justify-content: space-between;
|
gap: 10px;
|
||||||
padding: 8px 0;
|
|
||||||
border-bottom: 1px solid rgba(255,255,255,0.05);
|
|
||||||
}
|
}
|
||||||
.detail-row:last-child { border: none; }
|
.detail-cell {
|
||||||
.detail-label { opacity: 0.7; font-size: 13px; }
|
background: rgba(0,0,0,0.2);
|
||||||
.detail-value { font-weight: 500; font-size: 13px; }
|
border-radius: 8px;
|
||||||
.action-buttons {
|
padding: 10px;
|
||||||
|
}
|
||||||
|
.detail-cell .label {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--tg-theme-hint-color, #64748b);
|
||||||
|
}
|
||||||
|
.detail-cell .val {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 700;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
.detail-cell .val.ok { color: #22c55e; }
|
||||||
|
.detail-cell .val.warn { color: #f59e0b; }
|
||||||
|
.detail-cell .val.crit { color: #ef4444; }
|
||||||
|
|
||||||
|
.detail-actions {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
margin-top: 12px;
|
margin-top: 12px;
|
||||||
}
|
}
|
||||||
.action-btn {
|
.detail-btn {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background: var(--tg-theme-button-color, #0a84ff);
|
display: flex;
|
||||||
color: var(--tg-theme-button-text-color, #fff);
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 6px;
|
||||||
|
transition: opacity 0.1s;
|
||||||
|
color: #fff;
|
||||||
}
|
}
|
||||||
.action-btn.danger { background: #dc2626; }
|
.detail-btn:active { opacity: 0.7; }
|
||||||
.loading { text-align: center; padding: 40px; opacity: 0.5; }
|
.detail-btn.primary { background: #3b82f6; }
|
||||||
.refresh-btn {
|
.detail-btn.danger { background: #ef4444; }
|
||||||
display: block;
|
|
||||||
width: 100%;
|
/* Toast */
|
||||||
padding: 14px;
|
.toast {
|
||||||
margin-top: 16px;
|
position: fixed;
|
||||||
border: none;
|
bottom: 80px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%) translateY(20px);
|
||||||
|
background: var(--tg-theme-secondary-bg-color, #1e293b);
|
||||||
|
border: 1px solid rgba(255,255,255,0.1);
|
||||||
|
padding: 12px 24px;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
font-size: 15px;
|
font-size: 14px;
|
||||||
cursor: pointer;
|
font-weight: 500;
|
||||||
background: var(--tg-theme-button-color, #0a84ff);
|
opacity: 0;
|
||||||
color: var(--tg-theme-button-text-color, #fff);
|
transition: all 0.3s;
|
||||||
|
z-index: 100;
|
||||||
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
.toast.show {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateX(-50%) translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Loading */
|
||||||
|
.loading-screen {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 60vh;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
.spinner {
|
||||||
|
width: 32px; height: 32px;
|
||||||
|
border: 3px solid rgba(255,255,255,0.1);
|
||||||
|
border-top-color: #6366f1;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 0.8s linear infinite;
|
||||||
|
}
|
||||||
|
@keyframes spin { to { transform: rotate(360deg); } }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="header">
|
<div id="app">
|
||||||
<h1>🖥 VPS Monitor</h1>
|
<div class="loading-screen" id="loadingScreen">
|
||||||
<div class="subtitle">Мониторинг серверов</div>
|
<div class="spinner"></div>
|
||||||
</div>
|
<span style="opacity:0.5;font-size:13px">Загрузка...</span>
|
||||||
|
|
||||||
<div class="stats">
|
|
||||||
<div class="stat-card">
|
|
||||||
<div class="value" id="total">-</div>
|
|
||||||
<div class="label">Всего</div>
|
|
||||||
</div>
|
|
||||||
<div class="stat-card online">
|
|
||||||
<div class="value" id="online">-</div>
|
|
||||||
<div class="label">Online</div>
|
|
||||||
</div>
|
|
||||||
<div class="stat-card offline">
|
|
||||||
<div class="value" id="offline">-</div>
|
|
||||||
<div class="label">Offline</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="server-list" id="serverList">
|
<div class="toast" id="toast"></div>
|
||||||
<li class="loading">Загрузка...</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<button class="refresh-btn" onclick="loadServers()">🔄 Обновить</button>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const tg = window.Telegram?.WebApp;
|
const tg = window.Telegram?.WebApp;
|
||||||
if (tg) {
|
if (tg) { tg.ready(); tg.expand(); }
|
||||||
tg.ready();
|
|
||||||
tg.expand();
|
let data = null;
|
||||||
|
let openServerId = null;
|
||||||
|
|
||||||
|
// Toast
|
||||||
|
function showToast(text) {
|
||||||
|
const el = document.getElementById('toast');
|
||||||
|
el.textContent = text;
|
||||||
|
el.classList.add('show');
|
||||||
|
setTimeout(() => el.classList.remove('show'), 2500);
|
||||||
}
|
}
|
||||||
|
|
||||||
let servers = [];
|
// Fetch with auth
|
||||||
|
async function api(url, opts = {}) {
|
||||||
|
const resp = await fetch(url, {credentials: 'include', ...opts});
|
||||||
|
return resp.json();
|
||||||
|
}
|
||||||
|
|
||||||
async function loadServers() {
|
// Load all data
|
||||||
|
async function loadData() {
|
||||||
try {
|
try {
|
||||||
const resp = await fetch('/api/servers', {credentials: 'include'});
|
data = await api('/api/overview');
|
||||||
if (resp.status === 401) {
|
render();
|
||||||
document.getElementById('serverList').innerHTML =
|
|
||||||
'<li class="loading">Требуется авторизация в панели</li>';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
servers = await resp.json();
|
|
||||||
renderServers();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
document.getElementById('serverList').innerHTML =
|
document.getElementById('app').innerHTML = `
|
||||||
'<li class="loading">Ошибка загрузки</li>';
|
<div class="loading-screen">
|
||||||
|
<span style="font-size:32px">🔒</span>
|
||||||
|
<span style="opacity:0.5;font-size:13px">Авторизуйтесь в веб-панели</span>
|
||||||
|
</div>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderServers() {
|
function render() {
|
||||||
const list = document.getElementById('serverList');
|
if (!data) return;
|
||||||
const online = servers.filter(s => s.metrics?.online).length;
|
|
||||||
const offline = servers.length - online;
|
|
||||||
|
|
||||||
document.getElementById('total').textContent = servers.length;
|
const app = document.getElementById('app');
|
||||||
document.getElementById('online').textContent = online;
|
let html = '';
|
||||||
document.getElementById('offline').textContent = offline;
|
|
||||||
|
|
||||||
if (!servers.length) {
|
// Header
|
||||||
list.innerHTML = '<li class="loading">Нет серверов</li>';
|
html += `
|
||||||
return;
|
<div class="app-header">
|
||||||
}
|
<h1>🖥 VPS Monitor</h1>
|
||||||
|
<div class="stats-row">
|
||||||
list.innerHTML = servers.map((srv, i) => {
|
<div class="stat-pill">
|
||||||
const m = srv.metrics || {};
|
<span class="dot green"></span>
|
||||||
const isOnline = m.online;
|
${data.online} online
|
||||||
const cpu = m.cpu_percent || 0;
|
|
||||||
const ram = m.ram_percent || 0;
|
|
||||||
const disk = m.disk_percent || 0;
|
|
||||||
|
|
||||||
const cpuClass = cpu > 90 ? 'crit' : cpu > 70 ? 'warn' : '';
|
|
||||||
const ramClass = ram > 90 ? 'crit' : ram > 70 ? 'warn' : '';
|
|
||||||
const diskClass = disk > 90 ? 'crit' : disk > 70 ? 'warn' : '';
|
|
||||||
|
|
||||||
return `
|
|
||||||
<li class="server-item" onclick="toggleDetail(${i})">
|
|
||||||
<div class="server-info">
|
|
||||||
<div class="server-name">${srv.name}</div>
|
|
||||||
<div class="server-host">${srv.host}</div>
|
|
||||||
${isOnline ? `
|
|
||||||
<div class="server-metrics">
|
|
||||||
<span class="metric-badge ${cpuClass}">CPU ${cpu}%</span>
|
|
||||||
<span class="metric-badge ${ramClass}">RAM ${ram}%</span>
|
|
||||||
<span class="metric-badge ${diskClass}">Disk ${disk}%</span>
|
|
||||||
</div>` : ''}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="status-dot ${isOnline ? 'online' : 'offline'}"></div>
|
<div class="stat-pill">
|
||||||
</li>
|
<span class="dot ${data.offline > 0 ? 'red' : 'gray'}"></span>
|
||||||
<div class="server-detail" id="detail-${i}">
|
${data.offline} offline
|
||||||
<div class="detail-row"><span class="detail-label">Uptime</span><span class="detail-value">${m.uptime || 'N/A'}</span></div>
|
</div>
|
||||||
<div class="detail-row"><span class="detail-label">Load</span><span class="detail-value">${m.load_average || 'N/A'}</span></div>
|
<div class="stat-pill">
|
||||||
<div class="detail-row"><span class="detail-label">RAM</span><span class="detail-value">${(m.ram_used_mb||0).toFixed(0)} / ${(m.ram_total_mb||0).toFixed(0)} MB</span></div>
|
<span class="dot gray"></span>
|
||||||
<div class="detail-row"><span class="detail-label">Disk</span><span class="detail-value">${(m.disk_used_gb||0).toFixed(1)} / ${(m.disk_total_gb||0).toFixed(1)} GB</span></div>
|
${data.total} всего
|
||||||
<div class="detail-row"><span class="detail-label">Network In</span><span class="detail-value">${(m.network_in_mb||0).toFixed(0)} MB</span></div>
|
|
||||||
<div class="detail-row"><span class="detail-label">Network Out</span><span class="detail-value">${(m.network_out_mb||0).toFixed(0)} MB</span></div>
|
|
||||||
<div class="action-buttons">
|
|
||||||
<button class="action-btn" onclick="event.stopPropagation(); rebootServer('${srv.id || srv.host}')">🔄 Reboot</button>
|
|
||||||
<button class="action-btn danger" onclick="event.stopPropagation(); deleteServer('${srv.id || srv.host}')">🗑 Удалить</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
</div>`;
|
||||||
}).join('');
|
|
||||||
|
// Servers section
|
||||||
|
html += `<div class="section">
|
||||||
|
<div class="section-title">СЕРВЕРЫ</div>`;
|
||||||
|
|
||||||
|
data.servers.forEach((srv, idx) => {
|
||||||
|
const cpuClass = srv.cpu > 90 ? 'crit' : srv.cpu > 70 ? 'warn' : 'ok';
|
||||||
|
const ramClass = srv.ram > 90 ? 'crit' : srv.ram > 70 ? 'warn' : 'ok';
|
||||||
|
const diskClass = srv.disk > 90 ? 'crit' : srv.disk > 70 ? 'warn' : 'ok';
|
||||||
|
const isOpen = openServerId === srv.id;
|
||||||
|
|
||||||
|
html += `
|
||||||
|
<div class="card" onclick="toggleServer('${srv.id}')" style="${isOpen ? 'border-radius:14px 14px 0 0;margin-bottom:0' : ''}">
|
||||||
|
<div class="card-icon ${srv.online ? 'green' : 'red'}">
|
||||||
|
${srv.online ? '🟢' : '🔴'}
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-title">${srv.name}</div>
|
||||||
|
<div class="card-sub">${srv.host}${srv.online ? ' • CPU ' + srv.cpu + '% • RAM ' + srv.ram + '%' : ' • Недоступен'}</div>
|
||||||
|
</div>
|
||||||
|
<span class="card-badge ${srv.online ? 'online' : 'offline'}">${srv.online ? 'ON' : 'OFF'}</span>
|
||||||
|
<span class="card-chevron">${isOpen ? '▾' : '›'}</span>
|
||||||
|
</div>
|
||||||
|
<div class="server-detail ${isOpen ? 'open' : ''}" id="detail-${srv.id}">
|
||||||
|
<div class="server-detail-inner">
|
||||||
|
<div class="detail-grid">
|
||||||
|
<div class="detail-cell">
|
||||||
|
<div class="label">CPU</div>
|
||||||
|
<div class="val ${cpuClass}">${srv.cpu}%</div>
|
||||||
|
</div>
|
||||||
|
<div class="detail-cell">
|
||||||
|
<div class="label">RAM</div>
|
||||||
|
<div class="val ${ramClass}">${srv.ram}%</div>
|
||||||
|
</div>
|
||||||
|
<div class="detail-cell">
|
||||||
|
<div class="label">Disk</div>
|
||||||
|
<div class="val ${diskClass}">${srv.disk}%</div>
|
||||||
|
</div>
|
||||||
|
<div class="detail-cell">
|
||||||
|
<div class="label">Load</div>
|
||||||
|
<div class="val">${srv.load || '—'}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style="margin-top:8px;font-size:12px;color:var(--tg-theme-hint-color,#64748b)">
|
||||||
|
${srv.uptime || 'Uptime: N/A'}
|
||||||
|
</div>
|
||||||
|
<div class="detail-actions">
|
||||||
|
<button class="detail-btn primary" onclick="event.stopPropagation();rebootServer('${srv.id}','${srv.name}')">🔄 Reboot</button>
|
||||||
|
<button class="detail-btn danger" onclick="event.stopPropagation();deleteServer('${srv.id}','${srv.name}')">🗑 Удалить</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data.servers.length) {
|
||||||
|
html += `
|
||||||
|
<div class="card" style="justify-content:center;cursor:default">
|
||||||
|
<div class="card-body" style="text-align:center">
|
||||||
|
<div class="card-title" style="opacity:0.5">Нет серверов</div>
|
||||||
|
<div class="card-sub">Добавьте в веб-панели</div>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
html += `</div>`;
|
||||||
|
|
||||||
|
// Actions section
|
||||||
|
html += `
|
||||||
|
<div class="section">
|
||||||
|
<div class="section-title">ДЕЙСТВИЯ</div>
|
||||||
|
<div class="card" onclick="refreshAll()">
|
||||||
|
<div class="card-icon blue">🔄</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-title">Обновить данные</div>
|
||||||
|
<div class="card-sub">Принудительный опрос серверов</div>
|
||||||
|
</div>
|
||||||
|
<span class="card-chevron">›</span>
|
||||||
|
</div>
|
||||||
|
<div class="card" onclick="checkAll()">
|
||||||
|
<div class="card-icon green">✅</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-title">Проверка серверов</div>
|
||||||
|
<div class="card-sub">${data.online}/${data.total} доступны</div>
|
||||||
|
</div>
|
||||||
|
<span class="card-badge ${data.offline > 0 ? 'offline' : 'online'}">${data.offline > 0 ? data.offline + ' DOWN' : 'ALL OK'}</span>
|
||||||
|
<span class="card-chevron">›</span>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
// Notifications section
|
||||||
|
html += `
|
||||||
|
<div class="section">
|
||||||
|
<div class="section-title">УВЕДОМЛЕНИЯ</div>
|
||||||
|
${data.muted ? `
|
||||||
|
<div class="card" onclick="unmute()">
|
||||||
|
<div class="card-icon yellow">🔔</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-title">Снять mute</div>
|
||||||
|
<div class="card-sub">Уведомления приостановлены</div>
|
||||||
|
</div>
|
||||||
|
<span class="card-badge warn">MUTED</span>
|
||||||
|
<span class="card-chevron">›</span>
|
||||||
|
</div>
|
||||||
|
` : `
|
||||||
|
<div class="card" onclick="mute(2)">
|
||||||
|
<div class="card-icon red">🔕</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-title">Mute 2 часа</div>
|
||||||
|
<div class="card-sub">CRIT в Telegram остаются</div>
|
||||||
|
</div>
|
||||||
|
<span class="card-chevron">›</span>
|
||||||
|
</div>
|
||||||
|
<div class="card" onclick="mute(8)">
|
||||||
|
<div class="card-icon red">🔕</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-title">Mute 8 часов</div>
|
||||||
|
<div class="card-sub">Ночной режим</div>
|
||||||
|
</div>
|
||||||
|
<span class="card-chevron">›</span>
|
||||||
|
</div>
|
||||||
|
`}
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
// System section
|
||||||
|
html += `
|
||||||
|
<div class="section">
|
||||||
|
<div class="section-title">СИСТЕМА</div>
|
||||||
|
<div class="card" onclick="openPanel()">
|
||||||
|
<div class="card-icon cyan">🌐</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-title">Полная веб-панель</div>
|
||||||
|
<div class="card-sub">Дашборд в браузере</div>
|
||||||
|
</div>
|
||||||
|
<span class="card-chevron">›</span>
|
||||||
|
</div>
|
||||||
|
<div class="card" style="cursor:default">
|
||||||
|
<div class="card-icon purple">🔐</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-title">Сессия</div>
|
||||||
|
<div class="card-sub">Сессия активна</div>
|
||||||
|
</div>
|
||||||
|
<span class="card-badge online">OK</span>
|
||||||
|
<span class="card-chevron">›</span>
|
||||||
|
</div>
|
||||||
|
<div class="card" style="cursor:default">
|
||||||
|
<div class="card-icon blue">📊</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-title">Мониторинг</div>
|
||||||
|
<div class="card-sub">Интервал: 60 сек • Пороги: 90%</div>
|
||||||
|
</div>
|
||||||
|
<span class="card-badge online">ACTIVE</span>
|
||||||
|
<span class="card-chevron">›</span>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
app.innerHTML = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleDetail(idx) {
|
// Actions
|
||||||
const el = document.getElementById(`detail-${idx}`);
|
function toggleServer(id) {
|
||||||
el.classList.toggle('active');
|
openServerId = openServerId === id ? null : id;
|
||||||
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function rebootServer(id) {
|
async function rebootServer(id, name) {
|
||||||
if (!confirm('Перезагрузить сервер?')) return;
|
if (!confirm(`Перезагрузить ${name}?`)) return;
|
||||||
await fetch(`/api/servers/${id}/reboot`, {method: 'POST', credentials: 'include'});
|
await api(`/api/servers/${id}/reboot`, {method: 'POST'});
|
||||||
if (tg) tg.showAlert('Команда перезагрузки отправлена');
|
showToast('🔄 Reboot отправлен');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteServer(id) {
|
async function deleteServer(id, name) {
|
||||||
if (!confirm('Удалить сервер из мониторинга?')) return;
|
if (!confirm(`Удалить ${name}?`)) return;
|
||||||
await fetch(`/api/servers/${id}`, {method: 'DELETE', credentials: 'include'});
|
await api(`/api/servers/${id}`, {method: 'DELETE'});
|
||||||
loadServers();
|
showToast('🗑 Сервер удалён');
|
||||||
|
loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadServers();
|
async function refreshAll() {
|
||||||
setInterval(loadServers, 30000);
|
showToast('🔄 Обновление...');
|
||||||
|
await loadData();
|
||||||
|
showToast('✅ Данные обновлены');
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkAll() {
|
||||||
|
if (data.offline > 0) {
|
||||||
|
const names = data.servers.filter(s => !s.online).map(s => s.name).join(', ');
|
||||||
|
if (tg) tg.showAlert(`⚠️ Offline: ${names}`);
|
||||||
|
else alert(`Offline: ${names}`);
|
||||||
|
} else {
|
||||||
|
showToast('✅ Все серверы доступны');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function mute(hours) {
|
||||||
|
await api('/api/mute', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: JSON.stringify({hours})
|
||||||
|
});
|
||||||
|
showToast(`🔕 Mute ${hours}ч`);
|
||||||
|
loadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function unmute() {
|
||||||
|
await api('/api/unmute', {method: 'POST'});
|
||||||
|
showToast('🔔 Уведомления включены');
|
||||||
|
loadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
function openPanel() {
|
||||||
|
const url = `${location.protocol}//${location.host}/`;
|
||||||
|
if (tg) tg.openLink(url);
|
||||||
|
else window.open(url, '_blank');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init
|
||||||
|
loadData();
|
||||||
|
setInterval(loadData, 30000);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user