From 1524b6b10c7bd233f8435407b4fb575c9b91d8db Mon Sep 17 00:00:00 2001 From: h7x4 Date: Fri, 20 Jan 2023 01:08:09 +0100 Subject: [PATCH] metrics: stop parsing prometheus labels from url --- hosts/ildkule/services/metrics/prometheus.nix | 27 ------------------- hosts/jokum/services/matrix/synapse.nix | 23 +++++++++------- 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/hosts/ildkule/services/metrics/prometheus.nix b/hosts/ildkule/services/metrics/prometheus.nix index 90bba88..18b84c5 100644 --- a/hosts/ildkule/services/metrics/prometheus.nix +++ b/hosts/ildkule/services/metrics/prometheus.nix @@ -34,33 +34,6 @@ in { url = "https://matrix.pvv.ntnu.no/metrics/config.json"; } ]; - relabel_configs = [ - { - source_labels = [ "__address__" ]; - regex = "[^/]+(/.*)"; - target_label = "__metrics_path__"; - } - { - source_labels = [ "__address__" ]; - regex = "([^/]+)/.*"; - target_label = "instance"; - } - { - source_labels = [ "__address__" ]; - regex = "[^/]+\\/+[^/]+/(.*)/\\d+$"; - target_label = "job"; - } - { - source_labels = [ "__address__" ]; - regex = "[^/]+\\/+[^/]+/.*/(\\d+)$"; - target_label = "index"; - } - { - source_labels = [ "__address__" ]; - regex = "([^/]+)/.*"; - target_label = "__address__"; - } - ]; } ]; ruleFiles = [ rules/synapse-v2.rules ]; diff --git a/hosts/jokum/services/matrix/synapse.nix b/hosts/jokum/services/matrix/synapse.nix index 195cfb7..81e551f 100644 --- a/hosts/jokum/services/matrix/synapse.nix +++ b/hosts/jokum/services/matrix/synapse.nix @@ -206,17 +206,22 @@ in { }; locations."/metrics/" = let - endpoints = lib.pipe cfg.workers.instances [ + # See https://github.com/matrix-org/synapse/blob/develop/docs/metrics-howto.md + staticConfigs = lib.pipe cfg.workers.instances [ (lib.mapAttrsToList (_: v: v)) - (map (w: "${w.type}/${toString w.index}")) - (map (w: "matrix.pvv.ntnu.no/metrics/${w}")) - ] ++ [ "matrix.pvv.ntnu.no/metrics/master/1" ]; + # Add metrics for main process to the list of workers + (x: x ++ [{ type = "master"; index = 1; }]) + (map (w: { + targets = [ "matrix.pvv.ntnu.no/metrics/${w.type}/${toString w.index}" ]; + labels = { + instance = "matrix.pvv.ntnu.no"; + job = w.type; + index = toString w.index; + }; + })) + ]; in { - alias = pkgs.writeTextDir "/config.json" - (builtins.toJSON [ - { targets = endpoints; - labels = { }; - }]) + "/"; + alias = (pkgs.writeTextDir "/config.json" (builtins.toJSON staticConfigs)) + "/"; }; })]; }