@@ -28,6 +28,9 @@ import { resolvers as v3Resolvers } from "./v3/resolvers";
2828import { typeDefs as v3TypeDefs } from "./v3/typeDefinition" ;
2929import { resolvers as v4Resolvers } from "./v4/resolvers" ;
3030import { typeDefs as v4TypeDefs } from "./v4/typeDefinition" ;
31+ import { createPrometheusExporterPlugin } from "@bmatei/apollo-prometheus-exporter" ;
32+ import express from "express" ;
33+ import { Counter , Registry } from "prom-client" ;
3134
3235if ( process . env . NODE_ENV !== "production" )
3336 require ( "dotenv" ) . config ( { path : "../../../.env" } ) ;
@@ -70,7 +73,16 @@ export interface Context {
7073 transaction : Transaction ;
7174}
7275
76+ const pathMetric = new Counter ( {
77+ name : "premid_old_api_path" ,
78+ help : "The path of the request" ,
79+ labelNames : [ "path" ]
80+ } ) ;
81+
7382async function run ( ) {
83+ const registry = new Registry ( ) ;
84+ registry . registerMetric ( pathMetric ) ;
85+ const expressApp = express ( ) ;
7486 redis . setMaxListeners ( 12 ) ;
7587 redis . on ( "error" , error => {
7688 console . log ( error ) ;
@@ -103,6 +115,7 @@ async function run() {
103115 introspection : true ,
104116 cache : baseRedisCache ,
105117 plugins : [
118+ createPrometheusExporterPlugin ( { app : expressApp , register : registry } ) ,
106119 sentryPlugin ,
107120 fastifyAppClosePlugin ( app ) ,
108121 ApolloServerPluginDrainHttpServer ( { httpServer : app . server } ) ,
@@ -134,6 +147,7 @@ async function run() {
134147 } ) ;
135148
136149 app . addHook ( "onRequest" , async ( req , reply ) => {
150+ pathMetric . labels ( req . url ) . inc ( ) ;
137151 //@ts -ignore
138152 req . responseTimeCalc = process . hrtime ( ) ;
139153 reply . headers ( {
@@ -248,6 +262,8 @@ async function run() {
248262 . then ( url => {
249263 console . log ( `🚀 API Listening on ${ url } ` ) ;
250264 } ) ;
265+
266+ expressApp . listen ( 2112 , "0.0.0.0" ) ;
251267}
252268
253269run ( ) ;
0 commit comments