Skip to content

Commit e315096

Browse files
committed
fix: update healthchek response
1 parent cb89234 commit e315096

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/services/Client.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default class Client {
9797
@Logger("Client")
9898
public logger!: ILogger;
9999

100-
#balance?: bigint;
100+
#balance?: {value: bigint; status: string };
101101

102102
#anvilInfo: AnvilNodeInfo | null = null;
103103

@@ -297,7 +297,10 @@ export default class Client {
297297

298298
async #checkBalance(): Promise<void> {
299299
const balance = await this.pub.getBalance({ address: this.address });
300-
this.#balance = balance;
300+
this.#balance = {
301+
value: balance,
302+
status: balance < this.config.minBalance ? "alert" : "healthy",
303+
};
301304
this.logger.debug(`liquidator balance is ${formatEther(balance)}`);
302305
if (balance < this.config.minBalance) {
303306
this.notifier.alert(
@@ -357,7 +360,7 @@ export default class Client {
357360
return this.wallet.account.address;
358361
}
359362

360-
public get balance(): bigint | undefined {
363+
public get balance(): { value: bigint; status: string } | undefined {
361364
return this.#balance;
362365
}
363366

src/services/HealthCheckerService.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)