diff --git a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
index c389d19de14..74308b24b65 100644
--- a/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
+++ b/nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
@@ -96,6 +96,13 @@
services.maddy.
+
+
+ mtr-exporter,
+ a Prometheus exporter for mtr metrics. Available as
+ services.mtr-exporter.
+
+
tetrd, share your
diff --git a/nixos/doc/manual/release-notes/rl-2205.section.md b/nixos/doc/manual/release-notes/rl-2205.section.md
index c5da4acb87d..4979aff0595 100644
--- a/nixos/doc/manual/release-notes/rl-2205.section.md
+++ b/nixos/doc/manual/release-notes/rl-2205.section.md
@@ -31,6 +31,8 @@ In addition to numerous new and upgraded packages, this release has the followin
- [maddy](https://maddy.email), a composable all-in-one mail server. Available as [services.maddy](options.html#opt-services.maddy.enable).
+- [mtr-exporter](https://github.com/mgumz/mtr-exporter), a Prometheus exporter for mtr metrics. Available as [services.mtr-exporter](options.html#opt-services.mtr-exporter.enable).
+
- [tetrd](https://tetrd.app), share your internet connection from your device to your PC and vice versa through a USB cable. Available at [services.tetrd](#opt-services.tetrd.enable).
## Backward Incompatibilities {#sec-release-22.05-incompatibilities}
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 1ee4b4e88a9..225b4fd5119 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -797,6 +797,7 @@
./services/networking/miredo.nix
./services/networking/mstpd.nix
./services/networking/mtprotoproxy.nix
+ ./services/networking/mtr-exporter.nix
./services/networking/mullvad-vpn.nix
./services/networking/multipath.nix
./services/networking/murmur.nix
diff --git a/nixos/modules/services/networking/mtr-exporter.nix b/nixos/modules/services/networking/mtr-exporter.nix
new file mode 100644
index 00000000000..ca261074ebd
--- /dev/null
+++ b/nixos/modules/services/networking/mtr-exporter.nix
@@ -0,0 +1,87 @@
+{ config, lib, pkgs, ... }:
+
+let
+ inherit (lib)
+ maintainers types mkEnableOption mkOption mkIf
+ literalExpression escapeShellArg escapeShellArgs;
+ cfg = config.services.mtr-exporter;
+in {
+ options = {
+ services = {
+ mtr-exporter = {
+ enable = mkEnableOption "a Prometheus exporter for MTR";
+
+ target = mkOption {
+ type = types.str;
+ example = "example.org";
+ description = "Target to check using MTR.";
+ };
+
+ interval = mkOption {
+ type = types.int;
+ default = 60;
+ description = "Interval between MTR checks in seconds.";
+ };
+
+ port = mkOption {
+ type = types.port;
+ default = 8080;
+ description = "Listen port for MTR exporter.";
+ };
+
+ address = mkOption {
+ type = types.str;
+ default = "127.0.0.1";
+ description = "Listen address for MTR exporter.";
+ };
+
+ mtrFlags = mkOption {
+ type = with types; listOf str;
+ default = [];
+ example = ["-G1"];
+ description = "Additional flags to pass to MTR.";
+ };
+ };
+ };
+ };
+
+ config = mkIf cfg.enable {
+ 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" ];
+ requires = [ "network.target" ];
+ after = [ "network.target" ];
+ serviceConfig = {
+ 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 ];
+}
diff --git a/pkgs/tools/networking/mtr-exporter/default.nix b/pkgs/tools/networking/mtr-exporter/default.nix
new file mode 100644
index 00000000000..0243774262a
--- /dev/null
+++ b/pkgs/tools/networking/mtr-exporter/default.nix
@@ -0,0 +1,25 @@
+{ lib, buildGoModule, fetchurl, fetchFromGitHub }:
+
+buildGoModule rec {
+ pname = "mtr-exporter";
+ version = "0.1.0";
+
+ src = fetchFromGitHub {
+ owner = "mgumz";
+ repo = "mtr-exporter";
+ rev = "3ce854a53a44780d2294f59284d21b06aeae6940";
+ sha256 = "sha256-PZCSuvtTBD7yoUE1fR9Z/u3aa1BZgbrcj18smnWRYf4=";
+ };
+
+ vendorSha256 = "0njn0ac7j3lv8ax6jc3bg3hh96a42jal212qk6zxrd46nb5l1rj8";
+
+ meta = with lib; {
+ description = ''
+ Mtr-exporter periodically executes mtr to a given host and
+ provides the measured results as prometheus metrics.
+ '';
+ homepage = "https://github.com/mgumz/mtr-exporter";
+ license = licenses.bsd3;
+ maintainers = with maintainers; [ jakubgs ];
+ };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index e4a599c7c17..9e65b4cc94e 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -7867,6 +7867,8 @@ with pkgs;
mtr = callPackage ../tools/networking/mtr {};
+ mtr-exporter = callPackage ../tools/networking/mtr-exporter {};
+
mtr-gui = callPackage ../tools/networking/mtr { withGtk = true; };
mtx = callPackage ../tools/backup/mtx {};