mirror of
https://github.com/ether/etherpad-lite.git
synced 2026-01-23 02:35:34 +00:00
fix prometheus metric and add total users and active pad count (#7179)
* fix prometheus metric registration * add totalUsers and activePads metric to prometheus
This commit is contained in:
parent
49d431b6b8
commit
06f67b4c01
2 changed files with 42 additions and 18 deletions
|
|
@ -94,14 +94,25 @@ exports.socketio = () => {
|
|||
const sessioninfos:MapArrayType<any> = {};
|
||||
exports.sessioninfos = sessioninfos;
|
||||
|
||||
stats.gauge('totalUsers', () => socketio ? socketio.engine.clientsCount : 0);
|
||||
stats.gauge('activePads', () => {
|
||||
function getTotalActiveUsers() {
|
||||
return socketio ? socketio.engine.clientsCount : 0;
|
||||
}
|
||||
|
||||
exports.getTotalActiveUsers = getTotalActiveUsers;
|
||||
|
||||
function getActivePadCountFromSessionInfos() {
|
||||
const padIds = new Set();
|
||||
for (const {padId} of Object.values(sessioninfos)) {
|
||||
if (!padId) continue;
|
||||
padIds.add(padId);
|
||||
}
|
||||
return padIds.size;
|
||||
}
|
||||
exports.getActivePadCountFromSessionInfos = getActivePadCountFromSessionInfos;
|
||||
|
||||
stats.gauge('totalUsers', () => getTotalActiveUsers());
|
||||
stats.gauge('activePads', () => {
|
||||
return getActivePadCountFromSessionInfos();
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,25 +1,38 @@
|
|||
import client from 'prom-client'
|
||||
const db = require('./db/DB').db
|
||||
import client from 'prom-client';
|
||||
|
||||
const monitor = function () {
|
||||
const collectDefaultMetrics = client.collectDefaultMetrics;
|
||||
const Registry = client.Registry;
|
||||
const register = new Registry();
|
||||
collectDefaultMetrics({register});
|
||||
const gaugeDB = new client.Gauge({
|
||||
name: "ueberdb_stats",
|
||||
help: "ueberdb stats",
|
||||
labelNames: ['type'],
|
||||
})
|
||||
const db = require('./db/DB').db;
|
||||
const PadMessageHandler = require('./handler/PadMessageHandler');
|
||||
|
||||
const register = new client.Registry();
|
||||
const gaugeDB = new client.Gauge({
|
||||
name: 'ueberdb_stats',
|
||||
help: 'ueberdb stats',
|
||||
labelNames: ['type'],
|
||||
});
|
||||
register.registerMetric(gaugeDB);
|
||||
|
||||
const totalUsersGauge = new client.Gauge({
|
||||
name: 'etherpad_total_users',
|
||||
help: 'Total number of users',
|
||||
});
|
||||
register.registerMetric(totalUsersGauge);
|
||||
|
||||
const activePadsGauge = new client.Gauge({
|
||||
name: 'etherpad_active_pads',
|
||||
help: 'Total number of active pads',
|
||||
});
|
||||
register.registerMetric(activePadsGauge);
|
||||
|
||||
client.collectDefaultMetrics({register});
|
||||
|
||||
const monitor = async function () {
|
||||
for (const [metric, value] of Object.entries(db.metrics)) {
|
||||
if (typeof value !== 'number') continue;
|
||||
gaugeDB.set({type: metric}, value);
|
||||
}
|
||||
|
||||
|
||||
register.registerMetric(gaugeDB);
|
||||
return register
|
||||
activePadsGauge.set(PadMessageHandler.getActivePadCountFromSessionInfos());
|
||||
totalUsersGauge.set(PadMessageHandler.getTotalActiveUsers());
|
||||
return register;
|
||||
};
|
||||
|
||||
export default monitor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue