perf: fix dashboard out of memory crashing from massive historical metrics payloads

This commit is contained in:
SaelixCode
2026-03-19 19:59:40 -04:00
parent eb58f302a1
commit 4e9777d47f
3 changed files with 37 additions and 10 deletions
+14 -1
View File
@@ -324,7 +324,20 @@ export class DatabaseService {
public getContainerMetrics(hoursLookback = 24): any[] {
const cutoff = Date.now() - (hoursLookback * 60 * 60 * 1000);
const stmt = this.db.prepare('SELECT * FROM container_metrics WHERE timestamp >= ? ORDER BY timestamp ASC');
const stmt = this.db.prepare(`
SELECT
container_id,
stack_name,
AVG(cpu_percent) as cpu_percent,
AVG(memory_mb) as memory_mb,
MAX(net_rx_mb) as net_rx_mb,
MAX(net_tx_mb) as net_tx_mb,
(timestamp / 60000) * 60000 as timestamp
FROM container_metrics
WHERE timestamp >= ?
GROUP BY container_id, stack_name, (timestamp / 60000)
ORDER BY timestamp ASC
`);
return stmt.all(cutoff);
}