Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nixos/modules/services/monitoring/prometheus/exporters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ let
"smartctl"
"smokeping"
"snmp"
"speedtest"
"sql"
"statsd"
"storagebox"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
config,
lib,
pkgs,
utils,
...
}:

let
inherit (lib)
concatStringsSep
makeBinPath
mkOption
optionalString
types
;

cfg = config.services.prometheus.exporters.speedtest;
in
{
port = 9876;

extraOpts = with types; {
debug = mkOption {
type = bool;
default = false;
description = ''
Print debug information.
'';
};

refreshInterval = mkOption {
type = str;
default = "30m";
example = "1h";
description = ''
Refresh interval for the speedtest. It will cache the results for the given duration.
'';
};
};

serviceOpts = {
serviceConfig = {
StateDirectoryMode = "0750";
StateDirectory = "prometheus-speedtest-exporter";
WorkingDirectory = "/var/lib/prometheus-speedtest-exporter";

Environment = [
"PATH=${makeBinPath [ pkgs.ookla-speedtest ]}:$PATH"
"HOME=/var/lib/prometheus-speedtest-exporter"
];

ExecStart = concatStringsSep " " (
[
"${pkgs.prometheus-speedtest-exporter}/bin/speedtest-exporter"
"--bind ${cfg.listenAddress}:${toString cfg.port}"
"--refresh.interval ${cfg.refreshInterval}"
(optionalString cfg.debug "--debug")
]
++ cfg.extraFlags
);
};
};
}
14 changes: 14 additions & 0 deletions nixos/tests/prometheus-exporters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,20 @@ let
'';
};

speedtest = {
exporterConfig = {
enable = true;
debug = true;
refreshInterval = "1h";
};

exporterTest = ''
wait_for_unit("prometheus-speedtest-exporter.service")
wait_for_open_port(9876)
succeed("curl -sSf http://localhost:9876")
'';
};

storagebox = {
exporterConfig = {
enable = true;
Expand Down
37 changes: 37 additions & 0 deletions pkgs/by-name/pr/prometheus-speedtest-exporter/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
buildGoModule,
fetchFromGitHub,
lib,
nixosTests,
}:
buildGoModule (finalAttrs: {
pname = "speedtest-exporter";
version = "1.1.4";

src = fetchFromGitHub {
owner = "caarlos0";
repo = "speedtest-exporter";
tag = "v${finalAttrs.version}";
hash = "sha256-LKQVmGnKbznHHFZpa/SaqeMuCGUblnuYkZcsreq4f04=";
};
vendorHash = "sha256-KshKcOZOIrvjJ1vW/zuKo7yhrC4BGWial+AoYNXADGk=";

ldflags = [
"-s"
"-w"
"-X main.builtBy=nixpkgs"
"-X main.commit=unknown"
"-X main.date=unknown"
Comment on lines +22 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where did you get these from? i can only see version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"-X main.version=${finalAttrs.version}"
];

passthru.tests = { inherit (nixosTests.prometheus-exporters) speedtest; };

meta = {
homepage = "https://github.com/caarlos0/speedtest-exporter";
description = "Exports speedtests as prometheus metrics";
mainProgram = "speedtest-exporter";
maintainers = with lib.maintainers; [ emaiax ];
license = lib.licenses.asl20;
};
})
Loading