Skip to content

Commit 8ded04a

Browse files
committed
chore: added prometheus support in Etherpad
1 parent b595ef9 commit 8ded04a

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

pnpm-lock.yaml

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node/hooks/express/specialpages.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ const plugins = require('../../../static/js/pluginfw/plugin_defs');
1313

1414
import {build, buildSync} from 'esbuild'
1515
import {ArgsExpressType} from "../../types/ArgsExpressType";
16+
import prometheus from "../../prometheus";
17+
1618
let ioI: { sockets: { sockets: any[]; }; } | null = null
1719

20+
1821
exports.socketio = (hookName: string, {io}: any) => {
1922
ioI = io
2023
}
@@ -35,6 +38,12 @@ exports.expressPreSession = async (hookName:string, {app}:ArgsExpressType) => {
3538
app.get('/stats', (req:any, res:any) => {
3639
res.json(require('../../stats').toJSON());
3740
});
41+
42+
app.get('/stats/prometheus', async (req, res) => {
43+
const metrics = await prometheus()
44+
res.setHeader('Content-Type', metrics.contentType)
45+
res.send(await metrics.metrics())
46+
})
3847
}
3948

4049

src/node/metrics.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Prometheus from 'prom-client';
2+
3+
export const metrics = {
4+
'cpu': new Prometheus.Gauge({ name: 'nodejs_cpu_gauge', help: 'gauge for nodejs cpu' ,labelNames: ['type'] }),
5+
'memory_process': new Prometheus.Gauge({ name: 'nodejs_memory_process_gauge', help: 'gauge for nodejs memory_process' ,labelNames: ['type'] }),
6+
'memory_physical': new Prometheus.Gauge({ name: 'nodejs_memory_physical_gauge', help: 'gauge for nodejs_memory_physical' ,labelNames: ['type'] }),
7+
'eventloop_latency': new Prometheus.Gauge({ name: 'nodejs_eventloop_latency_gauge' , help: 'gauge for nodejs_eventloop_latency' ,labelNames: ['type'] }),
8+
'gc': new Prometheus.Gauge({ name: 'nodejs_gc_gauge' , help: 'gause for nodejs_gc' ,labelNames: ['type']}),
9+
'gc_duration': new Prometheus.Summary({ name: 'nodejs_gc_duration' , help: 'gause for nodejs_gc_duration', percentiles: [ 0.5, 0.75, 0.95 ] }),
10+
'http_duration': new Prometheus.Summary({ name: 'http_duration', help: 'summary for http_duration', percentiles: [ 0.5, 0.75, 0.95 ] ,labelNames: ['url'] })
11+
};

src/node/prometheus.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import client from 'prom-client'
2+
const db = require('./db/DB').db
3+
4+
const monitor = function () {
5+
const collectDefaultMetrics = client.collectDefaultMetrics;
6+
const Registry = client.Registry;
7+
const register = new Registry();
8+
collectDefaultMetrics({register});
9+
const gaugeDB = new client.Gauge({
10+
name: "ueberdb_stats",
11+
help: "ueberdb stats",
12+
labelNames: ['type'],
13+
})
14+
15+
for (const [metric, value] of Object.entries(db.metrics)) {
16+
if (typeof value !== 'number') continue;
17+
gaugeDB.set({type: metric}, value);
18+
}
19+
20+
21+
register.registerMetric(gaugeDB);
22+
return register
23+
};
24+
25+
export default monitor;

src/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"mime-types": "^3.0.1",
5959
"oidc-provider": "^9.4.2",
6060
"openapi-backend": "^5.15.0",
61+
"prom-client": "^15.1.3",
6162
"proxy-addr": "^2.0.7",
6263
"rate-limiter-flexible": "^7.2.0",
6364
"rehype": "^13.0.2",

0 commit comments

Comments
 (0)