From b7141fc8af07cd4c8a4d2a88e10a7124f3ebde73 Mon Sep 17 00:00:00 2001 From: collin Date: Tue, 16 Jun 2026 15:06:06 +0200 Subject: [PATCH] Adding prometheus --- src/app.module.ts | 2 ++ src/prometheus/module.ts | 8 ++++++++ src/prometheus/provider.ts | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/prometheus/module.ts create mode 100644 src/prometheus/provider.ts 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' }, + }) + } +}