From a7408b880031cab8a13a0d447fae4cc3b31dfd00 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sat, 21 Jan 2023 19:55:29 +0100 Subject: [PATCH] ildkule: restructure prometheus config --- hosts/ildkule/services/metrics/default.nix | 2 +- hosts/ildkule/services/metrics/prometheus.nix | 68 ------------------- .../services/metrics/prometheus/default.nix | 14 ++++ .../metrics/prometheus/matrix-synapse.nix | 40 +++++++++++ .../services/metrics/prometheus/node.nix | 20 ++++++ .../{ => prometheus}/rules/synapse-v2.rules | 0 6 files changed, 75 insertions(+), 69 deletions(-) delete mode 100644 hosts/ildkule/services/metrics/prometheus.nix create mode 100644 hosts/ildkule/services/metrics/prometheus/default.nix create mode 100644 hosts/ildkule/services/metrics/prometheus/matrix-synapse.nix create mode 100644 hosts/ildkule/services/metrics/prometheus/node.nix rename hosts/ildkule/services/metrics/{ => prometheus}/rules/synapse-v2.rules (100%) diff --git a/hosts/ildkule/services/metrics/default.nix b/hosts/ildkule/services/metrics/default.nix index 3493e56..a0a6a40 100644 --- a/hosts/ildkule/services/metrics/default.nix +++ b/hosts/ildkule/services/metrics/default.nix @@ -2,7 +2,7 @@ { imports = [ - ./prometheus.nix + ./prometheus ./grafana.nix ./loki.nix ]; diff --git a/hosts/ildkule/services/metrics/prometheus.nix b/hosts/ildkule/services/metrics/prometheus.nix deleted file mode 100644 index 90bba88..0000000 --- a/hosts/ildkule/services/metrics/prometheus.nix +++ /dev/null @@ -1,68 +0,0 @@ -{ config, pkgs, ... }: - -let - cfg = config.services.prometheus; -in { - services.prometheus = { - enable = true; - listenAddress = "127.0.0.1"; - port = 9001; - - scrapeConfigs = [ - { - job_name = "node"; - static_configs = [ - { - targets = [ - "ildkule.pvv.ntnu.no:${toString cfg.exporters.node.port}" - "microbel.pvv.ntnu.no:9100" - "isvegg.pvv.ntnu.no:9100" - "knakelibrak.pvv.ntnu.no:9100" - "hildring.pvv.ntnu.no:9100" - "bicep.pvv.ntnu.no:9100" - "jokum.pvv.ntnu.no:9100" - ]; - } - ]; - } - { - job_name = "synapse"; - scrape_interval = "15s"; - scheme = "https"; - http_sd_configs = [ - { - 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/ildkule/services/metrics/prometheus/default.nix b/hosts/ildkule/services/metrics/prometheus/default.nix new file mode 100644 index 0000000..21f689b --- /dev/null +++ b/hosts/ildkule/services/metrics/prometheus/default.nix @@ -0,0 +1,14 @@ +{ config, ... }: { + imports = [ + ./node.nix + ./matrix-synapse.nix + ]; + + services.prometheus = { + enable = true; + listenAddress = "127.0.0.1"; + port = 9001; + + ruleFiles = [ rules/synapse-v2.rules ]; + }; +} diff --git a/hosts/ildkule/services/metrics/prometheus/matrix-synapse.nix b/hosts/ildkule/services/metrics/prometheus/matrix-synapse.nix new file mode 100644 index 0000000..8a9f400 --- /dev/null +++ b/hosts/ildkule/services/metrics/prometheus/matrix-synapse.nix @@ -0,0 +1,40 @@ +{ ... }: +{ + services.prometheus.scrapeConfigs = [{ + job_name = "synapse"; + scrape_interval = "15s"; + scheme = "https"; + + http_sd_configs = [{ + 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__"; + } + ]; + }]; +} diff --git a/hosts/ildkule/services/metrics/prometheus/node.nix b/hosts/ildkule/services/metrics/prometheus/node.nix new file mode 100644 index 0000000..23a1969 --- /dev/null +++ b/hosts/ildkule/services/metrics/prometheus/node.nix @@ -0,0 +1,20 @@ +{ config, ... }: let + cfg = config.services.prometheus; +in { + services.prometheus.scrapeConfigs = [{ + job_name = "node"; + static_configs = [ + { + targets = [ + "ildkule.pvv.ntnu.no:${toString cfg.exporters.node.port}" + "microbel.pvv.ntnu.no:9100" + "isvegg.pvv.ntnu.no:9100" + "knakelibrak.pvv.ntnu.no:9100" + "hildring.pvv.ntnu.no:9100" + "bicep.pvv.ntnu.no:9100" + "jokum.pvv.ntnu.no:9100" + ]; + } + ]; + }]; +} diff --git a/hosts/ildkule/services/metrics/rules/synapse-v2.rules b/hosts/ildkule/services/metrics/prometheus/rules/synapse-v2.rules similarity index 100% rename from hosts/ildkule/services/metrics/rules/synapse-v2.rules rename to hosts/ildkule/services/metrics/prometheus/rules/synapse-v2.rules