-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store-indexer): add prometheus metrics (#2739)
- Loading branch information
Showing
7 changed files
with
106 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/store-indexer": patch | ||
--- | ||
|
||
Add Prometheus metrics at `/metrics` to the Postgres indexer backend and frontend, as well as the SQLite indexer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Middleware } from "koa"; | ||
import promClient from "prom-client"; | ||
|
||
type MetricsOptions = { | ||
isHealthy?: () => boolean; | ||
isReady?: () => boolean; | ||
}; | ||
|
||
/** | ||
* Middleware to add Prometheus metrics endpoints | ||
*/ | ||
export function metrics({ isHealthy, isReady }: MetricsOptions = {}): Middleware { | ||
promClient.collectDefaultMetrics(); | ||
if (isHealthy != null) { | ||
new promClient.Gauge({ | ||
name: "health_status", | ||
help: "Health status (0 = unhealthy, 1 = healthy)", | ||
collect(): void { | ||
this.set(Number(isHealthy())); | ||
}, | ||
}); | ||
} | ||
|
||
if (isReady != null) { | ||
new promClient.Gauge({ | ||
name: "readiness_status", | ||
help: "Readiness status (whether the service is ready to receive requests, 0 = not ready, 1 = ready)", | ||
collect(): void { | ||
this.set(Number(isReady())); | ||
}, | ||
}); | ||
} | ||
|
||
return async function metricsMiddleware(ctx, next): Promise<void> { | ||
if (ctx.path === "/metrics") { | ||
ctx.status = 200; | ||
ctx.body = await promClient.register.metrics(); | ||
return; | ||
} | ||
|
||
await next(); | ||
}; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.