Skip to content
Snippets Groups Projects
Commit f5acd0f0 authored by Alexander Tim Hobelsberger's avatar Alexander Tim Hobelsberger
Browse files

Custom Metrics

parent a29407ed
Branches
No related tags found
No related merge requests found
...@@ -38,8 +38,6 @@ services: ...@@ -38,8 +38,6 @@ services:
build: . build: .
ports: ports:
- 5000:5000 - 5000:5000
expose:
- 5000
volumes: volumes:
- ./:/code - ./:/code
depends_on: depends_on:
... ...
......
...@@ -9,11 +9,11 @@ const { mongo, default: mongoose } = require('mongoose'); ...@@ -9,11 +9,11 @@ const { mongo, default: mongoose } = require('mongoose');
const server = http.createServer(app); const server = http.createServer(app);
//https Server //https Server
/* const server = https.createServer({ const server = https.createServer({
key: fs.readFileSync(__dirname + '/tls/key.pem'), key: fs.readFileSync(__dirname + '/tls/key.pem'),
cert: fs.readFileSync(__dirname + '/tls/cert.pem'), cert: fs.readFileSync(__dirname + '/tls/cert.pem'),
}, app); }, app);
*/
const { Server } = require("socket.io"); const { Server } = require("socket.io");
const io = new Server(server); const io = new Server(server);
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
...@@ -24,6 +24,27 @@ const authenticationRoute = require('./routes/auth'); ...@@ -24,6 +24,27 @@ const authenticationRoute = require('./routes/auth');
const { response } = require('express'); const { response } = require('express');
const { resolve } = require('path'); const { resolve } = require('path');
const promClient = require('prom-client');
// Create a Registry to register the metrics
const register = new promClient.Registry();
promClient.collectDefaultMetrics({
app: 'node-application-monitoring-app',
prefix: 'node_',
timeout: 10000,
gcDurationBuckets: [0.001, 0.01, 0.1, 1, 2, 5],
register
});
app.get('/metrics', async (req, res) => {
res.setHeader('Content-Type', register.contentType);
res.send(await register.metrics());
});
//DB Connection //DB Connection
//mongoose.connect("mongodb://mongodb:27017/cloudComputing"); //mongoose.connect("mongodb://mongodb:27017/cloudComputing");
...@@ -92,7 +113,7 @@ app.get('/login', (req, res) => { ...@@ -92,7 +113,7 @@ app.get('/login', (req, res) => {
/** /**
* Summary: * Summary:
* Function for handling updating the List of users eho are currently online. * Function for handling updating the List of users who are currently online.
* *
* *
* Description: * Description:
...@@ -154,7 +175,7 @@ async function addUserToActiveUsers(response, socket) { ...@@ -154,7 +175,7 @@ async function addUserToActiveUsers(response, socket) {
* Function to delete a user from the map of users, who are currently online. * Function to delete a user from the map of users, who are currently online.
* *
* Description: * Description:
* Function will take the socketID from the socket, of the client, who is disconneting. * Function will take the socketID from the socket, of the promClient, who is disconneting.
* The socketID and its value (username) will be deleted from map activeUsers. * The socketID and its value (username) will be deleted from map activeUsers.
* After deleting the socketID and username io.emit() is called and the upodated userList is sent to all users who are currently online. * After deleting the socketID and username io.emit() is called and the upodated userList is sent to all users who are currently online.
* *
...@@ -331,7 +352,7 @@ io.on('connection', (socket) => { ...@@ -331,7 +352,7 @@ io.on('connection', (socket) => {
* *
* *
* Description: * Description:
* By triggering the 'sendImage' Event, the function emits the given files url to client * By triggering the 'sendImage' Event, the function emits the given files url to promClient
* *
* @listens socket.on() 'sendImage' event * @listens socket.on() 'sendImage' event
*/ */
...@@ -347,7 +368,7 @@ io.on("connection", (socket) => { ...@@ -347,7 +368,7 @@ io.on("connection", (socket) => {
* *
* *
* Description: * Description:
* By triggering the 'sendVideo' Event, the function emits the given files url to client * By triggering the 'sendVideo' Event, the function emits the given files url to promClient
* *
* @listens socket.on() 'sendVideo' event * @listens socket.on() 'sendVideo' event
*/ */
...@@ -363,7 +384,7 @@ io.on("connection", (socket) => { ...@@ -363,7 +384,7 @@ io.on("connection", (socket) => {
* *
* *
* Description: * Description:
* By triggering the 'sendAudio' Event, the function emits the given files url to client * By triggering the 'sendAudio' Event, the function emits the given files url to promClient
* *
* @listens socket.on() 'sendAudio' event * @listens socket.on() 'sendAudio' event
*/ */
... ...
......
This diff is collapsed.
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"mongoose": "^6.6.7", "mongoose": "^6.6.7",
"nodemon": "^2.0.20", "nodemon": "^2.0.20",
"prom-client": "^14.1.0",
"socket.io": "^4.5.3" "socket.io": "^4.5.3"
} }
}, },
...@@ -1263,11 +1262,6 @@ ...@@ -1263,11 +1262,6 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/bintrees": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/bintrees/-/bintrees-1.0.2.tgz",
"integrity": "sha512-VOMgTMwjAaUG580SXn3LacVgjurrbMme7ZZNYGSSV7mmtY6QQRh0Eg3pwIcntQ77DErK1L0NxkbetjcoXzVwKw=="
},
"node_modules/body-parser": { "node_modules/body-parser": {
"version": "1.20.1", "version": "1.20.1",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
...@@ -1553,9 +1547,9 @@ ...@@ -1553,9 +1547,9 @@
} }
}, },
"node_modules/engine.io": { "node_modules/engine.io": {
"version": "6.2.1", "version": "6.2.0",
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.2.1.tgz", "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.2.0.tgz",
"integrity": "sha512-ECceEFcAaNRybd3lsGQKas3ZlMVjN3cyWwMP25D2i0zWfyiytVbTpRPa34qrr+FHddtpBVOmq4H/DCv1O0lZRA==", "integrity": "sha512-4KzwW3F3bk+KlzSOY57fj/Jx6LyRQ1nbcyIadehl+AnXjKT7gDO0ORdRi/84ixvMKTym6ZKuxvbzN62HDDU1Lg==",
"dependencies": { "dependencies": {
"@types/cookie": "^0.4.1", "@types/cookie": "^0.4.1",
"@types/cors": "^2.8.12", "@types/cors": "^2.8.12",
...@@ -2550,17 +2544,6 @@ ...@@ -2550,17 +2544,6 @@
"url": "https://github.com/sponsors/jonschlinkert" "url": "https://github.com/sponsors/jonschlinkert"
} }
}, },
"node_modules/prom-client": {
"version": "14.1.0",
"resolved": "https://registry.npmjs.org/prom-client/-/prom-client-14.1.0.tgz",
"integrity": "sha512-iFWCchQmi4170omLpFXbzz62SQTmPhtBL35v0qGEVRHKcqIeiexaoYeP0vfZTujxEq3tA87iqOdRbC9svS1B9A==",
"dependencies": {
"tdigest": "^0.1.1"
},
"engines": {
"node": ">=10"
}
},
"node_modules/proxy-addr": { "node_modules/proxy-addr": {
"version": "2.0.7", "version": "2.0.7",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
...@@ -2983,14 +2966,6 @@ ...@@ -2983,14 +2966,6 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/tdigest": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/tdigest/-/tdigest-0.1.2.tgz",
"integrity": "sha512-+G0LLgjjo9BZX2MfdvPfH+MKLCrxlXSYec5DaPYP1fe6Iyhf0/fSmJ0bFiZ1F8BT6cGXl2LpltQptzjXKWEkKA==",
"dependencies": {
"bintrees": "1.0.2"
}
},
"node_modules/to-regex-range": { "node_modules/to-regex-range": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
...@@ -4200,11 +4175,6 @@ ...@@ -4200,11 +4175,6 @@
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz",
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==" "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA=="
}, },
"bintrees": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/bintrees/-/bintrees-1.0.2.tgz",
"integrity": "sha512-VOMgTMwjAaUG580SXn3LacVgjurrbMme7ZZNYGSSV7mmtY6QQRh0Eg3pwIcntQ77DErK1L0NxkbetjcoXzVwKw=="
},
"body-parser": { "body-parser": {
"version": "1.20.1", "version": "1.20.1",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
...@@ -4412,9 +4382,9 @@ ...@@ -4412,9 +4382,9 @@
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==" "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w=="
}, },
"engine.io": { "engine.io": {
"version": "6.2.1", "version": "6.2.0",
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.2.1.tgz", "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.2.0.tgz",
"integrity": "sha512-ECceEFcAaNRybd3lsGQKas3ZlMVjN3cyWwMP25D2i0zWfyiytVbTpRPa34qrr+FHddtpBVOmq4H/DCv1O0lZRA==", "integrity": "sha512-4KzwW3F3bk+KlzSOY57fj/Jx6LyRQ1nbcyIadehl+AnXjKT7gDO0ORdRi/84ixvMKTym6ZKuxvbzN62HDDU1Lg==",
"requires": { "requires": {
"@types/cookie": "^0.4.1", "@types/cookie": "^0.4.1",
"@types/cors": "^2.8.12", "@types/cors": "^2.8.12",
...@@ -5162,14 +5132,6 @@ ...@@ -5162,14 +5132,6 @@
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="
}, },
"prom-client": {
"version": "14.1.0",
"resolved": "https://registry.npmjs.org/prom-client/-/prom-client-14.1.0.tgz",
"integrity": "sha512-iFWCchQmi4170omLpFXbzz62SQTmPhtBL35v0qGEVRHKcqIeiexaoYeP0vfZTujxEq3tA87iqOdRbC9svS1B9A==",
"requires": {
"tdigest": "^0.1.1"
}
},
"proxy-addr": { "proxy-addr": {
"version": "2.0.7", "version": "2.0.7",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
...@@ -5487,14 +5449,6 @@ ...@@ -5487,14 +5449,6 @@
"yallist": "^4.0.0" "yallist": "^4.0.0"
} }
}, },
"tdigest": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/tdigest/-/tdigest-0.1.2.tgz",
"integrity": "sha512-+G0LLgjjo9BZX2MfdvPfH+MKLCrxlXSYec5DaPYP1fe6Iyhf0/fSmJ0bFiZ1F8BT6cGXl2LpltQptzjXKWEkKA==",
"requires": {
"bintrees": "1.0.2"
}
},
"to-regex-range": { "to-regex-range": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment