@@ -28,6 +28,9 @@ import { resolvers as v3Resolvers } from "./v3/resolvers";
28
28
import { typeDefs as v3TypeDefs } from "./v3/typeDefinition" ;
29
29
import { resolvers as v4Resolvers } from "./v4/resolvers" ;
30
30
import { 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" ;
31
34
32
35
if ( process . env . NODE_ENV !== "production" )
33
36
require ( "dotenv" ) . config ( { path : "../../../.env" } ) ;
@@ -70,7 +73,16 @@ export interface Context {
70
73
transaction : Transaction ;
71
74
}
72
75
76
+ const pathMetric = new Counter ( {
77
+ name : "premid_old_api_path" ,
78
+ help : "The path of the request" ,
79
+ labelNames : [ "path" ]
80
+ } ) ;
81
+
73
82
async function run ( ) {
83
+ const registry = new Registry ( ) ;
84
+ registry . registerMetric ( pathMetric ) ;
85
+ const expressApp = express ( ) ;
74
86
redis . setMaxListeners ( 12 ) ;
75
87
redis . on ( "error" , error => {
76
88
console . log ( error ) ;
@@ -103,6 +115,7 @@ async function run() {
103
115
introspection : true ,
104
116
cache : baseRedisCache ,
105
117
plugins : [
118
+ createPrometheusExporterPlugin ( { app : expressApp , register : registry } ) ,
106
119
sentryPlugin ,
107
120
fastifyAppClosePlugin ( app ) ,
108
121
ApolloServerPluginDrainHttpServer ( { httpServer : app . server } ) ,
@@ -134,6 +147,7 @@ async function run() {
134
147
} ) ;
135
148
136
149
app . addHook ( "onRequest" , async ( req , reply ) => {
150
+ pathMetric . labels ( req . url ) . inc ( ) ;
137
151
//@ts -ignore
138
152
req . responseTimeCalc = process . hrtime ( ) ;
139
153
reply . headers ( {
@@ -248,6 +262,8 @@ async function run() {
248
262
. then ( url => {
249
263
console . log ( `🚀 API Listening on ${ url } ` ) ;
250
264
} ) ;
265
+
266
+ expressApp . listen ( 2112 , "0.0.0.0" ) ;
251
267
}
252
268
253
269
run ( ) ;
0 commit comments