diff --git a/nixos/modules/services/monitoring/prometheus/exporters/smartctl.nix b/nixos/modules/services/monitoring/prometheus/exporters/smartctl.nix index df424ede6066..0c5648c14149 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters/smartctl.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters/smartctl.nix @@ -4,16 +4,12 @@ with lib; let cfg = config.services.prometheus.exporters.smartctl; - format = pkgs.formats.yaml {}; - configFile = format.generate "smartctl-exporter.yml" { - smartctl_exporter = { - bind_to = "${cfg.listenAddress}:${toString cfg.port}"; - url_path = "/metrics"; - smartctl_location = "${pkgs.smartmontools}/bin/smartctl"; - collect_not_more_than_period = cfg.maxInterval; - devices = cfg.devices; - }; - }; + args = concatStrings [ + "--web.listen-address=\"${cfg.listenAddress}:${toString cfg.port}\" " + "--smartctl.path=\"${pkgs.smartmontools}/bin/smartctl\" " + "--smartctl.interval=\"${cfg.maxInterval}\" " + "${concatMapStringsSep " " (device: "--smartctl.device=${device}") cfg.devices}" + ]; in { port = 9633; @@ -50,17 +46,13 @@ in { "CAP_SYS_ADMIN" ]; DevicePolicy = "closed"; - DeviceAllow = lib.mkOverride 50 ( - if cfg.devices != [] then - cfg.devices - else [ - "block-blkext rw" - "block-sd rw" - "char-nvme rw" - ] - ); + DeviceAllow = lib.mkOverride 50 [ + "block-blkext rw" + "block-sd rw" + "char-nvme rw" + ]; ExecStart = '' - ${pkgs.prometheus-smartctl-exporter}/bin/smartctl_exporter -config ${configFile} + ${pkgs.prometheus-smartctl-exporter}/bin/smartctl_exporter ${args} ''; PrivateDevices = lib.mkForce false; ProtectProc = "invisible"; diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index cdf666378fa3..8b40d7e41c00 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -1086,13 +1086,8 @@ let ]; }; exporterTest = '' - wait_for_unit("prometheus-smartctl-exporter.service") - wait_for_open_port(9633) wait_until_succeeds( - "curl -sSf 'localhost:9633/metrics'" - ) - wait_until_succeeds( - 'journalctl -eu prometheus-smartctl-exporter.service -o cat | grep "/dev/vda: Unable to detect device type"' + 'journalctl -eu prometheus-smartctl-exporter.service -o cat | grep "Device unavailable"' ) ''; }; diff --git a/pkgs/servers/monitoring/prometheus/smartctl-exporter/default.nix b/pkgs/servers/monitoring/prometheus/smartctl-exporter/default.nix index 21ccb8178c34..df21ef09f9f1 100644 --- a/pkgs/servers/monitoring/prometheus/smartctl-exporter/default.nix +++ b/pkgs/servers/monitoring/prometheus/smartctl-exporter/default.nix @@ -1,42 +1,33 @@ { lib , fetchFromGitHub -, fetchpatch , buildGoModule +, nixosTests }: buildGoModule rec { pname = "smartctl_exporter"; - version = "unstable-2020-11-14"; + version = "0.9.1"; src = fetchFromGitHub { owner = "prometheus-community"; repo = pname; - rev = "e27581d56ad80340fb076d3ce22cef337ed76679"; - sha256 = "sha256-iWaFDjVLBIAA9zGe0utbuvmEdA3R5lge0iCh3j2JfE8="; + rev = "refs/tags/v${version}"; + hash = "sha256-fc1NZ5QwzR/jJkeaDm5PMT4wBFFlqZOXKTJMBJWKJJ8="; }; - patches = [ - # Fixes out of range panic (https://github.com/prometheus-community/smartctl_exporter/issues/19) - (fetchpatch { - url = "https://github.com/prometheus-community/smartctl_exporter/commit/15575301a8e2fe5802a8c066c6fa9765d50b8cfa.patch"; - sha256 = "sha256-HLUrGXNz3uKpuQBUgQBSw6EGbGl23hQnimTGl64M5bQ="; - }) - # Fix validation on empty smartctl response (https://github.com/prometheus-community/smartctl_exporter/pull/31) - (fetchpatch { - url = "https://github.com/prometheus-community/smartctl_exporter/commit/744b4e5f6a46e029d31d5aa46642e85f429c2cfa.patch"; - sha256 = "sha256-MgLtYR1SpM6XrZQQ3AgQRmNF3OnaBCqXMJRV9BOzKPc="; - }) - # Fixes missing metrics if outside of query interval (https://github.com/prometheus-community/smartctl_exporter/pull/18) - ./0001-Return-the-cached-value-if-it-s-not-time-to-scan-aga.patch + vendorSha256 = "sha256-lQKuT5dzjDHFpRSmcXpKD1RJDlEv+0kcxENkv3mT4FU="; + + ldflags = [ + "-X github.com/prometheus/common/version.Version=${version}" ]; - vendorSha256 = "1xhrzkfm2p20k7prgdfax4408g4qpa4wbxigmcmfz7kjg2zi88ld"; + passthru.tests = { inherit (nixosTests.prometheus-exporters) smartctl; }; meta = with lib; { description = "Export smartctl statistics for Prometheus"; homepage = "https://github.com/prometheus-community/smartctl_exporter"; license = licenses.lgpl3; platforms = platforms.linux; - maintainers = with maintainers; [ hexa ]; + maintainers = with maintainers; [ hexa Frostman ]; }; }