feat(telemetry): add canonical VPS host monitoring
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
HOST_TELEMETRY_SCHEMA,
|
||||
telegrafBatchToHostTelemetry,
|
||||
} from "../src/index.mjs";
|
||||
|
||||
test("normalizes a bounded Telegraf Linux batch", () => {
|
||||
const value = telegrafBatchToHostTelemetry({ metrics: [
|
||||
{ name: "cpu", tags: { cpu: "cpu-total", host: "edge-01" }, fields: { usage_active: 21.5 }, timestamp: 1_777_000_000 },
|
||||
{ name: "mem", tags: { host: "edge-01" }, fields: { total: 1024, available: 700, used: 324, used_percent: 31.64 }, timestamp: 1_777_000_000 },
|
||||
{ name: "system", tags: { host: "edge-01" }, fields: { load1: 0.2, load5: 0.1, load15: 0.05, uptime: 120, n_users: 1 }, timestamp: 1_777_000_000 },
|
||||
{ name: "net", tags: { interface: "eth0", host: "edge-01" }, fields: { bytes_recv: 100, bytes_sent: 200 }, timestamp: 1_777_000_000 },
|
||||
{ name: "systemd_units", tags: { name: "nodedc-device-edge-channel.service", load: "loaded", active: "active", sub: "running" }, fields: { mem_current: 2048, restarts: 0, pid: 42 }, timestamp: 1_777_000_000 },
|
||||
] }, {
|
||||
hostKey: "robot2b-b2-edge-vps",
|
||||
architecture: "x64",
|
||||
kernelRelease: "6.8.0",
|
||||
cpuModel: "KVM CPU",
|
||||
logicalProcessors: 1,
|
||||
});
|
||||
|
||||
assert.equal(value.schemaVersion, HOST_TELEMETRY_SCHEMA);
|
||||
assert.equal(value.cpu.usagePercent, 21.5);
|
||||
assert.equal(value.memory.totalBytes, 1024);
|
||||
assert.equal(value.network[0].interface, "eth0");
|
||||
assert.equal(value.services[0].activeState, "active");
|
||||
assert.equal(Object.isFrozen(value), true);
|
||||
});
|
||||
|
||||
test("rejects an oversized Telegraf batch", () => {
|
||||
assert.throws(
|
||||
() => telegrafBatchToHostTelemetry({ metrics: Array.from({ length: 513 }, () => ({})) }, { hostKey: "host-01" }),
|
||||
/host_telemetry_telegraf_batch_invalid/,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user