diff options
author | azahi <azat@bahawi.net> | 2025-02-17 02:21:56 +0300 |
---|---|---|
committer | azahi <azat@bahawi.net> | 2025-02-17 02:21:56 +0300 |
commit | 59180328cda59817d71cd58c8f48ead047375064 (patch) | |
tree | 2cdd7d1bfa309839ef624c19daf283f510aacf69 /modules/monitoring/default.nix | |
parent | 2025-02-05 (diff) |
2025-02-17
Diffstat (limited to 'modules/monitoring/default.nix')
-rw-r--r-- | modules/monitoring/default.nix | 181 |
1 files changed, 90 insertions, 91 deletions
diff --git a/modules/monitoring/default.nix b/modules/monitoring/default.nix index 164ac5d..04fcccc 100644 --- a/modules/monitoring/default.nix +++ b/modules/monitoring/default.nix @@ -4,16 +4,15 @@ pkgs, ... }: -with lib; let cfg = config.nixfiles.modules.monitoring; in { - options.nixfiles.modules.monitoring.enable = mkEnableOption '' + options.nixfiles.modules.monitoring.enable = lib.mkEnableOption '' a glue to provision a monitoring stack ''; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { nixfiles.modules = { alertmanager.enable = true; grafana.enable = true; @@ -34,27 +33,27 @@ in # https://grafana.com/docs/grafana/latest/administration/provisioning/#data-sources datasources.settings.datasources = with config.nixfiles.modules; [ - (mkIf alertmanager.enable { + (lib.mkIf alertmanager.enable { name = "Alertmanager"; type = "alertmanager"; access = "proxy"; url = "https://${alertmanager.domain}"; jsonData.implementation = "prometheus"; }) - (mkIf loki.enable { + (lib.mkIf loki.enable { name = "Loki"; type = "loki"; access = "proxy"; url = "https://${loki.domain}"; isDefault = true; }) - (mkIf prometheus.enable { + (lib.mkIf prometheus.enable { name = "Prometheus"; type = "prometheus"; access = "proxy"; url = "https://${prometheus.domain}"; }) - (mkIf redis.enable { + (lib.mkIf redis.enable { name = "Redis"; type = "redis-datasource"; access = "proxy"; @@ -63,19 +62,19 @@ in }) ]; datasources.settings.deleteDatasources = with config.nixfiles.modules; [ - (mkIf (!alertmanager.enable) { + (lib.mkIf (!alertmanager.enable) { name = "Alertmanager"; orgId = 1; }) - (mkIf (!loki.enable) { + (lib.mkIf (!loki.enable) { name = "Loki"; orgId = 1; }) - (mkIf (!prometheus.enable) { + (lib.mkIf (!prometheus.enable) { name = "Prometheus"; orgId = 1; }) - (mkIf (!redis.enable) { + (lib.mkIf (!redis.enable) { name = "Redis"; orgId = 1; }) @@ -137,21 +136,18 @@ in prometheus = { scrapeConfigs = - with my.configurations; - mapAttrsToList + lib.mapAttrsToList (name: value: { job_name = name; static_configs = [ { - targets = - with value; - map ( - host: - concatStringsSep ":" [ - (if isAttrs host then host.hostname else host) - (toString port) - ] - ) hosts; + targets = map ( + host: + lib.concatStringsSep ":" [ + (if lib.isAttrs host then host.hostname else host) + (toString value.port) + ] + ) value.hosts; } ]; relabel_configs = [ @@ -160,76 +156,79 @@ in regex = "([^:]+):\\d+"; target_label = "instance"; } - ] ++ optionals (hasAttr "relabel" value) value.relabel; + ] ++ lib.optionals (lib.hasAttr "relabel" value) value.relabel; }) - { - promtail = { - hosts = [ - manwe - tulkas - varda - yavanna - ]; - inherit (config.nixfiles.modules.promtail) port; - }; - ntfy = { - hosts = [ manwe ]; - inherit (config.nixfiles.modules.ntfy.prometheus) port; - }; - soju = { - hosts = [ "127.0.0.1" ]; - inherit (config.nixfiles.modules.soju.prometheus) port; - }; - endlessh-go = { - hosts = [ - manwe - tulkas - varda - yavanna - ]; - inherit (config.services.endlessh-go.prometheus) port; - }; - exportarr-prowlarr = { - hosts = [ yavanna ]; - inherit (config.services.prometheus.exporters.exportarr-prowlarr) port; - }; - exportarr-lidarr = { - hosts = [ yavanna ]; - inherit (config.services.prometheus.exporters.exportarr-lidarr) port; - }; - nginx = { - hosts = [ - manwe - yavanna - ]; - inherit (config.services.prometheus.exporters.nginx) port; - }; - node = { - hosts = [ - manwe - tulkas - varda - yavanna - ]; - inherit (config.services.prometheus.exporters.node) port; - }; - postgres = { - hosts = [ manwe ]; - inherit (config.services.prometheus.exporters.postgres) port; - }; - redis = { - hosts = [ manwe ]; - inherit (config.services.prometheus.exporters.redis) port; - }; - unbound = { - hosts = [ manwe ]; - inherit (config.services.prometheus.exporters.unbound) port; - }; - wireguard = { - hosts = [ manwe ]; - inherit (config.services.prometheus.exporters.wireguard) port; - }; - }; + ( + with lib.my.configurations; + { + promtail = { + hosts = [ + manwe + tulkas + varda + yavanna + ]; + inherit (config.nixfiles.modules.promtail) port; + }; + ntfy = { + hosts = [ manwe ]; + inherit (config.nixfiles.modules.ntfy.prometheus) port; + }; + soju = { + hosts = [ "127.0.0.1" ]; + inherit (config.nixfiles.modules.soju.prometheus) port; + }; + endlessh-go = { + hosts = [ + manwe + tulkas + varda + yavanna + ]; + inherit (config.services.endlessh-go.prometheus) port; + }; + exportarr-prowlarr = { + hosts = [ yavanna ]; + inherit (config.services.prometheus.exporters.exportarr-prowlarr) port; + }; + exportarr-lidarr = { + hosts = [ yavanna ]; + inherit (config.services.prometheus.exporters.exportarr-lidarr) port; + }; + nginx = { + hosts = [ + manwe + yavanna + ]; + inherit (config.services.prometheus.exporters.nginx) port; + }; + node = { + hosts = [ + manwe + tulkas + varda + yavanna + ]; + inherit (config.services.prometheus.exporters.node) port; + }; + postgres = { + hosts = [ manwe ]; + inherit (config.services.prometheus.exporters.postgres) port; + }; + redis = { + hosts = [ manwe ]; + inherit (config.services.prometheus.exporters.redis) port; + }; + unbound = { + hosts = [ manwe ]; + inherit (config.services.prometheus.exporters.unbound) port; + }; + wireguard = { + hosts = [ manwe ]; + inherit (config.services.prometheus.exporters.wireguard) port; + }; + } + ); ruleFiles = [ ./rules/nginx.yaml |