Spaces:
Sleeping
Sleeping
Update central/src/index.js
Browse files- central/src/index.js +17 -7
central/src/index.js
CHANGED
|
@@ -75,14 +75,24 @@ const adminAuth = (req, res, next) => {
|
|
| 75 |
const translate = require('@vitalets/google-translate-api');
|
| 76 |
|
| 77 |
// Metrics collection
|
|
|
|
|
|
|
|
|
|
| 78 |
setInterval(() => {
|
| 79 |
-
const cpuUsage = process.cpuUsage();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
const memUsage = process.memoryUsage();
|
| 81 |
-
const totalMem = os.totalmem();
|
| 82 |
-
const freeMem = os.freemem();
|
| 83 |
|
| 84 |
-
metrics.cpuHistory.push({ timestamp: Date.now(), cpu:
|
| 85 |
-
metrics.ramHistory.push({ timestamp: Date.now(), used:
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
// Keep only last metricsWindowSeconds
|
| 88 |
const cutoff = Date.now() - settings.metricsWindowSeconds * 1000;
|
|
@@ -262,8 +272,8 @@ function dispatchToWorker(worker, job) {
|
|
| 262 |
});
|
| 263 |
}
|
| 264 |
|
| 265 |
-
// Admin dashboard
|
| 266 |
-
app.get('/admin',
|
| 267 |
res.sendFile(path.join(__dirname, '../../public/admin.html'));
|
| 268 |
});
|
| 269 |
|
|
|
|
| 75 |
const translate = require('@vitalets/google-translate-api');
|
| 76 |
|
| 77 |
// Metrics collection
|
| 78 |
+
let prevCpu = process.cpuUsage();
|
| 79 |
+
let prevTime = process.hrtime.bigint();
|
| 80 |
+
|
| 81 |
setInterval(() => {
|
| 82 |
+
const cpuUsage = process.cpuUsage(prevCpu);
|
| 83 |
+
const currentTime = process.hrtime.bigint();
|
| 84 |
+
const elapsedNs = Number(currentTime - prevTime);
|
| 85 |
+
const elapsedUs = elapsedNs / 1000;
|
| 86 |
+
|
| 87 |
+
const cpuPercent = Math.min(100, ((cpuUsage.user + cpuUsage.system) / elapsedUs) * 100);
|
| 88 |
+
|
| 89 |
const memUsage = process.memoryUsage();
|
|
|
|
|
|
|
| 90 |
|
| 91 |
+
metrics.cpuHistory.push({ timestamp: Date.now(), cpu: Math.round(cpuPercent * 10) / 10 });
|
| 92 |
+
metrics.ramHistory.push({ timestamp: Date.now(), used: memUsage.heapUsed, total: memUsage.heapTotal });
|
| 93 |
+
|
| 94 |
+
prevCpu = process.cpuUsage();
|
| 95 |
+
prevTime = currentTime;
|
| 96 |
|
| 97 |
// Keep only last metricsWindowSeconds
|
| 98 |
const cutoff = Date.now() - settings.metricsWindowSeconds * 1000;
|
|
|
|
| 272 |
});
|
| 273 |
}
|
| 274 |
|
| 275 |
+
// Admin dashboard page (auth handled client-side via modal)
|
| 276 |
+
app.get('/admin', (req, res) => {
|
| 277 |
res.sendFile(path.join(__dirname, '../../public/admin.html'));
|
| 278 |
});
|
| 279 |
|