Merge pull request #317107 from ibizaman/deluge_exporter_init

prometheus-deluge-exporter: init at 2.4.0-unstable-2024-06-02

authored by Pol Dellaiera and committed by GitHub ed24a0ba 5827f495

+164
+16
nixos/modules/services/monitoring/prometheus/exporters.nix
··· 29 29 "blackbox" 30 30 "buildkite-agent" 31 31 "collectd" 32 + "deluge" 32 33 "dmarc" 33 34 "dnsmasq" 34 35 "dnssec" ··· 408 409 Please ensure you have either `services.prometheus.exporters.idrac.configuration' 409 410 or `services.prometheus.exporters.idrac.configurationPath' set! 410 411 ''; 412 + } { 413 + assertion = cfg.deluge.enable -> ( 414 + (cfg.deluge.delugePassword == null) != (cfg.deluge.delugePasswordFile == null) 415 + ); 416 + message = '' 417 + Please ensure you have either `services.prometheus.exporters.deluge.delugePassword' 418 + or `services.prometheus.exporters.deluge.delugePasswordFile' set! 419 + ''; 411 420 } ] ++ (flip map (attrNames exporterOpts) (exporter: { 412 421 assertion = cfg.${exporter}.firewallFilter != null -> cfg.${exporter}.openFirewall; 413 422 message = '' ··· 437 446 hardware.rtl-sdr.enable = mkDefault true; 438 447 })] ++ [(mkIf config.services.postfix.enable { 439 448 services.prometheus.exporters.postfix.group = mkDefault config.services.postfix.setgidGroup; 449 + })] ++ [(mkIf config.services.prometheus.exporters.deluge.enable { 450 + system.activationScripts = { 451 + deluge-exported.text = '' 452 + mkdir -p /etc/deluge-exporter 453 + echo "DELUGE_PASSWORD=$(cat ${config.services.prometheus.exporters.deluge.delugePasswordFile})" > /etc/deluge-exporter/password 454 + ''; 455 + }; 440 456 })] ++ (mapAttrsToList (name: conf: 441 457 mkExporterConf { 442 458 inherit name;
+85
nixos/modules/services/monitoring/prometheus/exporters/deluge.nix
··· 1 + { config, lib, pkgs, ... }: 2 + 3 + let 4 + cfg = config.services.prometheus.exporters.deluge; 5 + inherit (lib) mkOption types concatStringsSep; 6 + in 7 + { 8 + port = 9354; 9 + 10 + extraOpts = { 11 + delugeHost = mkOption { 12 + type = types.str; 13 + default = "localhost"; 14 + description = '' 15 + Hostname where deluge server is running. 16 + ''; 17 + }; 18 + 19 + delugePort = mkOption { 20 + type = types.port; 21 + default = 58846; 22 + description = '' 23 + Port where deluge server is listening. 24 + ''; 25 + }; 26 + 27 + delugeUser = mkOption { 28 + type = types.str; 29 + default = "localclient"; 30 + description = '' 31 + User to connect to deluge server. 32 + ''; 33 + }; 34 + 35 + delugePassword = mkOption { 36 + type = types.nullOr types.str; 37 + default = null; 38 + description = '' 39 + Password to connect to deluge server. 40 + 41 + This stores the password unencrypted in the nix store and is thus considered unsafe. Prefer 42 + using the delugePasswordFile option. 43 + ''; 44 + }; 45 + 46 + delugePasswordFile = mkOption { 47 + type = types.nullOr types.path; 48 + default = null; 49 + description = '' 50 + File containing the password to connect to deluge server. 51 + ''; 52 + }; 53 + 54 + exportPerTorrentMetrics = mkOption { 55 + type = types.bool; 56 + default = false; 57 + description = '' 58 + Enable per-torrent metrics. 59 + 60 + This may significantly increase the number of time series depending on the number of 61 + torrents in your Deluge instance. 62 + ''; 63 + }; 64 + }; 65 + serviceOpts = { 66 + serviceConfig = { 67 + ExecStart = '' 68 + ${pkgs.prometheus-deluge-exporter}/bin/deluge-exporter 69 + ''; 70 + Environment = [ 71 + "LISTEN_PORT=${toString cfg.port}" 72 + "LISTEN_ADDRESS=${toString cfg.listenAddress}" 73 + 74 + "DELUGE_HOST=${cfg.delugeHost}" 75 + "DELUGE_USER=${cfg.delugeUser}" 76 + "DELUGE_PORT=${toString cfg.delugePort}" 77 + ] ++ lib.optionals (cfg.delugePassword != null) [ 78 + "DELUGE_PASSWORD=${cfg.delugePassword}" 79 + ] ++ lib.optionals cfg.exportPerTorrentMetrics [ 80 + "PER_TORRENT_METRICS=1" 81 + ]; 82 + EnvironmentFile = lib.optionalString (cfg.delugePasswordFile != null) "/etc/deluge-exporter/password"; 83 + }; 84 + }; 85 + }
+28
nixos/tests/prometheus-exporters.nix
··· 209 209 ''; 210 210 }; 211 211 212 + deluge = { 213 + exporterConfig = { 214 + enable = true; 215 + port = 1234; 216 + listenAddress = "127.0.0.1"; 217 + 218 + delugeUser = "user"; 219 + delugePort = 2345; 220 + delugePasswordFile = pkgs.writeText "password" "weak_password"; 221 + }; 222 + metricProvider = { 223 + services.deluge.enable = true; 224 + services.deluge.declarative = true; 225 + services.deluge.config.daemon_port = 2345; 226 + services.deluge.authFile = pkgs.writeText "authFile" '' 227 + localclient:abcdef:10 228 + user:weak_password:10 229 + ''; 230 + }; 231 + exporterTest = '' 232 + wait_for_unit("deluged.service") 233 + wait_for_open_port(2345) 234 + wait_for_unit("prometheus-deluge-exporter.service") 235 + wait_for_open_port(1234) 236 + succeed("curl -sSf http://localhost:1234 | grep 'deluge_torrents'") 237 + ''; 238 + }; 239 + 212 240 dnsmasq = { 213 241 exporterConfig = { 214 242 enable = true;
+35
pkgs/by-name/pr/prometheus-deluge-exporter/package.nix
··· 1 + { lib 2 + , python3 3 + , fetchFromGitHub 4 + , nixosTests 5 + }: 6 + 7 + python3.pkgs.buildPythonApplication rec { 8 + pname = "deluge-exporter"; 9 + version = "2.4.0-unstable-2024-06-02"; 10 + 11 + src = fetchFromGitHub { 12 + owner = "ibizaman"; 13 + repo = "deluge_exporter"; 14 + rev = "8d446c8cba4a324aa052e66c115121b23adc970f"; 15 + hash = "sha256-1brLWx6IEGffcvHPCkz10k9GCNQIXXJ9PYZuEzlKHTA="; 16 + }; 17 + 18 + propagatedBuildInputs = with python3.pkgs; [ 19 + deluge-client 20 + loguru 21 + prometheus-client 22 + ]; 23 + 24 + pythonImportsCheck = [ 25 + "deluge_exporter" 26 + ]; 27 + 28 + meta = with lib; { 29 + description = "Prometheus exporter for Deluge"; 30 + homepage = "https://github.com/ibizaman/deluge_exporter"; 31 + license = licenses.isc; 32 + maintainers = with maintainers; [ ibizaman ]; 33 + mainProgram = "deluge-exporter"; 34 + }; 35 + }