Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/db/MongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { nanoid } = require('nanoid');
const languages = require('../config/langages');
const configs = require('../config/config');
const utils = require('../utils');
const prom = require('../socket/prom')

const baseCode = [
{uuid: utils.uuid(Math.random().toString(), 10), content: 'def main(text: str) -> None:'},
Expand Down Expand Up @@ -216,6 +217,7 @@ class MongoDB {
case 'new-line':
results = await this.newLine(documentLink, data.previous, data.id, data.content);
if (!results) success = false;
prom.total_new_lines.inc();
break;
case 'delete-line':
results = await this.deleteLine(documentLink, data.id);
Expand Down
3 changes: 3 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const router = express.Router();

const hook = config.DISCORD_WEBHOOK ? new discordWebhook.Webhook(config.DISCORD_WEBHOOK) : null;

const prom = require('../socket/prom');

const client = require('prom-client');

const qr_scans = new client.Counter({
Expand Down Expand Up @@ -65,6 +67,7 @@ router.post('/create_document', async (req, res, next) => {
const language = 'python';
let documentId = await db.createDocument(language);
if (documentId) {
prom.total_new_documents.inc();
res.redirect(`/editor/${documentId}`);
}
else {
Expand Down
45 changes: 44 additions & 1 deletion src/socket/prom.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,47 @@ const total_packets = new client.Counter({
help: 'total_packets',
});

module.exports = { timestamp_uptime, connexions, connected, total_packets };
const total_packets_size = new client.Counter({
name: 'total_packets_size',
help: 'total_packets_size',
});

const total_new_documents = new client.Counter({
name: 'total_new_documents',
help: 'total_new_documents',
});

const total_new_lines = new client.Counter({
name: 'total_new_lines',
help: 'total_new_lines',
});

const active_rooms = new client.Gauge({
name: 'active_rooms',
help: 'active_rooms',
});

const unique_connected = new client.Gauge({
name: 'unique_connected',
help: 'unique_connected',
});

/*
const unique_connexions = new client.Counter({
name: 'unique_connexions',
help: 'unique_connexions',
});
*/

module.exports = {
timestamp_uptime,
connexions,
connected,
total_packets,
total_packets_size,
total_new_documents,
total_new_lines,
active_rooms,
unique_connected,
//unique_connexions,
};
11 changes: 10 additions & 1 deletion src/socket/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ module.exports = function (wss) {


socket.on('message', async data => {
prom.total_packets.inc();
data = JSON.parse(data);
if(!('uuid' in data)) data['uuid'] = 'None';
switch (data.event) {
Expand Down Expand Up @@ -139,6 +138,8 @@ module.exports = function (wss) {
}

}
prom.total_packets.inc();
prom.total_packets_size.inc(data.toString().length * 16);
});

socket.on('pong', () => {
Expand Down Expand Up @@ -171,6 +172,14 @@ module.exports = function (wss) {

setInterval(() => {
prom.connected.set(wss.clients.size);
const unique_list = [];
wss.clients.forEach(function(x){
if(!unique_list.includes(x._socket.address().address)){
unique_list.push(x._socket.address().address);
}
});
prom.unique_connected.set(unique_list.length);
prom.active_rooms.set(Object.keys(rooms).length);
}, 5000);

// delete old documents
Expand Down