33 lines
1001 B
JavaScript
33 lines
1001 B
JavaScript
import test from 'brittle'
|
|
import { MetricsCollector } from '../server/services/collector.js'
|
|
import { CHART_BY_ID, getAllChartDefs } from '../shared/metrics.js'
|
|
|
|
test('collector emits core system charts', async (t) => {
|
|
const c = new MetricsCollector({ intervalMs: 50 })
|
|
/** @type {any[]} */
|
|
let batch = []
|
|
c.once('samples', (b) => {
|
|
batch = b
|
|
})
|
|
c.start()
|
|
await new Promise((r) => setTimeout(r, 80))
|
|
c.stop()
|
|
|
|
t.ok(batch.length > 5)
|
|
const charts = new Set(batch.map((s) => s.chart))
|
|
t.ok(charts.has('system.cpu'))
|
|
t.ok(charts.has('system.ram') || charts.has('mem.available'))
|
|
t.ok(charts.has('system.load'))
|
|
t.ok(charts.has('system.uptime'))
|
|
|
|
const cpu = batch.find((s) => s.chart === 'system.cpu')
|
|
t.ok(cpu)
|
|
for (const dim of ['user', 'system', 'idle', 'iowait', 'steal']) {
|
|
t.ok(dim in cpu.values, dim)
|
|
}
|
|
|
|
// runtime instance charts should be registered after first tick
|
|
t.ok(getAllChartDefs().length >= 30)
|
|
t.ok(CHART_BY_ID.has('system.cpu'))
|
|
})
|