diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 83d19662a68e..d0a667121607 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -119,6 +119,7 @@ let "smartctl" "smokeping" "snmp" + "speedtest" "sql" "statsd" "storagebox" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/speedtest.nix b/nixos/modules/services/monitoring/prometheus/exporters/speedtest.nix new file mode 100644 index 000000000000..143cda300096 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/speedtest.nix @@ -0,0 +1,51 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.services.prometheus.exporters.speedtest; + inherit (lib) + mkOption + types + concatStringsSep + optionalString + ; +in +{ + port = 9798; + + extraOpts = { + serverID = mkOption { + type = types.int; + default = -1; + description = '' + Speedtest.net server ID to run tests against. + -1 picks the closest server to your location. + ''; + }; + + serverFallback = mkOption { + type = types.bool; + default = false; + description = '' + If the configured serverID is unavailable, fall back to the closest available server. + ''; + }; + }; + + serviceOpts = { + serviceConfig = { + ExecStart = '' + ${pkgs.prometheus-speedtest-exporter}/bin/speedtest_exporter \ + -listen-address ${cfg.listenAddress} \ + -port ${toString cfg.port} \ + -server_id ${toString cfg.serverID} \ + ${optionalString cfg.serverFallback "-server_fallback"} \ + ${concatStringsSep " \\\n " cfg.extraFlags} + ''; + }; + }; +} diff --git a/pkgs/by-name/pr/prometheus-speedtest-exporter/package.nix b/pkgs/by-name/pr/prometheus-speedtest-exporter/package.nix new file mode 100644 index 000000000000..8eee84e785da --- /dev/null +++ b/pkgs/by-name/pr/prometheus-speedtest-exporter/package.nix @@ -0,0 +1,28 @@ +{ + buildGoModule, + lib, + fetchFromGitHub, +}: + +buildGoModule (finalAttrs: { + __structuredAttrs = true; + pname = "prometheus-speedtest-exporter"; + version = "1.0.0"; + + src = fetchFromGitHub { + owner = "podocarp"; + repo = "speedtest_exporter"; + tag = "v${finalAttrs.version}"; + hash = "sha256-n9eunZRssS13mTOeFeZ/PpfSj430DKf3ZRS10hY4Ps8="; + }; + + vendorHash = "sha256-HBg44D0CUc4HYCBwGrswnrqG5o5ltA6UT8L0oWetlIc="; + + meta = { + description = "Speedtest.net Exporter for the Prometheus monitoring system"; + mainProgram = "speedtest_exporter"; + homepage = "https://github.com/podocarp/speedtest_exporter"; + license = lib.licenses.gpl3Only; + maintainers = with lib.maintainers; [ podocarp ]; + }; +})