mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 17:26:29 -05:00
Add custom prometheus metrics
This reuses the `realtime.getStatus` method to get the state of the application state on every prometheus scrape cycle. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
8914df60a9
commit
5c70cc021f
2 changed files with 51 additions and 0 deletions
2
app.js
2
app.js
|
@ -26,6 +26,7 @@ const logger = require('./lib/logger')
|
||||||
const errors = require('./lib/errors')
|
const errors = require('./lib/errors')
|
||||||
const models = require('./lib/models')
|
const models = require('./lib/models')
|
||||||
const csp = require('./lib/csp')
|
const csp = require('./lib/csp')
|
||||||
|
const metrics = require('./lib/prometheus')
|
||||||
|
|
||||||
// server setup
|
// server setup
|
||||||
const app = express()
|
const app = express()
|
||||||
|
@ -66,6 +67,7 @@ app.use(morgan('combined', {
|
||||||
|
|
||||||
// Register prometheus metrics endpoint
|
// Register prometheus metrics endpoint
|
||||||
app.use(apiMetrics())
|
app.use(apiMetrics())
|
||||||
|
metrics.setupCustomPrometheusMetrics()
|
||||||
|
|
||||||
// socket io
|
// socket io
|
||||||
const io = require('socket.io')(server, { cookie: false })
|
const io = require('socket.io')(server, { cookie: false })
|
||||||
|
|
49
lib/prometheus.js
Normal file
49
lib/prometheus.js
Normal file
|
@ -0,0 +1,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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in a new issue