diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d7ee84..cff7d94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Revert Loki to major version 2 because upgrading to version 3 required manual intervention as Loki refuses to start. So until this issue is tackled, reverting is the best immediate fix. See https://github.com/NixOS/nixpkgs/commit/8f95320f39d7e4e4a29ee70b8718974295a619f4 +- Add prometheus deluge exporter support. It just needs the `shb.deluge.prometheusScraperPasswordFile` option to be set. ## Other Changes diff --git a/flake.nix b/flake.nix index 204621b..110f09c 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,10 @@ url = "https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/315018.patch"; hash = "sha256-8jcGyO/d+htfv/ZajxXh89S3OiDZAr7/fsWC1JpGczM="; }) + (originPkgs.fetchpatch { + url = "https://github.com/NixOS/nixpkgs/pull/317107.patch"; + hash = "sha256-/bFQVxQgrDrMlACQGWBpMk76+PaA5mP9HuWm9MwCs/0="; + }) ]; patchedNixpkgs = originPkgs.applyPatches { name = "nixpkgs-patched"; diff --git a/modules/services/deluge.nix b/modules/services/deluge.nix index 45a1680..817bac4 100644 --- a/modules/services/deluge.nix +++ b/modules/services/deluge.nix @@ -182,6 +182,12 @@ in type = lib.types.path; }; + prometheusScraperPasswordFile = lib.mkOption { + description = "File containing password for prometheus scraper. Setting this option will activate the prometheus deluge exporter."; + type = lib.types.nullOr lib.types.path; + default = null; + }; + enabledPlugins = lib.mkOption { type = lib.types.listOf lib.types.str; description = '' @@ -266,7 +272,9 @@ in systemd.services.deluged.preStart = lib.mkBefore (shblib.replaceSecrets { userConfig = cfg.extraUsers // { localclient.password.source = config.shb.deluge.localclientPasswordFile; - }; + } // (lib.optionalAttrs (config.shb.deluge.prometheusScraperPasswordFile != null) { + prometheus_scraper.password.source = config.shb.deluge.prometheusScraperPasswordFile; + }); resultPath = "${config.services.deluge.dataDir}/.config/deluge/authTemplate"; generator = name: value: pkgs.writeText "delugeAuth" (authGenerator value); }); @@ -320,5 +328,24 @@ in }; } { systemd.services.deluged.serviceConfig = cfg.extraServiceConfig; - }]); + } (lib.mkIf (config.shb.deluge.prometheusScraperPasswordFile != null) { + services.prometheus.exporters.deluge = { + enable = true; + + delugeHost = "127.0.0.1"; + delugePort = config.services.deluge.config.daemon_port; + delugeUser = "prometheus_scraper"; + delugePasswordFile = config.shb.deluge.prometheusScraperPasswordFile; + }; + + services.prometheus.scrapeConfigs = [ + { + job_name = "deluge"; + static_configs = [{ + targets = ["127.0.0.1:${toString config.services.prometheus.exporters.deluge.port}"]; + }]; + } + ]; + }) + ]); } diff --git a/test/vm/deluge.nix b/test/vm/deluge.nix index 7e779cb..f419cca 100644 --- a/test/vm/deluge.nix +++ b/test/vm/deluge.nix @@ -98,6 +98,21 @@ let raise Exception(f"result had an error {response['error']}") ''; + prometheusTestScript = { nodes, ... }: + let + hasSSL = !(isNull nodes.server.shb.deluge.ssl); + proto_fqdn = if hasSSL then "https://${fqdn}" else "http://${fqdn}"; + in + '' + server.wait_for_open_port(${toString nodes.server.services.prometheus.exporters.deluge.port}) + with subtest("prometheus"): + response = server.succeed( + "curl -sSf " + + " http://localhost:${toString nodes.server.services.prometheus.exporters.deluge.port}/metrics" + ) + print(response) + ''; + base = { imports = [ (pkgs'.path + "/nixos/modules/profiles/headless.nix") @@ -293,4 +308,27 @@ in # # testScript = commonTestScript; # }; + + prometheus = pkgs.testers.runNixOSTest { + name = "deluge_https"; + + nodes.server = lib.mkMerge [ + base + certs + basic + https + prometheus + { + options = { + shb.authelia = lib.mkOption { type = lib.types.anything; }; + }; + } + ]; + + nodes.client = {}; + + testScript = inputs: + (commonTestScript inputs) + + (prometheusTestScript inputs); + }; }