@@ -43,17 +43,7 @@ export default class HealthCheckerService {
4343 if ( req . url === "/" ) {
4444 res . writeHead ( 200 , { "Content-Type" : "application/json" } ) ;
4545 res . end (
46- json_stringify ( {
47- startTime : this . #start,
48- version,
49- network : this . config . network ,
50- family : "liquidators" ,
51- liquidationMode : this . config . liquidationMode ,
52- address : this . client . address ,
53- balance : this . client . balance ,
54- currentBlock : this . scanner . lastUpdated ,
55- timestamp : Number ( this . scanner . lastTimestamp ) ,
56- } ) ,
46+ json_stringify ( this . #healthStatus) ,
5747 ) ;
5848 } else if ( req . url === "/metrics" ) {
5949 try {
@@ -86,6 +76,30 @@ export default class HealthCheckerService {
8676 this . log . info ( "launched" ) ;
8777 }
8878
79+ get #healthStatus( ) {
80+ const balanceOk = ! this . client . balance || this . client . balance . status === "healthy" ;
81+ const now = Math . ceil ( Date . now ( ) / 1000 )
82+ const timestamp = Number ( this . scanner . lastTimestamp ) ;
83+ const timestampOk = now - timestamp <= 120 ;
84+ const status = ( balanceOk && timestampOk ) ? "healthy" : "alert" ;
85+
86+ return {
87+ status,
88+ startTime : this . #start,
89+ version,
90+ network : this . config . network ,
91+ family : "liquidators" ,
92+ liquidationMode : this . config . liquidationMode ,
93+ address : this . client . address ,
94+ balance : this . client . balance ,
95+ currentBlock : this . scanner . lastUpdated ,
96+ timestamp : {
97+ value : timestamp ,
98+ status : timestampOk ? "healthy" : "alert" ,
99+ }
100+ }
101+ }
102+
89103 /**
90104 * Returns metrics in prometheus format
91105 * https://prometheus.io/docs/concepts/data_model/
0 commit comments