Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.

Commit 644193d

Browse files
run metrics on other port
1 parent 524de08 commit 644193d

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

src/app.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const index = require('./routes/index');
1616
const editor = require('./routes/editor');
1717
const legal = require('./routes/legal');
1818
const config = require('./config/config');
19-
const promBundle = require("express-prom-bundle");
2019

2120
const app = express();
2221
app.disable("x-powered-by");
@@ -40,14 +39,6 @@ else {
4039
}
4140
app.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);
5344
app.use(express.json());

src/config/config dist.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"DB_DATABASE": "codewe",
1717
"DB_PORT": "3306"
1818
},
19-
"METRICS": false
19+
"METRICS": false,
20+
"METRICS_PORT": 8000
2021
}

src/metricsApp.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 };

src/server.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ const options = ssl ? {
2323
} : null;
2424

2525
const 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
2936
const wss = new WebSocket.Server({ server });
@@ -34,3 +41,7 @@ require('./socket/socket')(wss);
3441
server.listen(port, host, () => {
3542
console.log('Server Started!');
3643
});
44+
45+
if (config.METRICS) {
46+
metricsServer.listen(config.METRICS_PORT);
47+
}

src/socket/socket.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const rooms = {};
2626
const hook = config.DISCORD_WEBHOOK ? new discordWebhook.Webhook(config.DISCORD_WEBHOOK) : null;
2727

2828
module.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();

0 commit comments

Comments
 (0)