mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 13:15:30 +03:00
Merge pull request #254370 from jakubgs/mtr-exporter/multi-job
mtr-exporter: support specifying multiple jobs
This commit is contained in:
commit
c51a273a92
2 changed files with 86 additions and 33 deletions
|
@ -224,6 +224,8 @@
|
||||||
|
|
||||||
- `rome` was removed because it is no longer maintained and is succeeded by `biome`.
|
- `rome` was removed because it is no longer maintained and is succeeded by `biome`.
|
||||||
|
|
||||||
|
- The `services.mtr-exporter.target` has been removed in favor of `services.mtr-exporter.jobs` which allows specifying multiple targets.
|
||||||
|
|
||||||
## Other Notable Changes {#sec-release-23.11-notable-changes}
|
## Other Notable Changes {#sec-release-23.11-notable-changes}
|
||||||
|
|
||||||
- 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.
|
- 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.
|
||||||
|
|
|
@ -2,32 +2,26 @@
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
maintainers types mkEnableOption mkOption mkIf
|
maintainers types literalExpression
|
||||||
literalExpression escapeShellArg escapeShellArgs;
|
escapeShellArg escapeShellArgs
|
||||||
|
mkEnableOption mkOption mkRemovedOptionModule mkIf mdDoc
|
||||||
|
optionalString concatMapStrings concatStringsSep;
|
||||||
|
|
||||||
cfg = config.services.mtr-exporter;
|
cfg = config.services.mtr-exporter;
|
||||||
|
|
||||||
|
jobsConfig = pkgs.writeText "mtr-exporter.conf" (concatMapStrings (job: ''
|
||||||
|
${job.name} -- ${job.schedule} -- ${concatStringsSep " " job.flags} ${job.address}
|
||||||
|
'') cfg.jobs);
|
||||||
in {
|
in {
|
||||||
|
imports = [
|
||||||
|
(mkRemovedOptionModule [ "services" "mtr-exporter" "target" ] "Use services.mtr-exporter.jobs instead.")
|
||||||
|
(mkRemovedOptionModule [ "services" "mtr-exporter" "mtrFlags" ] "Use services.mtr-exporter.jobs.<job>.flags instead.")
|
||||||
|
];
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
services = {
|
services = {
|
||||||
mtr-exporter = {
|
mtr-exporter = {
|
||||||
enable = mkEnableOption (lib.mdDoc "a Prometheus exporter for MTR");
|
enable = mkEnableOption (mdDoc "a Prometheus exporter for MTR");
|
||||||
|
|
||||||
target = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
example = "example.org";
|
|
||||||
description = lib.mdDoc "Target to check using MTR.";
|
|
||||||
};
|
|
||||||
|
|
||||||
interval = mkOption {
|
|
||||||
type = types.int;
|
|
||||||
default = 60;
|
|
||||||
description = lib.mdDoc "Interval between MTR checks in seconds.";
|
|
||||||
};
|
|
||||||
|
|
||||||
port = mkOption {
|
|
||||||
type = types.port;
|
|
||||||
default = 8080;
|
|
||||||
description = lib.mdDoc "Listen port for MTR exporter.";
|
|
||||||
};
|
|
||||||
|
|
||||||
address = mkOption {
|
address = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
|
@ -35,30 +29,87 @@ in {
|
||||||
description = lib.mdDoc "Listen address for MTR exporter.";
|
description = lib.mdDoc "Listen address for MTR exporter.";
|
||||||
};
|
};
|
||||||
|
|
||||||
mtrFlags = mkOption {
|
port = mkOption {
|
||||||
type = with types; listOf str;
|
type = types.port;
|
||||||
|
default = 8080;
|
||||||
|
description = mdDoc "Listen port for MTR exporter.";
|
||||||
|
};
|
||||||
|
|
||||||
|
extraFlags = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
default = [];
|
default = [];
|
||||||
example = ["-G1"];
|
example = ["-flag.deprecatedMetrics"];
|
||||||
description = lib.mdDoc "Additional flags to pass to MTR.";
|
description = mdDoc ''
|
||||||
|
Extra command line options to pass to MTR exporter.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
default = pkgs.mtr-exporter;
|
||||||
|
defaultText = literalExpression "pkgs.mtr-exporter";
|
||||||
|
description = mdDoc "The MTR exporter package to use.";
|
||||||
|
};
|
||||||
|
|
||||||
|
mtrPackage = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
default = pkgs.mtr;
|
||||||
|
defaultText = literalExpression "pkgs.mtr";
|
||||||
|
description = mdDoc "The MTR package to use.";
|
||||||
|
};
|
||||||
|
|
||||||
|
jobs = mkOption {
|
||||||
|
description = mdDoc "List of MTR jobs. Will be added to /etc/mtr-exporter.conf";
|
||||||
|
type = types.nonEmptyListOf (types.submodule {
|
||||||
|
options = {
|
||||||
|
name = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = mdDoc "Name of ICMP pinging job.";
|
||||||
|
};
|
||||||
|
|
||||||
|
address = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "host.example.org:1234";
|
||||||
|
description = mdDoc "Target address for MTR client.";
|
||||||
|
};
|
||||||
|
|
||||||
|
schedule = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "@every 60s";
|
||||||
|
example = "@hourly";
|
||||||
|
description = mdDoc "Schedule of MTR checks. Also accepts Cron format.";
|
||||||
|
};
|
||||||
|
|
||||||
|
flags = mkOption {
|
||||||
|
type = with types; listOf str;
|
||||||
|
default = [];
|
||||||
|
example = ["-G1"];
|
||||||
|
description = mdDoc "Additional flags to pass to MTR.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
environment.etc."mtr-exporter.conf" = {
|
||||||
|
source = jobsConfig;
|
||||||
|
};
|
||||||
|
|
||||||
systemd.services.mtr-exporter = {
|
systemd.services.mtr-exporter = {
|
||||||
script = ''
|
|
||||||
exec ${pkgs.mtr-exporter}/bin/mtr-exporter \
|
|
||||||
-mtr ${pkgs.mtr}/bin/mtr \
|
|
||||||
-schedule '@every ${toString cfg.interval}s' \
|
|
||||||
-bind ${escapeShellArg cfg.address}:${toString cfg.port} \
|
|
||||||
-- \
|
|
||||||
${escapeShellArgs (cfg.mtrFlags ++ [ cfg.target ])}
|
|
||||||
'';
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
requires = [ "network.target" ];
|
requires = [ "network.target" ];
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
|
ExecStart = ''
|
||||||
|
${cfg.package}/bin/mtr-exporter \
|
||||||
|
-mtr '${cfg.mtrPackage}/bin/mtr' \
|
||||||
|
-bind ${escapeShellArg "${cfg.address}:${toString cfg.port}"} \
|
||||||
|
-jobs '${jobsConfig}' \
|
||||||
|
${escapeShellArgs cfg.extraFlags}
|
||||||
|
'';
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
# Hardening
|
# Hardening
|
||||||
CapabilityBoundingSet = [ "" ];
|
CapabilityBoundingSet = [ "" ];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue