feat(telemetry): add canonical VPS host monitoring

This commit is contained in:
DCCONSTRUCTIONS
2026-08-22 17:29:30 +03:00
parent a3e7a015de
commit 23ea96fbb2
33 changed files with 2541 additions and 51 deletions
@@ -0,0 +1,37 @@
import assert from "node:assert/strict";
import test from "node:test";
import { createHostTelemetryCollector } from "./host-telemetry-runtime.mjs";
test("accepts Telegraf only on the bounded local collector", async () => {
let submitted = null;
const collector = createHostTelemetryCollector({
hostKey: "robot2b-b2-edge-vps",
host: "127.0.0.1",
port: 0,
submit: async (value) => { submitted = value; },
});
const address = await collector.start();
try {
const response = await fetch(`http://127.0.0.1:${address.port}/internal/v1/host-telemetry`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ metrics: [
{ name: "cpu", tags: { cpu: "cpu-total", host: "edge" }, fields: { usage_active: 9 }, timestamp: Math.floor(Date.now() / 1000) },
] }),
});
assert.equal(response.status, 202);
assert.equal(submitted.hostKey, "robot2b-b2-edge-vps");
assert.equal(collector.status().accepted, 1);
} finally {
await collector.stop();
}
});
test("rejects non-loopback collector binds", () => {
assert.throws(() => createHostTelemetryCollector({
hostKey: "host-01",
host: "0.0.0.0",
submit: async () => {},
}), /host_telemetry_host_invalid/);
});