Merge pull request #205123 from Frostman/prometheus-smartctl-exporter-0.9.1

This commit is contained in:
Martin Weinelt 2022-12-09 01:58:06 +01:00 committed by GitHub
commit a4f2ca1ef3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 45 deletions

View File

@ -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";

View File

@ -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"'
)
'';
};

View File

@ -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 ];
};
}