From f9877578b469b87850c6df1da69af77b2695621b Mon Sep 17 00:00:00 2001 From: Samuel Papineau Date: Mon, 2 Oct 2023 11:16:46 -0400 Subject: [PATCH] Added ping and trace id metrics --- index.ts | 10 ++++++++-- src/prometheus.ts | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index d90cdd1..747afaa 100644 --- a/index.ts +++ b/index.ts @@ -11,7 +11,7 @@ console.log(`Server listening on http://${HOSTNAME || "0.0.0.0"}:${PORT}`); console.log("Verifying with PUBLIC_KEY", PUBLIC_KEY); // Create SQLite DB -const db = new Database("./db.sqlite", {create: true}); // TO-DO as .env variable +const db = new Database("./sqlite/db.sqlite", {create: true}); // TO-DO as .env variable sqlite.create(db, "moduleHash"); sqlite.create(db, "traceId"); @@ -85,8 +85,13 @@ Bun.serve<{key: string}>({ prometheus.webhook_module_hash.labels({moduleHash}).inc(1); prometheus.webhook_messages.inc(1); - // Upsert moduleHash into SQLite DB + //Metrics for trace id const traceId = "654b2e1fd43e8468863595baaad68627"; // TO-DO: get traceId from Substreams metadata + if (traceId) { + prometheus.trace_id.inc(1); + } + + // Upsert moduleHash into SQLite DB sqlite.replace(db, "moduleHash", moduleHash, timestamp); sqlite.replace(db, "traceId", traceId, timestamp); @@ -111,6 +116,7 @@ Bun.serve<{key: string}>({ // TO-DO: maybe to be removed?? // https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#pings_and_pongs_the_heartbeat_of_websockets if ( message === "0x9" || message === "pong" ) { + prometheus.total_pings.inc(1); console.log('ping', {key: ws.data.key, remoteAddress: ws.remoteAddress}); ws.pong(); if ( message == "0x9" ) ws.send("0xA"); diff --git a/src/prometheus.ts b/src/prometheus.ts index e59bde4..ef3b0b6 100644 --- a/src/prometheus.ts +++ b/src/prometheus.ts @@ -37,3 +37,5 @@ export const connected = registerCounter('connected', 'Total connected clients') export const published_messages = registerCounter('published_messages', 'Total published messages'); export const bytes_published = registerCounter('bytes_published', 'Total bytes published'); export const disconnects = registerCounter('disconnects', 'Total disconnects'); +export const total_pings = registerCounter('total_pings', 'Total pings'); +export const trace_id = registerGauge('trace_id', 'Total trace ids') \ No newline at end of file