diff --git a/package.json b/package.json index 98e7002..63aca8d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "substreams-sink-prometheus", - "version": "0.3.2", + "version": "0.3.3", "description": "Substreams Prometheus sink module", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/metrics.ts b/src/metrics.ts index fcf2b4f..c9dd58b 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -11,16 +11,18 @@ export function handleOperation(promOp: PrometheusOperation) { } export function handleClock(clock: Clock) { + const block_num = Number(clock.number); + const seconds = Number(clock.timestamp?.seconds); + const head_block_time_drift = Math.floor((new Date().valueOf() / 1000) - seconds); registerGauge("head_block_number", "Last block number processed by Substreams Sink"); registerGauge("head_block_timestamp", "Last block timestamp (in seconds) processed by Substreams Sink"); - registerGauge("head_block_drift", "Head block drift (in seconds) by Substreams Sink"); + registerGauge("head_block_time_drift", "Head block drift (in seconds) by Substreams Sink"); const gauge1 = register.getSingleMetric("head_block_number") as Gauge; const gauge2 = register.getSingleMetric("head_block_timestamp") as Gauge; const gauge3 = register.getSingleMetric("head_block_time_drift") as Gauge; - if ( gauge1 ) gauge1.set(Number(clock.number)); - if ( gauge2 ) gauge2.set(Number(clock.timestamp?.seconds)); - const head_block_time_drift = Math.floor(new Date().getTime() / 1000) - Number(clock.timestamp?.seconds); - if ( gauge3 ) gauge3.set(head_block_time_drift > 0 ? head_block_time_drift : 0); + if ( gauge1 ) gauge1.set(block_num); + if ( gauge2 ) gauge2.set(seconds); + if ( gauge3 ) gauge3.set(head_block_time_drift); } export function handleCounter(promOp: PrometheusOperation) {