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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="ar" dir="rtl">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Duck.ai API Dashboard</title>
|
| 7 |
+
<style>
|
| 8 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 9 |
+
body { background: #0f1117; color: #e0e0e0; font-family: 'Segoe UI', sans-serif; padding: 20px; }
|
| 10 |
+
h1 { text-align: center; color: #4fc3f7; margin-bottom: 24px; font-size: 1.6rem; }
|
| 11 |
+
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
|
| 12 |
+
.card { background: #1e2130; border-radius: 12px; padding: 20px; border: 1px solid #2a2d3e; }
|
| 13 |
+
.card .label { font-size: 0.8rem; color: #888; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 1px; }
|
| 14 |
+
.card .value { font-size: 2rem; font-weight: bold; }
|
| 15 |
+
.card .value.green { color: #69f0ae; }
|
| 16 |
+
.card .value.blue { color: #4fc3f7; }
|
| 17 |
+
.card .value.orange { color: #ffb74d; }
|
| 18 |
+
.card .value.red { color: #ef5350; }
|
| 19 |
+
.card .value.purple { color: #ce93d8; }
|
| 20 |
+
.section { background: #1e2130; border-radius: 12px; padding: 20px; margin-bottom: 20px; border: 1px solid #2a2d3e; }
|
| 21 |
+
.section h2 { color: #4fc3f7; margin-bottom: 16px; font-size: 1rem; }
|
| 22 |
+
table { width: 100%; border-collapse: collapse; }
|
| 23 |
+
th { text-align: right; padding: 10px; background: #252840; color: #aaa; font-size: 0.8rem; }
|
| 24 |
+
td { padding: 10px; border-bottom: 1px solid #2a2d3e; font-size: 0.9rem; }
|
| 25 |
+
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; }
|
| 26 |
+
.badge.busy { background: #ef535020; color: #ef5350; border: 1px solid #ef535050; }
|
| 27 |
+
.badge.free { background: #69f0ae20; color: #69f0ae; border: 1px solid #69f0ae50; }
|
| 28 |
+
.bar-wrap { background: #252840; border-radius: 20px; height: 10px; overflow: hidden; margin-top: 6px; }
|
| 29 |
+
.bar { height: 100%; border-radius: 20px; transition: width 0.5s; background: linear-gradient(90deg, #4fc3f7, #69f0ae); }
|
| 30 |
+
.bar.warn { background: linear-gradient(90deg, #ffb74d, #ef5350); }
|
| 31 |
+
.log-box { background: #0d1117; border-radius: 8px; padding: 14px; font-family: monospace; font-size: 0.8rem;
|
| 32 |
+
height: 220px; overflow-y: auto; color: #ccc; border: 1px solid #2a2d3e; }
|
| 33 |
+
.log-box .ok { color: #69f0ae; }
|
| 34 |
+
.log-box .err { color: #ef5350; }
|
| 35 |
+
.log-box .info { color: #4fc3f7; }
|
| 36 |
+
.log-box .warn { color: #ffb74d; }
|
| 37 |
+
.refresh-badge { text-align: center; color: #555; font-size: 0.75rem; margin-top: 10px; }
|
| 38 |
+
.chart-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
|
| 39 |
+
canvas { background: #141720; border-radius: 8px; border: 1px solid #2a2d3e; }
|
| 40 |
+
</style>
|
| 41 |
+
</head>
|
| 42 |
+
<body>
|
| 43 |
+
|
| 44 |
+
<h1>🦆 Duck.ai API — لوحة المراقبة</h1>
|
| 45 |
+
|
| 46 |
+
<!-- KPI Cards -->
|
| 47 |
+
<div class="grid">
|
| 48 |
+
<div class="card">
|
| 49 |
+
<div class="label">إجمالي الطلبات</div>
|
| 50 |
+
<div class="value blue" id="total_req">—</div>
|
| 51 |
+
</div>
|
| 52 |
+
<div class="card">
|
| 53 |
+
<div class="label">طلبات اليوم</div>
|
| 54 |
+
<div class="value green" id="today_req">—</div>
|
| 55 |
+
</div>
|
| 56 |
+
<div class="card">
|
| 57 |
+
<div class="label">مرفوضة (Queue Full)</div>
|
| 58 |
+
<div class="value red" id="rejected">—</div>
|
| 59 |
+
</div>
|
| 60 |
+
<div class="card">
|
| 61 |
+
<div class="label">Workers حرة</div>
|
| 62 |
+
<div class="value green" id="workers_free">—</div>
|
| 63 |
+
</div>
|
| 64 |
+
<div class="card">
|
| 65 |
+
<div class="label">Workers مشغولة</div>
|
| 66 |
+
<div class="value orange" id="workers_busy">—</div>
|
| 67 |
+
</div>
|
| 68 |
+
<div class="card">
|
| 69 |
+
<div class="label">RAM المستخدم</div>
|
| 70 |
+
<div class="value purple" id="ram_used">—</div>
|
| 71 |
+
</div>
|
| 72 |
+
<div class="card">
|
| 73 |
+
<div class="label">RAM الكلي</div>
|
| 74 |
+
<div class="value blue" id="ram_total">—</div>
|
| 75 |
+
</div>
|
| 76 |
+
<div class="card">
|
| 77 |
+
<div class="label">CPU %</div>
|
| 78 |
+
<div class="value orange" id="cpu">—</div>
|
| 79 |
+
</div>
|
| 80 |
+
</div>
|
| 81 |
+
|
| 82 |
+
<!-- Workers Table -->
|
| 83 |
+
<div class="section">
|
| 84 |
+
<h2>⚙️ حالة Workers</h2>
|
| 85 |
+
<table>
|
| 86 |
+
<thead>
|
| 87 |
+
<tr>
|
| 88 |
+
<th>Worker</th>
|
| 89 |
+
<th>الحالة</th>
|
| 90 |
+
<th>إجمالي الطلبات</th>
|
| 91 |
+
<th>حتى التجديد</th>
|
| 92 |
+
<th>شريط التقدم</th>
|
| 93 |
+
</tr>
|
| 94 |
+
</thead>
|
| 95 |
+
<tbody id="workers_table"></tbody>
|
| 96 |
+
</table>
|
| 97 |
+
</div>
|
| 98 |
+
|
| 99 |
+
<!-- Charts -->
|
| 100 |
+
<div class="chart-wrap" style="margin-bottom:20px;">
|
| 101 |
+
<div class="section" style="margin:0;">
|
| 102 |
+
<h2>📈 الطلبات (آخر 60 دقيقة)</h2>
|
| 103 |
+
<canvas id="reqChart" height="120"></canvas>
|
| 104 |
+
</div>
|
| 105 |
+
<div class="section" style="margin:0;">
|
| 106 |
+
<h2>💾 RAM % (آخر 60 دقيقة)</h2>
|
| 107 |
+
<canvas id="ramChart" height="120"></canvas>
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
<!-- Live Log -->
|
| 112 |
+
<div class="section">
|
| 113 |
+
<h2>📋 السجل المباشر</h2>
|
| 114 |
+
<div class="log-box" id="log_box"></div>
|
| 115 |
+
</div>
|
| 116 |
+
|
| 117 |
+
<div class="refresh-badge">يتجدد كل <span id="interval_val">5</span> ثوان • آخر تحديث: <span id="last_update">—</span></div>
|
| 118 |
+
|
| 119 |
+
<script>
|
| 120 |
+
const REFRESH = 5000;
|
| 121 |
+
let reqHistory = Array(60).fill(0);
|
| 122 |
+
let ramHistory = Array(60).fill(0);
|
| 123 |
+
let logs = [];
|
| 124 |
+
let lastTotal = 0;
|
| 125 |
+
|
| 126 |
+
const todayKey = () => new Date().toISOString().slice(0,10);
|
| 127 |
+
let todayCount = parseInt(localStorage.getItem('today_' + todayKey()) || '0');
|
| 128 |
+
let lastDay = localStorage.getItem('last_day') || todayKey();
|
| 129 |
+
|
| 130 |
+
async function fetchData() {
|
| 131 |
+
try {
|
| 132 |
+
const r = await fetch('/health');
|
| 133 |
+
const d = await r.json();
|
| 134 |
+
|
| 135 |
+
// KPIs
|
| 136 |
+
document.getElementById('total_req').textContent = d.total_requests ?? '—';
|
| 137 |
+
document.getElementById('rejected').textContent = d.rejected_requests ?? 0;
|
| 138 |
+
document.getElementById('workers_free').textContent = d.workers_free ?? '—';
|
| 139 |
+
document.getElementById('workers_busy').textContent = d.workers_busy ?? '—';
|
| 140 |
+
|
| 141 |
+
if (d.ram) {
|
| 142 |
+
document.getElementById('ram_used').textContent = d.ram.used_gb + ' GB';
|
| 143 |
+
document.getElementById('ram_total').textContent = d.ram.total_gb + ' GB';
|
| 144 |
+
}
|
| 145 |
+
if (d.cpu !== undefined) {
|
| 146 |
+
document.getElementById('cpu').textContent = d.cpu + '%';
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
// Today counter
|
| 150 |
+
const diff = (d.total_requests ?? 0) - lastTotal;
|
| 151 |
+
if (diff > 0) {
|
| 152 |
+
if (lastDay !== todayKey()) {
|
| 153 |
+
todayCount = 0;
|
| 154 |
+
lastDay = todayKey();
|
| 155 |
+
localStorage.setItem('last_day', lastDay);
|
| 156 |
+
}
|
| 157 |
+
todayCount += diff;
|
| 158 |
+
localStorage.setItem('today_' + todayKey(), todayCount);
|
| 159 |
+
lastTotal = d.total_requests ?? 0;
|
| 160 |
+
}
|
| 161 |
+
document.getElementById('today_req').textContent = todayCount;
|
| 162 |
+
|
| 163 |
+
// Workers table
|
| 164 |
+
const tbody = document.getElementById('workers_table');
|
| 165 |
+
tbody.innerHTML = '';
|
| 166 |
+
(d.workers || []).forEach(w => {
|
| 167 |
+
const pct = Math.round(((30 - w.requests_until_rotation) / 30) * 100);
|
| 168 |
+
const warn = pct > 80 ? 'warn' : '';
|
| 169 |
+
tbody.innerHTML += `
|
| 170 |
+
<tr>
|
| 171 |
+
<td>W${w.id}</td>
|
| 172 |
+
<td><span class="badge ${w.busy ? 'busy' : 'free'}">${w.busy ? '🔴 مشغول' : '🟢 حر'}</span></td>
|
| 173 |
+
<td>${w.total_requests}</td>
|
| 174 |
+
<td>${w.requests_until_rotation}</td>
|
| 175 |
+
<td style="width:160px">
|
| 176 |
+
<div class="bar-wrap"><div class="bar ${warn}" style="width:${pct}%"></div></div>
|
| 177 |
+
</td>
|
| 178 |
+
</tr>`;
|
| 179 |
+
});
|
| 180 |
+
|
| 181 |
+
// History
|
| 182 |
+
reqHistory.push(diff > 0 ? diff : 0); reqHistory.shift();
|
| 183 |
+
if (d.ram) { ramHistory.push(d.ram.percent); ramHistory.shift(); }
|
| 184 |
+
|
| 185 |
+
drawChart('reqChart', reqHistory, '#4fc3f7');
|
| 186 |
+
drawChart('ramChart', ramHistory, '#ce93d8', 100);
|
| 187 |
+
|
| 188 |
+
// Log
|
| 189 |
+
addLog(`✓ total=${d.total_requests} | free=${d.workers_free} | busy=${d.workers_busy}`, 'ok');
|
| 190 |
+
|
| 191 |
+
document.getElementById('last_update').textContent = new Date().toLocaleTimeString('ar-EG');
|
| 192 |
+
|
| 193 |
+
} catch(e) {
|
| 194 |
+
addLog('❌ فشل الاتصال: ' + e.message, 'err');
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
function addLog(msg, cls='info') {
|
| 199 |
+
const now = new Date().toLocaleTimeString('ar-EG');
|
| 200 |
+
logs.unshift(`<span class="${cls}">[${now}] ${msg}</span>`);
|
| 201 |
+
if (logs.length > 80) logs.pop();
|
| 202 |
+
document.getElementById('log_box').innerHTML = logs.join('<br>');
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
function drawChart(id, data, color, maxVal = null) {
|
| 206 |
+
const canvas = document.getElementById(id);
|
| 207 |
+
const ctx = canvas.getContext('2d');
|
| 208 |
+
canvas.width = canvas.offsetWidth;
|
| 209 |
+
canvas.height = 120;
|
| 210 |
+
const W = canvas.width, H = canvas.height;
|
| 211 |
+
const max = maxVal ?? (Math.max(...data, 1));
|
| 212 |
+
ctx.clearRect(0,0,W,H);
|
| 213 |
+
|
| 214 |
+
// grid lines
|
| 215 |
+
ctx.strokeStyle = '#2a2d3e'; ctx.lineWidth = 1;
|
| 216 |
+
[0.25, 0.5, 0.75].forEach(f => {
|
| 217 |
+
ctx.beginPath(); ctx.moveTo(0, H*f); ctx.lineTo(W, H*f); ctx.stroke();
|
| 218 |
+
});
|
| 219 |
+
|
| 220 |
+
// area
|
| 221 |
+
const step = W / (data.length - 1);
|
| 222 |
+
ctx.beginPath();
|
| 223 |
+
data.forEach((v, i) => {
|
| 224 |
+
const x = i * step, y = H - (v / max) * (H - 10) - 5;
|
| 225 |
+
i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
|
| 226 |
+
});
|
| 227 |
+
ctx.strokeStyle = color; ctx.lineWidth = 2; ctx.stroke();
|
| 228 |
+
|
| 229 |
+
ctx.lineTo(W, H); ctx.lineTo(0, H); ctx.closePath();
|
| 230 |
+
ctx.fillStyle = color + '22'; ctx.fill();
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
document.getElementById('interval_val').textContent = REFRESH / 1000;
|
| 234 |
+
fetchData();
|
| 235 |
+
setInterval(fetchData, REFRESH);
|
| 236 |
+
</script>
|
| 237 |
+
</body>
|
| 238 |
+
</html>
|