2022-01-08 10:52:36 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib)
|
2023-09-10 10:01:34 +00:00
|
|
|
maintainers types literalExpression
|
|
|
|
escapeShellArg escapeShellArgs
|
2024-04-13 13:11:11 +00:00
|
|
|
mkEnableOption mkOption mkRemovedOptionModule mkIf
|
2023-11-27 00:19:27 +00:00
|
|
|
mkPackageOption optionalString concatMapStrings concatStringsSep;
|
2023-09-10 10:01:34 +00:00
|
|
|
|
2022-01-08 10:52:36 +00:00
|
|
|
cfg = config.services.mtr-exporter;
|
2023-09-10 10:01:34 +00:00
|
|
|
|
|
|
|
jobsConfig = pkgs.writeText "mtr-exporter.conf" (concatMapStrings (job: ''
|
|
|
|
${job.name} -- ${job.schedule} -- ${concatStringsSep " " job.flags} ${job.address}
|
|
|
|
'') cfg.jobs);
|
2022-01-08 10:52:36 +00:00
|
|
|
in {
|
2023-09-10 10:01:34 +00:00
|
|
|
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.")
|
|
|
|
];
|
|
|
|
|
2022-01-08 10:52:36 +00:00
|
|
|
options = {
|
|
|
|
services = {
|
|
|
|
mtr-exporter = {
|
2023-09-10 10:01:34 +00:00
|
|
|
enable = mkEnableOption "a Prometheus exporter for MTR";
|
2022-01-08 10:52:36 +00:00
|
|
|
|
2023-09-10 10:01:34 +00:00
|
|
|
address = mkOption {
|
2022-01-08 10:52:36 +00:00
|
|
|
type = types.str;
|
2023-09-10 10:01:34 +00:00
|
|
|
default = "127.0.0.1";
|
|
|
|
description = "Listen address for MTR exporter.";
|
2022-01-08 10:52:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8080;
|
2023-09-10 10:01:34 +00:00
|
|
|
description = "Listen port for MTR exporter.";
|
2022-01-08 10:52:36 +00:00
|
|
|
};
|
|
|
|
|
2023-09-10 10:01:34 +00:00
|
|
|
extraFlags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = ["-flag.deprecatedMetrics"];
|
|
|
|
description = ''
|
|
|
|
Extra command line options to pass to MTR exporter.
|
|
|
|
'';
|
2022-01-08 10:52:36 +00:00
|
|
|
};
|
|
|
|
|
2023-11-27 00:19:27 +00:00
|
|
|
package = mkPackageOption pkgs "mtr-exporter" { };
|
2023-09-10 10:01:34 +00:00
|
|
|
|
2023-11-27 00:19:27 +00:00
|
|
|
mtrPackage = mkPackageOption pkgs "mtr" { };
|
2023-09-10 10:01:34 +00:00
|
|
|
|
|
|
|
jobs = mkOption {
|
|
|
|
description = "List of MTR jobs. Will be added to /etc/mtr-exporter.conf";
|
|
|
|
type = types.nonEmptyListOf (types.submodule {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Name of ICMP pinging job.";
|
|
|
|
};
|
|
|
|
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "host.example.org:1234";
|
|
|
|
description = "Target address for MTR client.";
|
|
|
|
};
|
|
|
|
|
|
|
|
schedule = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "@every 60s";
|
|
|
|
example = "@hourly";
|
|
|
|
description = "Schedule of MTR checks. Also accepts Cron format.";
|
|
|
|
};
|
|
|
|
|
|
|
|
flags = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [];
|
|
|
|
example = ["-G1"];
|
|
|
|
description = "Additional flags to pass to MTR.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
2022-01-08 10:52:36 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-09-10 10:01:34 +00:00
|
|
|
environment.etc."mtr-exporter.conf" = {
|
|
|
|
source = jobsConfig;
|
|
|
|
};
|
|
|
|
|
2022-01-08 10:52:36 +00:00
|
|
|
systemd.services.mtr-exporter = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "network.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
serviceConfig = {
|
2023-09-10 10:01:34 +00:00
|
|
|
ExecStart = ''
|
|
|
|
${cfg.package}/bin/mtr-exporter \
|
|
|
|
-mtr '${cfg.mtrPackage}/bin/mtr' \
|
|
|
|
-bind ${escapeShellArg "${cfg.address}:${toString cfg.port}"} \
|
|
|
|
-jobs '${jobsConfig}' \
|
|
|
|
${escapeShellArgs cfg.extraFlags}
|
|
|
|
'';
|
2022-01-08 10:52:36 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
# Hardening
|
|
|
|
CapabilityBoundingSet = [ "" ];
|
|
|
|
DynamicUser = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
ProcSubset = "pid";
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ jakubgs ];
|
|
|
|
}
|