forked from snxraven/peardock
Expand server history samples with network/block rates and longer retention, and rebuild the details Stats tab with live KPIs, 1m–30m windows, auto-scale, pause, CSV export, and CPU/memory/net/disk charts.
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
import test from 'brittle'
|
|
import {
|
|
recordSample,
|
|
getHistory,
|
|
pruneMissing,
|
|
clearHistory,
|
|
maxHistoryPoints,
|
|
} from '../server/services/stats-history.js'
|
|
|
|
test('stats history ring buffer', (t) => {
|
|
clearHistory()
|
|
const id = 'abc'
|
|
for (let i = 0; i < 5; i++) {
|
|
recordSample(id, { cpu: i, memory: i * 1000 })
|
|
}
|
|
const h = getHistory(id, { limit: 3 })
|
|
t.is(h.length, 3)
|
|
t.is(h[2].cpu, 4)
|
|
pruneMissing([])
|
|
t.is(getHistory(id).length, 0)
|
|
})
|
|
|
|
test('stats history stores io rates and supports since filter', (t) => {
|
|
clearHistory()
|
|
const id = 'io1'
|
|
const t0 = Date.now() - 10_000
|
|
// inject samples with forced timestamps via direct map is not exported;
|
|
// recordSample uses Date.now() — filter by since slightly in the past
|
|
recordSample(id, {
|
|
cpu: 1,
|
|
memory: 100,
|
|
memoryLimit: 1000,
|
|
netRxRate: 10,
|
|
netTxRate: 20,
|
|
blkReadRate: 30,
|
|
blkWriteRate: 40,
|
|
})
|
|
recordSample(id, {
|
|
cpu: 2,
|
|
memory: 200,
|
|
netRxRate: 11,
|
|
netTxRate: 21,
|
|
blkReadRate: 31,
|
|
blkWriteRate: 41,
|
|
})
|
|
const all = getHistory(id)
|
|
t.is(all.length, 2)
|
|
t.is(all[0].netRxRate, 10)
|
|
t.is(all[1].blkWriteRate, 41)
|
|
t.ok(all[0].memoryLimit === 1000 || all[0].memoryLimit === 0)
|
|
|
|
const future = getHistory(id, { since: Date.now() + 60_000 })
|
|
t.is(future.length, 0)
|
|
|
|
const recent = getHistory(id, { since: t0 })
|
|
t.is(recent.length, 2)
|
|
t.ok(maxHistoryPoints() >= 120)
|
|
})
|