This repository was archived by the owner on Mar 10, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +30
-12
lines changed
Expand file tree Collapse file tree 5 files changed +30
-12
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ const index = require('./routes/index');
1616const editor = require ( './routes/editor' ) ;
1717const legal = require ( './routes/legal' ) ;
1818const config = require ( './config/config' ) ;
19- const promBundle = require ( "express-prom-bundle" ) ;
2019
2120const app = express ( ) ;
2221app . disable ( "x-powered-by" ) ;
@@ -40,14 +39,6 @@ else {
4039}
4140app . use ( minify ( { jsMatch : false } ) ) ;
4241
43- // Prometheus middleware
44- // TODO new middleware
45- if ( config . METRICS ) {
46- app . use ( promBundle ( {
47- includeMethod : true ,
48- includePath : true ,
49- } ) ) ;
50- }
5142
5243//app.use(secure);
5344app . use ( express . json ( ) ) ;
Original file line number Diff line number Diff line change 1616 "DB_DATABASE" : " codewe" ,
1717 "DB_PORT" : " 3306"
1818 },
19- "METRICS" : false
19+ "METRICS" : false ,
20+ "METRICS_PORT" : 8000
2021}
Original file line number Diff line number Diff line change 1+ const express = require ( "express" ) ;
2+ const promBundle = require ( "express-prom-bundle" ) ;
3+
4+ const promMetrics = promBundle ( {
5+ includeMethod : true ,
6+ includePath : true ,
7+ autoregister : false
8+ } ) ;
9+
10+ const { promClient, metricsMiddleware } = promMetrics ;
11+
12+ const metricsApp = express ( ) ;
13+ metricsApp . disable ( "x-powered-by" ) ;
14+ metricsApp . use ( metricsMiddleware ) ;
15+
16+ module . exports = { metricsMiddleware, metricsApp } ;
Original file line number Diff line number Diff line change @@ -23,7 +23,14 @@ const options = ssl ? {
2323} : null ;
2424
2525const app = require ( './app' ) ;
26- const server = ssl ? require ( 'https' ) . createServer ( options , app ) : require ( 'http' ) . createServer ( app ) ;
26+ const config = require ( './config/config' ) ;
27+
28+ const http = ssl ? require ( 'https' ) : require ( 'http' ) ;
29+ const server = http . createServer ( options , app ) ;
30+ if ( configs . METRICS ) {
31+ const { metricsApp} = require ( './metricsApp' ) ;
32+ var metricsServer = http . createServer ( metricsApp ) ;
33+ }
2734
2835// config websockets
2936const wss = new WebSocket . Server ( { server } ) ;
@@ -34,3 +41,7 @@ require('./socket/socket')(wss);
3441server . listen ( port , host , ( ) => {
3542 console . log ( 'Server Started!' ) ;
3643} ) ;
44+
45+ if ( config . METRICS ) {
46+ metricsServer . listen ( config . METRICS_PORT ) ;
47+ }
Original file line number Diff line number Diff line change @@ -26,7 +26,6 @@ const rooms = {};
2626const hook = config . DISCORD_WEBHOOK ? new discordWebhook . Webhook ( config . DISCORD_WEBHOOK ) : null ;
2727
2828module . exports = function ( wss ) {
29- // TODO catch error handle disconnection etc
3029 // Based on https://stackoverflow.com/a/62867363
3130 wss . on ( 'connection' , socket => {
3231 prom . connexions . inc ( ) ;
You can’t perform that action at this time.
0 commit comments