@@ -3,7 +3,7 @@ import * as SparkImpactEvaluator from '@filecoin-station/spark-impact-evaluator'
3
3
import { ethers } from 'ethers'
4
4
import * as Sentry from '@sentry/node'
5
5
import timers from 'node:timers/promises'
6
- import { InfluxDB } from '@influxdata/influxdb-client '
6
+ import { createInflux } from '../lib/telemetry.js '
7
7
import assert from 'node:assert/strict'
8
8
9
9
import { RPC_URL , rpcHeaders } from '../lib/config.js'
@@ -26,11 +26,7 @@ const provider = new ethers.JsonRpcProvider(fetchRequest, null, { polling: true
26
26
27
27
const ieContract = new ethers . Contract ( SparkImpactEvaluator . ADDRESS , SparkImpactEvaluator . ABI , provider )
28
28
29
- const influx = new InfluxDB ( {
30
- url : 'https://eu-central-1-1.aws.cloud2.influxdata.com' ,
31
- // spark-stats-observer-read
32
- token : INFLUXDB_TOKEN
33
- } )
29
+ const { influx, recordTelemetry } = createInflux ( INFLUXDB_TOKEN )
34
30
35
31
const influxQueryApi = influx . getQueryApi ( 'Filecoin Station' )
36
32
@@ -47,7 +43,14 @@ const loop = async (name, fn, interval) => {
47
43
}
48
44
const dt = Date . now ( ) - start
49
45
console . log ( `Loop "${ name } " took ${ dt } ms` )
50
- await timers . setTimeout ( interval - dt )
46
+ recordTelemetry ( `loop_${ name . replaceAll ( ' ' , '_' ) } ` , point => {
47
+ point . intField ( 'interval_ms' , interval )
48
+ point . intField ( 'duration_ms' , dt )
49
+ point . intField ( 'delay_ms' , interval - dt )
50
+ } )
51
+ if ( dt < interval ) {
52
+ await timers . setTimeout ( interval - dt )
53
+ }
51
54
}
52
55
}
53
56
0 commit comments