summary refs log tree commit diff
path: root/pkgs/servers/monitoring/prometheus
diff options
context:
space:
mode:
authorMartin Weinelt <mweinelt@users.noreply.github.com>2021-12-05 03:00:48 +0100
committerGitHub <noreply@github.com>2021-12-05 03:00:48 +0100
commit0c008f9c0d081036e7237983c1cd91a539fd2ead (patch)
tree7181006cd9e7b94d441ca5b45836b7a59088196e /pkgs/servers/monitoring/prometheus
parent894fb34b239d37acbd670f0322a6739a8d668916 (diff)
parent02316a4565428d6c392dfa5f3ff3e87771783184 (diff)
downloadnixpkgs-0c008f9c0d081036e7237983c1cd91a539fd2ead.tar
nixpkgs-0c008f9c0d081036e7237983c1cd91a539fd2ead.tar.gz
nixpkgs-0c008f9c0d081036e7237983c1cd91a539fd2ead.tar.bz2
nixpkgs-0c008f9c0d081036e7237983c1cd91a539fd2ead.tar.lz
nixpkgs-0c008f9c0d081036e7237983c1cd91a539fd2ead.tar.xz
nixpkgs-0c008f9c0d081036e7237983c1cd91a539fd2ead.tar.zst
nixpkgs-0c008f9c0d081036e7237983c1cd91a539fd2ead.zip
Merge pull request #147056 from mweinelt/smartctl-exporter
Diffstat (limited to 'pkgs/servers/monitoring/prometheus')
-rw-r--r--pkgs/servers/monitoring/prometheus/smartctl-exporter/0001-Return-the-cached-value-if-it-s-not-time-to-scan-aga.patch51
-rw-r--r--pkgs/servers/monitoring/prometheus/smartctl-exporter/default.nix41
2 files changed, 92 insertions, 0 deletions
diff --git a/pkgs/servers/monitoring/prometheus/smartctl-exporter/0001-Return-the-cached-value-if-it-s-not-time-to-scan-aga.patch b/pkgs/servers/monitoring/prometheus/smartctl-exporter/0001-Return-the-cached-value-if-it-s-not-time-to-scan-aga.patch
new file mode 100644
index 00000000000..28616251f37
--- /dev/null
+++ b/pkgs/servers/monitoring/prometheus/smartctl-exporter/0001-Return-the-cached-value-if-it-s-not-time-to-scan-aga.patch
@@ -0,0 +1,51 @@
+From e81b06df67b1d42ef915615fafa0b56ef956673b Mon Sep 17 00:00:00 2001
+From: Andreas Fuchs <asf@boinkor.net>
+Date: Thu, 11 Feb 2021 17:30:44 -0500
+Subject: [PATCH] Return the cached value if it's not time to scan again yet
+
+This should ensure that if we have a valid value cached (which ought
+to be every time after the first scan), we return it as metrics.
+
+This fixes the crashes that would happen if queries happened earlier
+than the re-scan interval allowed.
+
+Address review feedback: Shorten the time-to-scan logic
+
+We can express this in a single if statement, so it takes fewer lines
+to do the "should we check again" check.
+---
+ readjson.go | 11 ++---------
+ 1 file changed, 2 insertions(+), 9 deletions(-)
+
+diff --git a/readjson.go b/readjson.go
+index da35448..c9996fd 100644
+--- a/readjson.go
++++ b/readjson.go
+@@ -78,14 +78,7 @@ func readData(device string) (gjson.Result, error) {
+ 
+ 	if _, err := os.Stat(device); err == nil {
+ 		cacheValue, cacheOk := jsonCache[device]
+-		timeToScan := false
+-		if cacheOk {
+-			timeToScan = time.Now().After(cacheValue.LastCollect.Add(options.SMARTctl.CollectPeriodDuration))
+-		} else {
+-			timeToScan = true
+-		}
+-
+-		if timeToScan {
++		if !cacheOk || time.Now().After(cacheValue.LastCollect.Add(options.SMARTctl.CollectPeriodDuration)) {
+ 			json, ok := readSMARTctl(device)
+ 			if ok {
+ 				jsonCache[device] = JSONCache{JSON: json, LastCollect: time.Now()}
+@@ -93,7 +86,7 @@ func readData(device string) (gjson.Result, error) {
+ 			}
+ 			return gjson.Parse(DEFAULT_EMPTY_JSON), fmt.Errorf("smartctl returned bad data for device %s", device)
+ 		}
+-		return gjson.Parse(DEFAULT_EMPTY_JSON), fmt.Errorf("Too early collect called for device %s", device)
++		return cacheValue.JSON, nil
+ 	}
+ 	return gjson.Parse(DEFAULT_EMPTY_JSON), fmt.Errorf("Device %s unavialable", device)
+ }
+-- 
+2.33.1
+
diff --git a/pkgs/servers/monitoring/prometheus/smartctl-exporter/default.nix b/pkgs/servers/monitoring/prometheus/smartctl-exporter/default.nix
new file mode 100644
index 00000000000..45315a0f3d7
--- /dev/null
+++ b/pkgs/servers/monitoring/prometheus/smartctl-exporter/default.nix
@@ -0,0 +1,41 @@
+{ lib
+, fetchFromGitHub
+, fetchpatch
+, buildGoModule
+}:
+
+buildGoModule rec {
+  pname = "smartctl_exporter";
+  version = "unstable-2020-11-14";
+
+  src = fetchFromGitHub {
+    owner = "prometheus-community";
+    repo = pname;
+    rev = "e27581d56ad80340fb076d3ce22cef337ed76679";
+    sha256 = "sha256-iWaFDjVLBIAA9zGe0utbuvmEdA3R5lge0iCh3j2JfE8=";
+  };
+
+  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 = "1xhrzkfm2p20k7prgdfax4408g4qpa4wbxigmcmfz7kjg2zi88ld";
+
+  meta = with lib; {
+    description = "Export smartctl statistics for Prometheus";
+    homepage = "https://github.com/prometheus-community/smartctl_exporter";
+    license = licenses.lgpl3;
+    maintainers = with maintainers; [ hexa ];
+  };
+}