summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Mehren2021-04-25 20:34:03 +0200
committerGitHub2021-04-25 20:34:03 +0200
commit2faf5b69741e2ff9b310b63295e4f8b50ce2ca80 (patch)
tree718f172f6b8edf63a92682a512b5d9c6bc43b188 /lib
parentc8e2117452c905a75c4644e4e2c2dea95aaa8f81 (diff)
parentcbe7b03b59af80ae6ae3c51a19c334fe8e478da2 (diff)
Merge pull request #1150 from hedgedoc/feature/prometheus_metrics
Diffstat (limited to '')
-rw-r--r--lib/prometheus.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/prometheus.js b/lib/prometheus.js
new file mode 100644
index 00000000..1ffb9ad7
--- /dev/null
+++ b/lib/prometheus.js
@@ -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)
+ })
+ }
+ })
+}