-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathprometheus.ts
More file actions
58 lines (50 loc) · 2 KB
/
prometheus.ts
File metadata and controls
58 lines (50 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import client from 'prom-client';
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);
// Added for the #7756 scaling dive: lets the load-test harness attribute
// where time goes (apply path vs. fan-out) and confirm per-pad concurrency.
// The metric handles live in prom-instruments.ts to avoid a circular import
// with PadMessageHandler (which records into them on the hot path).
// Gated behind settings.scalingDiveMetrics so production deployments don't
// pay for the instrumentation by default.
import {padUsersGauge, changesetApplyDuration, socketEmitsTotal, enabled as scalingDiveMetricsEnabled} from './prom-instruments';
if (scalingDiveMetricsEnabled()) {
register.registerMetric(padUsersGauge);
register.registerMetric(changesetApplyDuration);
register.registerMetric(socketEmitsTotal);
}
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);
}
activePadsGauge.set(PadMessageHandler.getActivePadCountFromSessionInfos());
totalUsersGauge.set(PadMessageHandler.getTotalActiveUsers());
if (scalingDiveMetricsEnabled()) {
// Per-pad concurrency: reset to avoid stale labels for pads that drained.
padUsersGauge.reset();
for (const [padId, count] of PadMessageHandler.getPadUsersMap()) {
padUsersGauge.set({padId}, count);
}
}
return register;
};
export default monitor;