Files
peardata/test/host-deep.test.js
T
Raven Scott 2e1a3e9b06
CI / test (push) Successful in 1m24s
Release rolling / release (push) Has been cancelled
Updates
2026-07-18 19:44:32 -04:00

45 lines
1.6 KiB
JavaScript

import test from 'brittle'
import { DEEP_STATIC_CHARTS } from '../shared/metrics-deep.js'
import { STATIC_CHART_DEFS, CHART_BY_ID } from '../shared/metrics.js'
import { parseSoftnet, parsePressureFull, parseNetstatTables } from '../server/services/collectors/host-deep.js'
import { MetricsCollector } from '../server/services/collector.js'
test('deep static charts are merged into catalog', (t) => {
t.ok(DEEP_STATIC_CHARTS.length > 20)
t.ok(STATIC_CHART_DEFS.length >= 35 + DEEP_STATIC_CHARTS.length)
for (const id of ['mem.zswap', 'mem.reclaiming', 'ip.tcpsyncookies', 'system.softnet_stat']) {
t.ok(CHART_BY_ID.has(id), id)
}
})
test('host-deep parsers tolerate missing proc', (t) => {
const soft = parseSoftnet()
t.ok(typeof soft.processed === 'number')
const tables = parseNetstatTables()
t.ok(tables.TcpExt)
// may be null off Linux
const p = parsePressureFull('cpu')
t.ok(p === null || typeof p.some10 === 'number')
})
test('collector emits expanded disk/net charts on Linux', async (t) => {
const c = new MetricsCollector({ intervalMs: 40 })
/** @type {any[]} */
let batch = []
c.on('samples', (b) => {
batch = b
})
c.start()
await new Promise((r) => setTimeout(r, 100))
c.stop()
t.ok(batch.length > 5)
const charts = new Set(batch.map((s) => s.chart))
t.ok(charts.has('system.cpu'))
// expanded dims present when meminfo exists
const kernel = batch.find((s) => s.chart === 'mem.kernel')
if (kernel) t.ok('percpu' in kernel.values)
const wb = batch.find((s) => s.chart === 'mem.writeback')
if (wb) t.ok('Bounce' in wb.values)
})