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
@@ -14,6 +14,9 @@ import {
normalizeAdapterMessage,
normalizeDiscoverySignal,
} from "../../../packages/device-protocol-contract/src/index.mjs";
import {
normalizeHostTelemetrySnapshot,
} from "../../../packages/infrastructure-telemetry-contract/src/index.mjs";
const CHANNEL_TRACKER_SESSION_ID = "channel:control";
const CHANNEL_PROFILE_REF = "channel.control.v1";
@@ -195,6 +198,20 @@ export function createDeviceEdgeChannelServer(options = {}) {
}
return Object.freeze({ status: "recorded" });
},
async submitHostTelemetry(snapshot) {
const normalized = normalizeHostTelemetrySnapshot(snapshot);
const result = await submitEvent("host.telemetry.observed", {
snapshot: normalized,
}, {
trackerSessionId: `host-telemetry:${normalized.hostKey}`,
adapterProfileRef: normalized.profile,
eventAt: normalized.observedAt,
});
if (result?.status !== "recorded") {
throw new Error("device_edge_channel_host_telemetry_invalid");
}
return Object.freeze({ status: "recorded" });
},
status() {
return Object.freeze({
listening: started,
@@ -68,6 +68,33 @@ test("accepts synthetic discovery and durable message results over Core-initiate
}
});
test("delivers a normalized host observation over the existing pinned mTLS channel", async () => {
const recorded = [];
const pair = await startPair({
recordHostTelemetry: async (snapshot, context) => {
recorded.push({ snapshot, context });
return { status: "recorded" };
},
});
try {
const observation = hostTelemetrySnapshot();
assert.deepEqual(await pair.edge.submitHostTelemetry(observation), {
status: "recorded",
});
assert.equal(recorded.length, 1);
assert.equal(recorded[0].snapshot.hostKey, "robot2b-b2-edge-vps");
assert.equal(
recorded[0].context.authenticatedEdgeRef,
"edge:pilot-1",
);
assert.equal(pair.edge.status().eventsAccepted, 1);
assert.equal(pair.core.status().eventsAccepted, 1);
} finally {
await stopPair(pair);
}
});
test("recovers the claimed device from telemetry after a Core restart and completes a typed command", async () => {
const commandRef = "command:11111111-1111-4111-8111-111111111111";
const deviceRef = "device:22222222-2222-4222-8222-222222222222";
@@ -547,9 +574,61 @@ function createCoreClient(options) {
commandTransport: options.commandTransport,
offerCommand: options.offerCommand,
recordCommandStatus: options.recordCommandStatus,
recordHostTelemetry: options.recordHostTelemetry,
});
}
function hostTelemetrySnapshot() {
return {
schemaVersion: "nodedc.infrastructure.host-telemetry.v1",
profile: "linux-host-telegraf-v1",
hostKey: "robot2b-b2-edge-vps",
observedAt: new Date().toISOString(),
source: {
agent: "telegraf",
agentVersion: "1.38.4",
collectorRef: "service:nodedc-host-telemetry-agent",
},
hardware: {
hostname: "koffyvngij",
architecture: "x64",
platform: "linux",
kernelRelease: "6.8.0",
cpuModel: "KVM CPU",
logicalProcessors: 1,
},
cpu: { usagePercent: 20, load1: 0.2, load5: 0.1, load15: 0.05 },
memory: {
totalBytes: 1024,
availableBytes: 700,
freeBytes: null,
usedBytes: 324,
usedPercent: 31.6,
},
swap: {
totalBytes: 0,
availableBytes: null,
freeBytes: 0,
usedBytes: 0,
usedPercent: 0,
},
system: {
uptimeSeconds: 100,
users: 1,
processes: {
total: 10,
running: 1,
sleeping: 9,
blocked: 0,
zombies: 0,
},
},
disks: [],
network: [],
services: [],
};
}
function productionDiscoveryObserver() {
return createDeviceGatewayIngest({
identifierPepper: "test-only-device-edge-channel-identifier-pepper",