-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Prometheus and HealthCheck (#1780)
- Loading branch information
Showing
12 changed files
with
331 additions
and
35 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["metrics"] | ||
} | ||
|
||
datasource db { | ||
|
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,19 @@ | ||
import { Controller, Get } from "@nestjs/common"; | ||
import { HealthCheckService, HealthCheck, PrismaHealthIndicator } from "@nestjs/terminus"; | ||
import { PrismaService } from "nestjs-prisma"; | ||
@Controller("health") | ||
export class HealthController { | ||
constructor( | ||
private health: HealthCheckService, | ||
private prisma: PrismaHealthIndicator, | ||
private readonly prismaService: PrismaService, | ||
) {} | ||
|
||
@Get() | ||
@HealthCheck() | ||
check() { | ||
return this.health.check([ | ||
() => this.prisma.pingCheck('prisma', this.prismaService), | ||
]); | ||
} | ||
} |
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,15 @@ | ||
import { Controller, Get, Res } from "@nestjs/common"; | ||
import { Response } from "express"; | ||
import { register } from "./prom"; | ||
import { PrismaService } from "nestjs-prisma"; | ||
@Controller("metrics") | ||
export class MetricsController { | ||
constructor(private prisma: PrismaService) {} | ||
|
||
@Get() | ||
async getMetrics(@Res() res: Response) { | ||
const prismaMetrics = await this.prisma.$metrics.prometheus(); | ||
const appMetrics = await register.metrics(); | ||
res.end(prismaMetrics + appMetrics); | ||
} | ||
} |
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,11 @@ | ||
import * as prom from 'prom-client'; | ||
import promBundle from 'express-prom-bundle'; | ||
const register = new prom.Registry(); | ||
prom.collectDefaultMetrics({ register }); | ||
const metricsMiddleware = promBundle({ | ||
includeMethod: true, | ||
includePath: true, | ||
metricsPath: '/prom-metrics', | ||
promRegistry: register, | ||
}); | ||
export { metricsMiddleware, register }; |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
{ | ||
auto_https off | ||
admin off | ||
admin 0.0.0.0:3003 | ||
servers { | ||
metrics | ||
} | ||
} | ||
:3000 { | ||
log { | ||
|