hackmdio / hackmdio/codimd

Prometheus metrics

Open
#1,554 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
10.1k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Hi,

I've been trying to setup Prometheus scraping metrics out of CodiMD, and use the following dashboard visualizing them:
https://grafana.com/grafana/dashboards/12214

I'm quite new to Prometheus, and find it confusing to have two endpoints (`metrics/router` and `/metrics/codimd`), to scrape metrics from.

FYI, I'm now using the following patch, centralizing all metrics into the same location. I've also introduced a `codimd_` prefix for metrics that used to be served at `/metrics/codimd`, arguably preventing from mixing them up with something else:

```
--- ../codimd/lib/realtime/realtime.js 2020-07-08 21:09:08.120466578 +0200
+++ ./lib/realtime/realtime.js 2020-07-13 11:38:11.744836709 +0200
@@ -9,6 +9,22 @@
const chance = new Chance()
const moment = require('moment')

+// Merging CodiMD metrics into Prometheus main /metrics/router endpoint
+const pclt = require('prom-client');
+const ctrs = [ 'online_notes', 'online_users', 'distinct_online_users',
+ 'notes_count', 'registered_users', 'online_registered_users',
+ 'distinct_online_registered_users', 'is_connection_busy',
+ 'connection_socket_queue_length', 'is_disconnect_busy',
+ 'disconnect_socket_queue_length' ];
+let gauges = [];
+for (let j = 0; j < ctrs.length; j++) {
+ gauges[ctrs[j]] = new pclt.Gauge({
+ name: `codimd_${ctrs[j]}`,
+ help: `CodiMD ${ctrs[j]}`
+ });
+}
+// end-of-patch
+
const get = require('lodash/get')

// core
@@ -282,7 +298,20 @@
})

return models.User.count()
- .then(function (regcount) {
+ .then((regcount) => {
+// Merging CodiMD metrics into Prometheus main /metrics/router endpoint
+ gauges['online_notes'].set(Object.keys(notes).length);
+ gauges['online_users'].set(Object.keys(users).length);
+ gauges['distinct_online_users'].set(distinctaddresses.length);
+ gauges['notes_count'].set(notecount);
+ gauges['registered_users'].set(regcount);
+ gauges['online_registered_users'].set(regaddresses.length);
+ gauges['distinct_online_registered_users'].set(distinctregaddresses.length);
+ gauges['is_connection_busy'].set(connectProcessQueue.lock);
+ gauges['connection_socket_queue_length'].set(connectProcessQueue.queue.length);
+ gauges['is_disconnect_busy'].set(disconnectProcessQueue.lock);
+ gauges['disconnect_socket_queue_length'].set(disconnectProcessQueue.queue.length);
+// end-of-patch
return {
onlineNotes: Object.keys(notes).length,
onlineUsers: Object.keys(users).length,
```

Not sure it really makes sense. I'ld gladly send a PR if it does.

Regards.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.