feat(telemetry): add canonical VPS host monitoring
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
import {
|
||||
createDeviceGatewayRuntime,
|
||||
} from "../../services/device-gateway/src/runtime.mjs";
|
||||
import { createHostTelemetryCollector } from "./host-telemetry-runtime.mjs";
|
||||
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
||||
await main();
|
||||
@@ -51,16 +52,26 @@ export async function main(environment = process.env) {
|
||||
onMessage: (message) => channel.submitAdapterMessage(message),
|
||||
onCommandStatus: (status) => channel.submitCommandStatus(status),
|
||||
});
|
||||
const health = createCombinedHealthServer(channel, gateway, base.health);
|
||||
const telemetry = createHostTelemetryCollector({
|
||||
submit: (snapshot) => channel.submitHostTelemetry(snapshot),
|
||||
hostKey: environment.NODEDC_INFRASTRUCTURE_HOST_KEY
|
||||
?? "robot2b-b2-edge-vps",
|
||||
host: environment.NODEDC_HOST_TELEMETRY_HOST ?? "127.0.0.1",
|
||||
port: environment.NODEDC_HOST_TELEMETRY_PORT ?? 18223,
|
||||
agentVersion: environment.NODEDC_HOST_TELEMETRY_AGENT_VERSION ?? "1.38.4",
|
||||
});
|
||||
const health = createCombinedHealthServer(channel, gateway, telemetry, base.health);
|
||||
let stopping = false;
|
||||
|
||||
try {
|
||||
await channel.start();
|
||||
await gateway.start();
|
||||
await telemetry.start();
|
||||
await listen(health, base.health.port, base.health.host);
|
||||
} catch (error) {
|
||||
await Promise.allSettled([
|
||||
gateway.stop(),
|
||||
telemetry.stop(),
|
||||
channel.stop(),
|
||||
closeServer(health),
|
||||
]);
|
||||
@@ -72,6 +83,7 @@ export async function main(environment = process.env) {
|
||||
channel: `${base.channel.host}:${base.channel.port}`,
|
||||
health: `${base.health.host}:${base.health.port}`,
|
||||
trackerIngress: `${tracker.tcpHost}:${tracker.tcpPort}`,
|
||||
hostTelemetry: `${telemetry.status().host}:${telemetry.status().port}`,
|
||||
adapterProfile: tracker.protocolProfileRef,
|
||||
edgeRegistrationId: base.channel.edgeRegistrationId,
|
||||
channelGeneration: base.channel.channelGeneration,
|
||||
@@ -87,6 +99,7 @@ export async function main(environment = process.env) {
|
||||
stopping = true;
|
||||
await Promise.allSettled([
|
||||
gateway.stop(),
|
||||
telemetry.stop(),
|
||||
channel.stop(),
|
||||
closeServer(health),
|
||||
]);
|
||||
@@ -161,7 +174,7 @@ export function normalizeTrackerIngressConfiguration(environment = {}, edgeRef)
|
||||
});
|
||||
}
|
||||
|
||||
function createCombinedHealthServer(channel, gateway, healthConfig) {
|
||||
function createCombinedHealthServer(channel, gateway, telemetry, healthConfig) {
|
||||
return createServer((request, response) => {
|
||||
response.setHeader("Content-Type", "application/json; charset=utf-8");
|
||||
response.setHeader("Cache-Control", "no-store");
|
||||
@@ -179,6 +192,7 @@ function createCombinedHealthServer(channel, gateway, healthConfig) {
|
||||
...channel.status(),
|
||||
trackerIngress: "telemetry-ingest",
|
||||
tracker: gateway.status(),
|
||||
hostTelemetry: telemetry.status(),
|
||||
commandTransport: "typed-service-ping-v1",
|
||||
}));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user