Files
2026-10-30 16:35:46 +02:00

495 lines
24 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="DB Monitor - Self-hosted PostgreSQL monitoring dashboard with real-time metrics, charts, and alerts">
<title>DB Monitor — PostgreSQL Monitoring</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/css/style.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.4/dist/chart.umd.min.js"></script>
</head>
<body>
<!-- Header -->
<header id="app-header">
<div class="header-left">
<div class="logo">
<svg width="32" height="32" viewBox="0 0 32 32" fill="none">
<rect width="32" height="32" rx="8" fill="url(#logo-grad)"/>
<path d="M8 12C8 10 12 8 16 8C20 8 24 10 24 12C24 14 20 16 16 16C12 16 8 14 8 12Z" fill="white" opacity="0.9"/>
<path d="M8 12V16C8 18 12 20 16 20C20 20 24 18 24 16V12" stroke="white" stroke-width="1.5" opacity="0.7"/>
<path d="M8 16V20C8 22 12 24 16 24C20 24 24 22 24 20V16" stroke="white" stroke-width="1.5" opacity="0.5"/>
<defs>
<linearGradient id="logo-grad" x1="0" y1="0" x2="32" y2="32">
<stop stop-color="#6366f1"/>
<stop offset="1" stop-color="#8b5cf6"/>
</linearGradient>
</defs>
</svg>
</div>
<div class="header-title">
<h1>DB Monitor</h1>
<span class="header-subtitle">PostgreSQL Monitoring</span>
</div>
</div>
<div class="header-right">
<a href="/settings.html" class="settings-btn" title="Settings">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="3"/>
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
</svg>
</a>
<div class="db-selector-wrap">
<select id="db-selector" aria-label="Select database"></select>
</div>
<div class="refresh-info">
<span class="pulse-dot"></span>
<span id="last-update">Connecting...</span>
</div>
</div>
</header>
<main id="dashboard">
<!-- All Databases Overview -->
<section id="db-overview">
<h2 class="section-title">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/>
<rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/>
</svg>
All Databases
</h2>
<div id="db-overview-grid"></div>
</section>
<!-- Status Banner -->
<section id="status-banner" class="status-up">
<div class="status-icon" id="status-icon">
<svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
<polyline points="22 4 12 14.01 9 11.01"/>
</svg>
</div>
<div class="status-text">
<h2 id="status-label">PostgreSQL</h2>
<p id="status-detail">Checking connection...</p>
</div>
<div class="status-meta">
<div class="meta-item">
<span class="meta-label">Latency</span>
<span class="meta-value" id="latency-value">—</span>
</div>
<div class="meta-item">
<span class="meta-label">Version</span>
<span class="meta-value" id="version-value">—</span>
</div>
<div class="meta-item">
<span class="meta-label">Uptime</span>
<span class="meta-value" id="uptime-value">—</span>
</div>
</div>
</section>
<!-- Metrics Cards Grid -->
<section id="metrics-grid">
<!-- Connections Card -->
<div class="metric-card" id="card-connections">
<div class="card-header">
<div class="card-icon connections-icon">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/>
<circle cx="9" cy="7" r="4"/>
<path d="M23 21v-2a4 4 0 0 0-3-3.87"/>
<path d="M16 3.13a4 4 0 0 1 0 7.75"/>
</svg>
</div>
<h3>Connections</h3>
</div>
<div class="card-body">
<div class="card-big-number" id="conn-total">—</div>
<div class="card-big-label">Total Connections</div>
<div class="card-progress">
<div class="progress-bar">
<div class="progress-fill" id="conn-progress-fill" style="width: 0%"></div>
</div>
<span class="progress-text" id="conn-progress-text">0%</span>
</div>
<div class="card-details">
<div class="detail-row">
<span>Active</span>
<span class="detail-value" id="conn-active">—</span>
</div>
<div class="detail-row">
<span>Idle</span>
<span class="detail-value" id="conn-idle">—</span>
</div>
<div class="detail-row">
<span>Max</span>
<span class="detail-value" id="conn-max">—</span>
</div>
</div>
</div>
</div>
<!-- Queries Card -->
<div class="metric-card" id="card-queries">
<div class="card-header">
<div class="card-icon queries-icon">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="16 18 22 12 16 6"/>
<polyline points="8 6 2 12 8 18"/>
</svg>
</div>
<h3>Queries</h3>
</div>
<div class="card-body">
<div class="card-big-number" id="query-active">—</div>
<div class="card-big-label">Active Queries</div>
<div class="card-details">
<div class="detail-row">
<span>Long Running (&gt;5m)</span>
<span class="detail-value warning-value" id="query-long">—</span>
</div>
<div class="detail-row">
<span>Waiting</span>
<span class="detail-value" id="query-waiting">—</span>
</div>
</div>
</div>
</div>
<!-- Database Size Card -->
<div class="metric-card" id="card-size">
<div class="card-header">
<div class="card-icon size-icon">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<ellipse cx="12" cy="5" rx="9" ry="3"/>
<path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/>
<path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/>
</svg>
</div>
<h3>Database Size</h3>
</div>
<div class="card-body">
<div class="card-big-number" id="db-size">—</div>
<div class="card-big-label" id="db-size-label">Total Size</div>
</div>
</div>
<!-- Cache & Transactions Card -->
<div class="metric-card" id="card-cache">
<div class="card-header">
<div class="card-icon cache-icon">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/>
</svg>
</div>
<h3>Performance</h3>
</div>
<div class="card-body">
<div class="card-big-number" id="cache-ratio">—</div>
<div class="card-big-label">Cache Hit Ratio</div>
<div class="card-details">
<div class="detail-row">
<span>Commits</span>
<span class="detail-value" id="tx-commit">—</span>
</div>
<div class="detail-row">
<span>Rollbacks</span>
<span class="detail-value" id="tx-rollback">—</span>
</div>
</div>
</div>
</div>
<!-- Locks Card -->
<div class="metric-card" id="card-locks">
<div class="card-header">
<div class="card-icon locks-icon">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
</svg>
</div>
<h3>Locks</h3>
</div>
<div class="card-body">
<div class="card-big-number" id="locks-active">—</div>
<div class="card-big-label">Active Locks</div>
<div class="card-details">
<div class="detail-row">
<span>Waiting</span>
<span class="detail-value warning-value" id="locks-waiting">—</span>
</div>
<div class="detail-row">
<span>Deadlocks</span>
<span class="detail-value danger-value" id="locks-deadlocks">—</span>
</div>
</div>
</div>
</div>
<!-- Row Activity Card -->
<div class="metric-card" id="card-rows">
<div class="card-header">
<div class="card-icon rows-icon">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
<polyline points="14 2 14 8 20 8"/>
<line x1="16" y1="13" x2="8" y2="13"/>
<line x1="16" y1="17" x2="8" y2="17"/>
</svg>
</div>
<h3>Row Activity</h3>
</div>
<div class="card-body">
<div class="card-big-number" id="rows-fetched">—</div>
<div class="card-big-label">Rows Fetched</div>
<div class="card-details">
<div class="detail-row">
<span>Inserted</span>
<span class="detail-value insert-value" id="rows-inserted">—</span>
</div>
<div class="detail-row">
<span>Updated</span>
<span class="detail-value update-value" id="rows-updated">—</span>
</div>
<div class="detail-row">
<span>Deleted</span>
<span class="detail-value danger-value" id="rows-deleted">—</span>
</div>
</div>
</div>
</div>
<!-- Replication Card -->
<div class="metric-card" id="card-replication">
<div class="card-header">
<div class="card-icon replication-icon">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="17 1 21 5 17 9"/>
<path d="M3 11V9a4 4 0 0 1 4-4h14"/>
<polyline points="7 23 3 19 7 15"/>
<path d="M21 13v2a4 4 0 0 1-4 4H3"/>
</svg>
</div>
<h3>Replication</h3>
</div>
<div class="card-body">
<div class="card-big-number" id="repl-status">—</div>
<div class="card-big-label" id="repl-label">Status</div>
<div class="card-details">
<div class="detail-row">
<span>Lag</span>
<span class="detail-value" id="repl-lag">—</span>
</div>
</div>
</div>
</div>
<!-- I/O Card -->
<div class="metric-card" id="card-io">
<div class="card-header">
<div class="card-icon io-icon">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/>
</svg>
</div>
<h3>Block I/O</h3>
</div>
<div class="card-body">
<div class="card-big-number" id="io-hit">—</div>
<div class="card-big-label">Blocks Hit (Cache)</div>
<div class="card-details">
<div class="detail-row">
<span>Blocks Read (Disk)</span>
<span class="detail-value" id="io-read">—</span>
</div>
<div class="detail-row">
<span>Temp Files</span>
<span class="detail-value" id="io-tempfiles">—</span>
</div>
<div class="detail-row">
<span>Temp Size</span>
<span class="detail-value" id="io-tempbytes">—</span>
</div>
</div>
</div>
</div>
</section>
<!-- Charts Section -->
<section id="charts-section">
<div class="chart-card">
<div class="chart-header">
<h3>Connections Over Time</h3>
<div class="chart-controls">
<button class="chart-range active" data-range="60">1h</button>
<button class="chart-range" data-range="360">6h</button>
<button class="chart-range" data-range="1440">24h</button>
</div>
</div>
<div class="chart-container">
<canvas id="chart-connections"></canvas>
</div>
</div>
<div class="chart-card">
<div class="chart-header">
<h3>Cache Hit Ratio</h3>
<div class="chart-controls">
<button class="chart-range active" data-range="60">1h</button>
<button class="chart-range" data-range="360">6h</button>
<button class="chart-range" data-range="1440">24h</button>
</div>
</div>
<div class="chart-container">
<canvas id="chart-cache"></canvas>
</div>
</div>
<div class="chart-card">
<div class="chart-header">
<h3>Latency Over Time</h3>
<div class="chart-controls">
<button class="chart-range active" data-range="60">1h</button>
<button class="chart-range" data-range="360">6h</button>
<button class="chart-range" data-range="1440">24h</button>
</div>
</div>
<div class="chart-container">
<canvas id="chart-latency"></canvas>
</div>
</div>
<div class="chart-card">
<div class="chart-header">
<h3>Transaction Throughput</h3>
<div class="chart-controls">
<button class="chart-range active" data-range="60">1h</button>
<button class="chart-range" data-range="360">6h</button>
<button class="chart-range" data-range="1440">24h</button>
</div>
</div>
<div class="chart-container">
<canvas id="chart-tps"></canvas>
</div>
</div>
<div class="chart-card">
<div class="chart-header">
<h3>Database Size Over Time</h3>
<div class="chart-controls">
<button class="chart-range active" data-range="60">1h</button>
<button class="chart-range" data-range="360">6h</button>
<button class="chart-range" data-range="1440">24h</button>
</div>
</div>
<div class="chart-container">
<canvas id="chart-dbsize"></canvas>
</div>
</div>
<div class="chart-card">
<div class="chart-header">
<h3>Locks Over Time</h3>
<div class="chart-controls">
<button class="chart-range active" data-range="60">1h</button>
<button class="chart-range" data-range="360">6h</button>
<button class="chart-range" data-range="1440">24h</button>
</div>
</div>
<div class="chart-container">
<canvas id="chart-locks"></canvas>
</div>
</div>
<div class="chart-card full-width">
<div class="chart-header">
<h3>Query Activity</h3>
<div class="chart-controls">
<button class="chart-range active" data-range="60">1h</button>
<button class="chart-range" data-range="360">6h</button>
<button class="chart-range" data-range="1440">24h</button>
</div>
</div>
<div class="chart-container">
<canvas id="chart-queries"></canvas>
</div>
</div>
</section>
<!-- Table Stats Section -->
<section id="table-stats-section">
<div class="data-panel">
<div class="panel-header">
<h3>
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 3v18"/>
<rect x="4" y="8" width="4" height="13" rx="1"/>
<rect x="10" y="5" width="4" height="16" rx="1"/>
<rect x="16" y="11" width="4" height="10" rx="1"/>
</svg>
Top Tables by Size
</h3>
</div>
<div class="panel-body">
<table class="data-table" id="table-stats-table">
<thead>
<tr>
<th>Table</th>
<th>Size</th>
<th class="hide-mobile">Rows</th>
<th class="hide-mobile">Dead Tuples</th>
<th>Size Bar</th>
</tr>
</thead>
<tbody id="table-stats-body">
<tr><td colspan="5" class="empty-state">Waiting for data...</td></tr>
</tbody>
</table>
</div>
</div>
</section>
<!-- Active Queries Section -->
<section id="queries-section">
<div class="data-panel">
<div class="panel-header">
<h3>
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"/>
<polyline points="12 6 12 12 16 14"/>
</svg>
Active Queries
</h3>
<span class="badge" id="running-queries-count">0</span>
</div>
<div class="panel-body">
<table class="data-table" id="queries-table">
<thead>
<tr>
<th>PID</th>
<th>Duration</th>
<th>State</th>
<th class="hide-mobile">User</th>
<th>Query</th>
</tr>
</thead>
<tbody id="queries-body">
<tr><td colspan="5" class="empty-state">No active queries</td></tr>
</tbody>
</table>
</div>
</div>
</section>
</main>
<!-- Footer -->
<footer id="app-footer">
<span>DB Monitor</span>
<span class="footer-sep">·</span>
<span>Open Source PostgreSQL Monitoring</span>
<span class="footer-sep">·</span>
<a href="https://github.com/mahmoud/db-monitor" target="_blank" rel="noopener">GitHub</a>
</footer>
<script src="/js/app.js"></script>
</body>
</html>