Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
monitor.html · 9.8 KB · 210 lines
| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="UTF-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | <title>DBBasic Real-time Monitor</title> |
| 7 | <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> |
| 8 | <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css"> |
| 9 | |
| 10 | <style> |
| 11 | .card { transition: transform 0.3s; } |
| 12 | .card:hover { transform: translateY(-5px); } |
| 13 | </style> |
| 14 | </head> |
| 15 | <body> |
| 16 | |
| 17 | <nav class="navbar navbar-expand-lg navbar-light bg-light"> |
| 18 | <div class="container-fluid"> |
| 19 | <a class="navbar-brand" href="#">DBBasic Monitor</a> |
| 20 | <div class="navbar-nav ms-auto"> |
| 21 | <a class="nav-link" href="http://localhost:8005">Dashboard</a> <a class="nav-link" href="http://localhost:8005">Data</a> <a class="nav-link" href="http://localhost:8003">AI Services</a> <a class="nav-link" href="http://localhost:8005/templates">Templates</a> |
| 22 | </div> |
| 23 | </div> |
| 24 | </nav><div class="container-fluid"><div class="text-center mb-4"><h1 class="display-4"><i class="bi bi-activity text-success"></i> Real-time Monitor</h1><span class="badge bg-success rounded-pill">⚡ 402M rows/sec</span></div> |
| 25 | <div class="container my-5"> |
| 26 | <div class="row row-cols-1 row-cols-md-4 g-4"> |
| 27 | <div class="col"> |
| 28 | <div class="card h-100"> |
| 29 | <div class="card-body"> |
| 30 | <div class="d-flex justify-content-between align-items-start mb-2"> |
| 31 | <h5 class="card-title">Operations/sec</h5> |
| 32 | |
| 33 | </div> |
| 34 | <p class="card-text"><h2 id="opsPerSec" class="text-primary">0</h2></p> |
| 35 | </div> |
| 36 | |
| 37 | </div></div> <div class="col"> |
| 38 | <div class="card h-100"> |
| 39 | <div class="card-body"> |
| 40 | <div class="d-flex justify-content-between align-items-start mb-2"> |
| 41 | <h5 class="card-title">Active Services</h5> |
| 42 | |
| 43 | </div> |
| 44 | <p class="card-text"><h2 id="activeServices" class="text-success">0</h2></p> |
| 45 | </div> |
| 46 | |
| 47 | </div></div> <div class="col"> |
| 48 | <div class="card h-100"> |
| 49 | <div class="card-body"> |
| 50 | <div class="d-flex justify-content-between align-items-start mb-2"> |
| 51 | <h5 class="card-title">Total Operations</h5> |
| 52 | |
| 53 | </div> |
| 54 | <p class="card-text"><h2 id="totalOps" class="text-info">0</h2></p> |
| 55 | </div> |
| 56 | |
| 57 | </div></div> <div class="col"> |
| 58 | <div class="card h-100"> |
| 59 | <div class="card-body"> |
| 60 | <div class="d-flex justify-content-between align-items-start mb-2"> |
| 61 | <h5 class="card-title">Connected Clients</h5> |
| 62 | |
| 63 | </div> |
| 64 | <p class="card-text"><h2 id="connectedClients" class="text-warning">0</h2></p> |
| 65 | </div> |
| 66 | |
| 67 | </div></div> |
| 68 | </div> |
| 69 | </div><div class="row mt-4"><div class="col-md-6"> |
| 70 | <div class="card h-100"> |
| 71 | <div class="card-body"> |
| 72 | <div class="d-flex justify-content-between align-items-start mb-2"> |
| 73 | <h5 class="card-title">📡 Live Service Calls</h5> |
| 74 | |
| 75 | </div> |
| 76 | <p class="card-text"></p> |
| 77 | </div> |
| 78 | |
| 79 | </div></div><div class="col-md-6"> |
| 80 | <div class="card h-100"> |
| 81 | <div class="card-body"> |
| 82 | <div class="d-flex justify-content-between align-items-start mb-2"> |
| 83 | <h5 class="card-title">💾 Database Operations</h5> |
| 84 | |
| 85 | </div> |
| 86 | <p class="card-text"></p> |
| 87 | </div> |
| 88 | |
| 89 | </div></div></div><div class="mt-4"> |
| 90 | <div class="card h-100"> |
| 91 | <div class="card-body"> |
| 92 | <div class="d-flex justify-content-between align-items-start mb-2"> |
| 93 | <h5 class="card-title">📊 Table Activity</h5> |
| 94 | |
| 95 | </div> |
| 96 | <p class="card-text"></p> |
| 97 | </div> |
| 98 | |
| 99 | </div></div><div class="mt-4 text-center"><div id="connectionStatus" class="badge bg-secondary">Connecting...</div></div> |
| 100 | <script> |
| 101 | let ws = null; |
| 102 | let reconnectInterval = null; |
| 103 | |
| 104 | function connectWebSocket() { |
| 105 | ws = new WebSocket('ws://localhost:8004/ws'); |
| 106 | |
| 107 | ws.onopen = function() { |
| 108 | document.getElementById('connectionStatus').className = 'badge bg-success'; |
| 109 | document.getElementById('connectionStatus').textContent = '🟢 Connected'; |
| 110 | clearInterval(reconnectInterval); |
| 111 | }; |
| 112 | |
| 113 | ws.onmessage = function(event) { |
| 114 | const data = JSON.parse(event.data); |
| 115 | |
| 116 | if (data.type === 'metrics') { |
| 117 | updateMetrics(data.data); |
| 118 | } else if (data.type === 'service_call') { |
| 119 | addServiceCall(data.data); |
| 120 | } else if (data.type === 'db_operation') { |
| 121 | addDbOperation(data.data); |
| 122 | } |
| 123 | }; |
| 124 | |
| 125 | ws.onclose = function() { |
| 126 | document.getElementById('connectionStatus').className = 'badge bg-danger'; |
| 127 | document.getElementById('connectionStatus').textContent = '🔴 Disconnected'; |
| 128 | |
| 129 | // Attempt to reconnect every 3 seconds |
| 130 | if (!reconnectInterval) { |
| 131 | reconnectInterval = setInterval(connectWebSocket, 3000); |
| 132 | } |
| 133 | }; |
| 134 | |
| 135 | ws.onerror = function(error) { |
| 136 | console.error('WebSocket error:', error); |
| 137 | }; |
| 138 | } |
| 139 | |
| 140 | function updateMetrics(metrics) { |
| 141 | document.getElementById('opsPerSec').textContent = |
| 142 | metrics.operations_per_second ? metrics.operations_per_second.toLocaleString() : '0'; |
| 143 | document.getElementById('activeServices').textContent = |
| 144 | metrics.active_services || '0'; |
| 145 | document.getElementById('totalOps').textContent = |
| 146 | metrics.total_operations ? metrics.total_operations.toLocaleString() : '0'; |
| 147 | document.getElementById('connectedClients').textContent = |
| 148 | metrics.active_connections || '0'; |
| 149 | } |
| 150 | |
| 151 | function addServiceCall(data) { |
| 152 | const feed = document.getElementById('serviceCalls'); |
| 153 | const entry = document.createElement('div'); |
| 154 | entry.className = 'alert alert-info py-2 mb-2'; |
| 155 | entry.innerHTML = ` |
| 156 | <small class="text-muted">${new Date(data.timestamp).toLocaleTimeString()}</small><br> |
| 157 | <strong>${data.service}</strong>: ${data.result} |
| 158 | `; |
| 159 | feed.insertBefore(entry, feed.firstChild); |
| 160 | |
| 161 | // Keep only last 20 entries |
| 162 | while (feed.children.length > 20) { |
| 163 | feed.removeChild(feed.lastChild); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | function addDbOperation(data) { |
| 168 | const feed = document.getElementById('dbOperations'); |
| 169 | const entry = document.createElement('div'); |
| 170 | entry.className = 'alert alert-success py-2 mb-2'; |
| 171 | entry.innerHTML = ` |
| 172 | <small class="text-muted">${new Date(data.timestamp).toLocaleTimeString()}</small><br> |
| 173 | <strong>${data.operation}</strong> on ${data.table}: ${data.count} rows |
| 174 | `; |
| 175 | feed.insertBefore(entry, feed.firstChild); |
| 176 | |
| 177 | // Update table stats |
| 178 | if (data.table) { |
| 179 | const opsElement = document.getElementById(data.table + '-ops'); |
| 180 | if (opsElement) { |
| 181 | const current = parseInt(opsElement.textContent) || 0; |
| 182 | opsElement.textContent = (current + 1).toLocaleString(); |
| 183 | } |
| 184 | |
| 185 | const rateElement = document.getElementById(data.table + '-rate'); |
| 186 | if (rateElement) { |
| 187 | rateElement.textContent = data.rate ? data.rate.toLocaleString() : '0'; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // Keep only last 20 entries |
| 192 | while (feed.children.length > 20) { |
| 193 | feed.removeChild(feed.lastChild); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Connect on page load |
| 198 | document.addEventListener('DOMContentLoaded', function() { |
| 199 | connectWebSocket(); |
| 200 | }); |
| 201 | </script> |
| 202 | </div> |
| 203 | <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> |
| 204 | |
| 205 | <script> |
| 206 | function deployTemplate(id) { alert('Deploying: ' + id); } |
| 207 | function previewTemplate(id) { alert('Preview: ' + id); } |
| 208 | </script> |
| 209 | </body> |
| 210 | </html> |