lol

mtr-exporter: support specifying multiple jobs

This ability has been added in `0.3.0` release:
https://github.com/mgumz/mtr-exporter/releases/tag/0.3.0
https://github.com/NixOS/nixpkgs/pull/252667

To achieve this a config is generated and symlinked at `/etc/mtr-exporter.conf`.

Signed-off-by: Jakub Sokołowski <jakub@status.im>

+83 -30
+2
nixos/doc/manual/release-notes/rl-2311.section.md
··· 224 224 225 225 - `rome` was removed because it is no longer maintained and is succeeded by `biome`. 226 226 227 + - The `services.mtr-exporter.target` has been removed in favor of `services.mtr-exporter.jobs` which allows specifying multiple targets. 228 + 227 229 ## Other Notable Changes {#sec-release-23.11-notable-changes} 228 230 229 231 - The Cinnamon module now enables XDG desktop integration by default. If you are experiencing collisions related to xdg-desktop-portal-gtk you can safely remove `xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk ];` from your NixOS configuration.
+81 -30
nixos/modules/services/networking/mtr-exporter.nix
··· 2 2 3 3 let 4 4 inherit (lib) 5 - maintainers types mkEnableOption mkOption mkIf 6 - literalExpression escapeShellArg escapeShellArgs; 5 + maintainers types literalExpression 6 + escapeShellArg escapeShellArgs 7 + mkEnableOption mkOption mkRemovedOptionModule mkIf mdDoc 8 + optionalString concatMapStrings concatStringsSep; 9 + 7 10 cfg = config.services.mtr-exporter; 11 + 12 + jobsConfig = pkgs.writeText "mtr-exporter.conf" (concatMapStrings (job: '' 13 + ${job.name} -- ${job.schedule} -- ${concatStringsSep " " job.flags} ${job.address} 14 + '') cfg.jobs); 8 15 in { 16 + imports = [ 17 + (mkRemovedOptionModule [ "services" "mtr-exporter" "target" ] "Use services.mtr-exporter.jobs instead.") 18 + (mkRemovedOptionModule [ "services" "mtr-exporter" "mtrFlags" ] "Use services.mtr-exporter.jobs.<job>.flags instead.") 19 + ]; 20 + 9 21 options = { 10 22 services = { 11 23 mtr-exporter = { 12 - enable = mkEnableOption (lib.mdDoc "a Prometheus exporter for MTR"); 24 + enable = mkEnableOption (mdDoc "a Prometheus exporter for MTR"); 13 25 14 - target = mkOption { 26 + address = mkOption { 15 27 type = types.str; 16 - example = "example.org"; 17 - description = lib.mdDoc "Target to check using MTR."; 18 - }; 19 - 20 - interval = mkOption { 21 - type = types.int; 22 - default = 60; 23 - description = lib.mdDoc "Interval between MTR checks in seconds."; 28 + default = "127.0.0.1"; 29 + description = lib.mdDoc "Listen address for MTR exporter."; 24 30 }; 25 31 26 32 port = mkOption { 27 33 type = types.port; 28 34 default = 8080; 29 - description = lib.mdDoc "Listen port for MTR exporter."; 35 + description = mdDoc "Listen port for MTR exporter."; 30 36 }; 31 37 32 - address = mkOption { 33 - type = types.str; 34 - default = "127.0.0.1"; 35 - description = lib.mdDoc "Listen address for MTR exporter."; 38 + extraFlags = mkOption { 39 + type = types.listOf types.str; 40 + default = []; 41 + example = ["-flag.deprecatedMetrics"]; 42 + description = mdDoc '' 43 + Extra command line options to pass to MTR exporter. 44 + ''; 45 + }; 46 + 47 + package = mkOption { 48 + type = types.package; 49 + default = pkgs.mtr-exporter; 50 + defaultText = literalExpression "pkgs.mtr-exporter"; 51 + description = mdDoc "The MTR exporter package to use."; 52 + }; 53 + 54 + mtrPackage = mkOption { 55 + type = types.package; 56 + default = pkgs.mtr; 57 + defaultText = literalExpression "pkgs.mtr"; 58 + description = mdDoc "The MTR package to use."; 36 59 }; 37 60 38 - mtrFlags = mkOption { 39 - type = with types; listOf str; 40 - default = []; 41 - example = ["-G1"]; 42 - description = lib.mdDoc "Additional flags to pass to MTR."; 61 + jobs = mkOption { 62 + description = mdDoc "List of MTR jobs. Will be added to /etc/mtr-exporter.conf"; 63 + type = types.nonEmptyListOf (types.submodule { 64 + options = { 65 + name = mkOption { 66 + type = types.str; 67 + description = mdDoc "Name of ICMP pinging job."; 68 + }; 69 + 70 + address = mkOption { 71 + type = types.str; 72 + example = "host.example.org:1234"; 73 + description = mdDoc "Target address for MTR client."; 74 + }; 75 + 76 + schedule = mkOption { 77 + type = types.str; 78 + default = "@every 60s"; 79 + example = "@hourly"; 80 + description = mdDoc "Schedule of MTR checks. Also accepts Cron format."; 81 + }; 82 + 83 + flags = mkOption { 84 + type = with types; listOf str; 85 + default = []; 86 + example = ["-G1"]; 87 + description = mdDoc "Additional flags to pass to MTR."; 88 + }; 89 + }; 90 + }); 43 91 }; 44 92 }; 45 93 }; 46 94 }; 47 95 48 96 config = mkIf cfg.enable { 97 + environment.etc."mtr-exporter.conf" = { 98 + source = jobsConfig; 99 + }; 100 + 49 101 systemd.services.mtr-exporter = { 50 - script = '' 51 - exec ${pkgs.mtr-exporter}/bin/mtr-exporter \ 52 - -mtr ${pkgs.mtr}/bin/mtr \ 53 - -schedule '@every ${toString cfg.interval}s' \ 54 - -bind ${escapeShellArg cfg.address}:${toString cfg.port} \ 55 - -- \ 56 - ${escapeShellArgs (cfg.mtrFlags ++ [ cfg.target ])} 57 - ''; 58 102 wantedBy = [ "multi-user.target" ]; 59 103 requires = [ "network.target" ]; 60 104 after = [ "network.target" ]; 61 105 serviceConfig = { 106 + ExecStart = '' 107 + ${cfg.package}/bin/mtr-exporter \ 108 + -mtr '${cfg.mtrPackage}/bin/mtr' \ 109 + -bind ${escapeShellArg "${cfg.address}:${toString cfg.port}"} \ 110 + -jobs '${jobsConfig}' \ 111 + ${escapeShellArgs cfg.extraFlags} 112 + ''; 62 113 Restart = "on-failure"; 63 114 # Hardening 64 115 CapabilityBoundingSet = [ "" ];