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
|
const promClient = require('prom-client')
const realtime = require('./realtime')
exports.setupCustomPrometheusMetrics = function () {
const onlineNotes = new promClient.Gauge({
name: 'hedgedoc_online_notes',
help: 'Notes currently being edited'
})
const onlineSessions = new promClient.Gauge({
name: 'hedgedoc_online_sessions',
help: 'Sessions currently editing notes',
labelNames: ['type']
})
const onlineUsers = new promClient.Gauge({
name: 'hedgedoc_online_users',
help: 'Distinct users currently editing notes',
labelNames: ['type']
})
const notesCount = new promClient.Gauge({
name: 'hedgedoc_notes',
help: 'Notes in the instance'
})
const registeredUsers = new promClient.Gauge({
name: 'hedgedoc_registered_users',
help: 'Users that registered in the instance'
})
const isConnectionBusy = new promClient.Gauge({
name: 'hedgedoc_connection_busy',
help: 'Indicates that realtime currently connecting'
})
const connectionSocketQueueLength = new promClient.Gauge({
name: 'hedgedoc_connection_socket_queue_length',
help: 'Length of connection socket queue',
// The last gauge provides the collect callback for all metrics
collect () {
realtime.getStatus(function (data) {
onlineNotes.set(data.onlineNotes)
onlineSessions.set({ type: 'all' }, data.onlineUsers)
onlineSessions.set({ type: 'signed-in' }, data.onlineRegisteredUsers)
onlineUsers.set({ type: 'all' }, data.distinctOnlineUsers)
onlineUsers.set({ type: 'signed-in' }, data.distinctOnlineRegisteredUsers)
notesCount.set(data.notesCount)
registeredUsers.set(data.registeredUsers)
isConnectionBusy.set(data.isConnectionBusy ? 1 : 0)
connectionSocketQueueLength.set(data.connectionSocketQueueLength)
})
}
})
}
|