From ec4d6379d0581a057b21d6d8d61bf08a907199a1 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Sun, 4 Jun 2023 15:23:47 +0200 Subject: [PATCH] service/hedgedoc: add monitoring and dashboard --- modules/services/hedgedoc/default.nix | 24 + pkgs/grafana-dashboards/default.nix | 10 + pkgs/grafana-dashboards/hedgedoc.json | 800 ++++++++++++++++++++++++++ 3 files changed, 834 insertions(+) create mode 100644 pkgs/grafana-dashboards/hedgedoc.json diff --git a/modules/services/hedgedoc/default.nix b/modules/services/hedgedoc/default.nix index 0be9e38..f7507bc 100644 --- a/modules/services/hedgedoc/default.nix +++ b/modules/services/hedgedoc/default.nix @@ -50,6 +50,30 @@ in #systemd.services.hedgedoc.serviceConfig.StateDirectory = lib.mkForce "/var/lib/hedgedoc"; systemd.services.hedgedoc.serviceConfig.StateDirectory = lib.mkForce "hedgedoc"; + services.prometheus = { + scrapeConfigs = [ + { + job_name = "hedgedoc"; + static_configs = [ + { + targets = [ "127.0.0.1:${toString cfg.port}" ]; + labels = { + instance = config.networking.hostName; + }; + } + ]; + } + ]; + }; + + services.grafana.provision.dashboards.settings.providers = [ + { + name = "Hedgedoc"; + options.path = pkgs.grafana-dashboards.hedgedoc; + disableDeletion = true; + } + ]; + my.services.nginx.virtualHosts = [ { subdomain = "notes"; diff --git a/pkgs/grafana-dashboards/default.nix b/pkgs/grafana-dashboards/default.nix index 54f592b..bdf8dee 100644 --- a/pkgs/grafana-dashboards/default.nix +++ b/pkgs/grafana-dashboards/default.nix @@ -67,6 +67,16 @@ in src = ./navidrome.json; # sadly data source is not detected }); + # taken from https://gitlab.archlinux.org/archlinux/infrastructure/-/blob/master/roles/grafana/files/dashboards/Hedgedoc.json?ref_type=heads + hedgedoc = (buildGrafanaDashboard { + id = -1; + pname = "hedgedoc"; + version = "1"; + hash = lib.fakeSha256; + }).overrideAttrs (self: super: { + src = ./hedgedoc.json; # sadly data source is not detected + }); + cadvisor = buildGrafanaDashboard { id = 10619; pname = "cadvisor"; diff --git a/pkgs/grafana-dashboards/hedgedoc.json b/pkgs/grafana-dashboards/hedgedoc.json new file mode 100644 index 0000000..cbf014e --- /dev/null +++ b/pkgs/grafana-dashboards/hedgedoc.json @@ -0,0 +1,800 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "datasource", + "uid": "grafana" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 55, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "description": "Hedgedoc notes stats", + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 1000 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "text": {}, + "textMode": "auto" + }, + "pluginVersion": "9.5.2", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "hedgedoc_notes", + "interval": "", + "legendFormat": "Notes", + "queryType": "randomWalk", + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "hedgedoc_online_notes ", + "hide": false, + "interval": "", + "legendFormat": "Online notes ", + "refId": "B" + }, + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "hedgedoc_registered_users", + "hide": false, + "interval": "", + "legendFormat": "Registered users", + "refId": "C" + }, + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "hedgedoc_online_users", + "hide": false, + "instant": false, + "interval": "", + "legendFormat": "Online users", + "refId": "D" + } + ], + "title": "hedgedoc stats", + "type": "stat" + }, + { + "cards": {}, + "color": { + "cardColor": "#b4ff00", + "colorScale": "sqrt", + "colorScheme": "interpolateOranges", + "exponent": 0.5, + "mode": "spectrum" + }, + "dataFormat": "timeseries", + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "description": "", + "fieldConfig": { + "defaults": { + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "scaleDistribution": { + "type": "linear" + } + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 24, + "x": 0, + "y": 6 + }, + "heatmap": {}, + "hideZeroBuckets": false, + "highlightCards": true, + "id": 6, + "legend": { + "show": false + }, + "options": { + "calculate": true, + "calculation": {}, + "cellGap": 2, + "cellValues": {}, + "color": { + "exponent": 0.5, + "fill": "#b4ff00", + "mode": "scheme", + "reverse": false, + "scale": "exponential", + "scheme": "Oranges", + "steps": 128 + }, + "exemplars": { + "color": "rgba(255,0,255,0.7)" + }, + "filterValues": { + "le": 1e-9 + }, + "legend": { + "show": false + }, + "rowsFrame": { + "layout": "auto" + }, + "showValue": "never", + "tooltip": { + "show": true, + "yHistogram": false + }, + "yAxis": { + "axisPlacement": "left", + "reverse": false, + "unit": "s" + } + }, + "pluginVersion": "9.5.2", + "reverseYBuckets": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "sum by (le) (rate(http_request_duration_seconds_bucket{job=\"hedgedoc\"}[3m]))", + "interval": "", + "legendFormat": "{{ le }}", + "queryType": "randomWalk", + "refId": "A" + } + ], + "title": "Request duration", + "tooltip": { + "show": true, + "showHistogram": false + }, + "type": "heatmap", + "xAxis": { + "show": true + }, + "yAxis": { + "format": "s", + "logBase": 1, + "show": true + }, + "yBucketBound": "auto" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 10, + "x": 0, + "y": 14 + }, + "hiddenSeries": false, + "id": 8, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "paceLength": 10, + "percentage": false, + "pluginVersion": "9.5.2", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "irate(process_cpu_user_seconds_total{job=\"hedgedoc\"}[2m]) * 100", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "User CPU", + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "irate(process_cpu_system_seconds_total{job=\"hedgedoc\"}[2m]) * 100", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "Sys CPU", + "refId": "B" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Process CPU Usage", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:147", + "format": "percent", + "logBase": 1, + "show": true + }, + { + "$$hashKey": "object:148", + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 9, + "x": 10, + "y": 14 + }, + "hiddenSeries": false, + "id": 10, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "paceLength": 10, + "percentage": false, + "pluginVersion": "9.5.2", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "nodejs_eventloop_lag_seconds{job=\"hedgedoc\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "hedgedoc", + "refId": "A" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Event Loop Lag", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:205", + "format": "s", + "logBase": 1, + "show": true + }, + { + "$$hashKey": "object:206", + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "description": "Length of connection socket queue and connection busy indicates that realtime currently connecting", + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 5, + "x": 19, + "y": 14 + }, + "hiddenSeries": false, + "id": 4, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "9.5.2", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "hedgedoc_connection_busy", + "interval": "", + "legendFormat": "connections busy", + "queryType": "randomWalk", + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "hedgedoc_connection_socket_queue_length", + "hide": false, + "interval": "", + "legendFormat": "socket queue length", + "refId": "B" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Connections", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:225", + "format": "short", + "logBase": 1, + "show": true + }, + { + "$$hashKey": "object:226", + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 16, + "x": 0, + "y": 21 + }, + "hiddenSeries": false, + "id": 12, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "rightSide": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "paceLength": 10, + "percentage": false, + "pluginVersion": "9.5.2", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "process_resident_memory_bytes{job=\"hedgedoc\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "Process Memory", + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "nodejs_heap_size_total_bytes{job=\"hedgedoc\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "Heap Total ", + "refId": "B" + }, + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "nodejs_heap_size_used_bytes{job=\"hedgedoc\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "Heap Used", + "refId": "C" + }, + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "nodejs_external_memory_bytes{job=\"hedgedoc\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "External Memory - {{instance}}", + "refId": "D" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Process Memory Usage", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:267", + "format": "bytes", + "logBase": 1, + "show": true + }, + { + "$$hashKey": "object:268", + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 21 + }, + "hiddenSeries": false, + "id": 14, + "legend": { + "alignAsTable": true, + "avg": true, + "current": true, + "max": true, + "min": true, + "show": true, + "total": false, + "values": true + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "paceLength": 10, + "percentage": false, + "pluginVersion": "9.5.2", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "nodejs_active_handles_total{job=\"hedgedoc\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "Active Handler ", + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "KNkR71YVk" + }, + "exemplar": true, + "expr": "nodejs_active_requests_total{job=\"hedgedoc\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "Active Request", + "refId": "B" + } + ], + "thresholds": [], + "timeRegions": [], + "title": "Active Handlers/Requests Total", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "mode": "time", + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:323", + "format": "short", + "logBase": 1, + "show": true + }, + { + "$$hashKey": "object:324", + "format": "short", + "logBase": 1, + "show": true + } + ], + "yaxis": { + "align": false + } + } + ], + "refresh": "", + "schemaVersion": 38, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-24h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Hedgedoc", + "uid": "U0Zk8-6Mk", + "version": 1, + "weekStart": "" +}