File tree Expand file tree Collapse file tree 14 files changed +132
-0
lines changed
Expand file tree Collapse file tree 14 files changed +132
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { AppModule } from './app.module';
33import { MicroserviceOptions , Transport } from '@nestjs/microservices' ;
44import { ConfigService } from '@nestjs/config' ;
55import { Configuration } from '@leetcode/config' ;
6+ import { startMetricsServer } from './metrics-server' ;
7+ import { register } from 'prom-client' ;
68
79async function bootstrap ( ) {
810 const appContext = await NestFactory . createApplicationContext ( AppModule ) ;
@@ -15,6 +17,9 @@ async function bootstrap() {
1517 port : configService . get ( 'auth_service_port' ) ,
1618 } ,
1719 } ) ;
20+
21+ startMetricsServer ( register , configService . get ( 'auth_service_port' ) ! ) ;
22+
1823 await app . listen ( ) ;
1924}
2025bootstrap ( ) ;
Original file line number Diff line number Diff line change 1+ import express from 'express' ;
2+ import { Registry } from 'prom-client' ;
3+
4+ export function startMetricsServer ( registry : Registry , port : number ) {
5+ const app = express ( ) ;
6+
7+ app . get ( '/metrics' , async ( _req , res ) => {
8+ res . set ( 'Content-Type' , registry . contentType ) ;
9+ res . send ( await registry . metrics ( ) ) ;
10+ } ) ;
11+
12+ app . listen ( port , ( ) => {
13+ console . log ( `Prometheus metrics on port ${ port } /metrics` ) ;
14+ } ) ;
15+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { AppModule } from './app.module';
33import { ConfigService } from '@nestjs/config' ;
44import { Configuration } from '@leetcode/config' ;
55import { MicroserviceOptions , Transport } from '@nestjs/microservices' ;
6+ import { register } from 'prom-client' ;
7+ import { startMetricsServer } from './metrics-server' ;
68
79async function bootstrap ( ) {
810 const appContext = await NestFactory . createApplicationContext ( AppModule ) ;
@@ -15,6 +17,9 @@ async function bootstrap() {
1517 port : configService . get ( 'companies_service_port' ) ,
1618 } ,
1719 } ) ;
20+
21+ startMetricsServer ( register , configService . get ( 'companies_service_port' ) ! ) ;
22+
1823 await app . listen ( ) ;
1924}
2025bootstrap ( ) ;
Original file line number Diff line number Diff line change 1+ import express from 'express' ;
2+ import { Registry } from 'prom-client' ;
3+
4+ export function startMetricsServer ( registry : Registry , port : number ) {
5+ const app = express ( ) ;
6+
7+ app . get ( '/metrics' , async ( _req , res ) => {
8+ res . set ( 'Content-Type' , registry . contentType ) ;
9+ res . send ( await registry . metrics ( ) ) ;
10+ } ) ;
11+
12+ app . listen ( port , ( ) => {
13+ console . log ( `Prometheus metrics on port ${ port } /metrics` ) ;
14+ } ) ;
15+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { AppModule } from './app.module';
33import { MicroserviceOptions , Transport } from '@nestjs/microservices' ;
44import { ConfigService } from '@nestjs/config' ;
55import { Configuration } from '@leetcode/config' ;
6+ import { register } from 'prom-client' ;
7+ import { startMetricsServer } from './metrics-server' ;
68
79async function bootstrap ( ) {
810 const appContext = await NestFactory . createApplicationContext ( AppModule ) ;
@@ -15,6 +17,9 @@ async function bootstrap() {
1517 port : configService . get ( 'execution_service_port' ) ,
1618 } ,
1719 } ) ;
20+
21+ startMetricsServer ( register , configService . get ( 'execution_service_port' ) ! ) ;
22+
1823 await app . listen ( ) ;
1924}
2025bootstrap ( ) ;
Original file line number Diff line number Diff line change 1+ import express from 'express' ;
2+ import { Registry } from 'prom-client' ;
3+
4+ export function startMetricsServer ( registry : Registry , port : number ) {
5+ const app = express ( ) ;
6+
7+ app . get ( '/metrics' , async ( _req , res ) => {
8+ res . set ( 'Content-Type' , registry . contentType ) ;
9+ res . send ( await registry . metrics ( ) ) ;
10+ } ) ;
11+
12+ app . listen ( port , ( ) => {
13+ console . log ( `Prometheus metrics on port ${ port } /metrics` ) ;
14+ } ) ;
15+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { AppModule } from './app.module';
33import { MicroserviceOptions , Transport } from '@nestjs/microservices' ;
44import { ConfigService } from '@nestjs/config' ;
55import { Configuration } from '@leetcode/config' ;
6+ import { startMetricsServer } from './metrics-server' ;
7+ import { register } from 'prom-client' ;
68
79async function bootstrap ( ) {
810 const appContext = await NestFactory . createApplicationContext ( AppModule ) ;
@@ -15,6 +17,7 @@ async function bootstrap() {
1517 port : configService . get ( 'problems_service_port' ) ,
1618 } ,
1719 } ) ;
20+ startMetricsServer ( register , configService . get ( 'problems_service_port' ) ! ) ;
1821 await app . listen ( ) ;
1922}
2023bootstrap ( ) ;
Original file line number Diff line number Diff line change 1+ import express from 'express' ;
2+ import { Registry } from 'prom-client' ;
3+
4+ export function startMetricsServer ( registry : Registry , port : number ) {
5+ const app = express ( ) ;
6+
7+ app . get ( '/metrics' , async ( _req , res ) => {
8+ res . set ( 'Content-Type' , registry . contentType ) ;
9+ res . send ( await registry . metrics ( ) ) ;
10+ } ) ;
11+
12+ app . listen ( port , ( ) => {
13+ console . log ( `Prometheus metrics on port ${ port } /metrics` ) ;
14+ } ) ;
15+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { AppModule } from './app.module';
33import { MicroserviceOptions , Transport } from '@nestjs/microservices' ;
44import { ConfigService } from '@nestjs/config' ;
55import { Configuration } from '@leetcode/config' ;
6+ import { register } from 'prom-client' ;
7+ import { startMetricsServer } from './metrics-server' ;
68
79async function bootstrap ( ) {
810 const appContext = await NestFactory . createApplicationContext ( AppModule ) ;
@@ -15,6 +17,7 @@ async function bootstrap() {
1517 port : configService . get ( 'submissions_service_port' ) ,
1618 } ,
1719 } ) ;
20+ startMetricsServer ( register , configService . get ( 'submissions_service_port' ) ! ) ;
1821 await app . listen ( ) ;
1922}
2023bootstrap ( ) ;
Original file line number Diff line number Diff line change 1+ import express from 'express' ;
2+ import { Registry } from 'prom-client' ;
3+
4+ export function startMetricsServer ( registry : Registry , port : number ) {
5+ const app = express ( ) ;
6+
7+ app . get ( '/metrics' , async ( _req , res ) => {
8+ res . set ( 'Content-Type' , registry . contentType ) ;
9+ res . send ( await registry . metrics ( ) ) ;
10+ } ) ;
11+
12+ app . listen ( port , ( ) => {
13+ console . log ( `Prometheus metrics on port ${ port } /metrics` ) ;
14+ } ) ;
15+ }
You can’t perform that action at this time.
0 commit comments