diff --git a/src/app.module.ts b/src/app.module.ts index 5495d7a..682cf84 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -13,6 +13,7 @@ import { DatabaseLoggerService } from './logger/service.database_logger' import { MembersModule } from './members/module' import { MonitoringModule } from './monitoring/module' import { NtfyModule } from './ntfy/module' +import { PrometheusModule } from './prometheus/module' import { RecurringReservationsModule } from './recurringReservations/module' import { ReservationsModule } from './reservations/module' import { RunnerModule } from './runner/module' @@ -63,6 +64,7 @@ import { WaitingListModule } from './waitingList/module' WaitingListModule, NtfyModule, MonitoringModule, + PrometheusModule, ], }) export class AppModule implements NestModule { diff --git a/src/prometheus/module.ts b/src/prometheus/module.ts new file mode 100644 index 0000000..27d3c3d --- /dev/null +++ b/src/prometheus/module.ts @@ -0,0 +1,8 @@ +import { Module } from '@nestjs/common' + +import { PrometheusProvider } from './provider' + +@Module({ + providers: [PrometheusProvider], +}) +export class PrometheusModule {} diff --git a/src/prometheus/provider.ts b/src/prometheus/provider.ts new file mode 100644 index 0000000..8422f08 --- /dev/null +++ b/src/prometheus/provider.ts @@ -0,0 +1,18 @@ +import { OnApplicationBootstrap } from '@nestjs/common' +import { collectDefaultMetrics, Registry } from 'prom-client' + +export class PrometheusProvider implements OnApplicationBootstrap { + private readonly registry: Registry + + constructor() { + this.registry = new Registry() + } + + onApplicationBootstrap() { + collectDefaultMetrics({ + register: this.registry, + prefix: 'autobaan_', + labels: { GIT_COMMIT: process.env.GIT_COMMIT ?? 'unknown' }, + }) + } +}