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 { 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/);
|
||||
});
|
||||
Reference in New Issue
Block a user