aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2025-12-14 22:44:31 +0100
committerMartin Fischer <martin@push-f.com>2025-12-14 23:12:56 +0100
commitef15d5aad7360ee6811cc3fa09ca8106a7f09fb6 (patch)
tree999f19b39ae4b0390bda4bd20f05e45b028b2e8f
parentde4843c5002f3f58f8bc69dd57d368324b67f4ce (diff)
feat: add prometheus-storagebox-exporter
-rw-r--r--nixos/hosts/tente/default.nix1
-rw-r--r--nixos/hosts/tente/exporters.nix19
-rw-r--r--nixos/hosts/tente/ports.nix1
-rw-r--r--nixos/hosts/tente/secrets/hetzner-token.agebin0 -> 387 bytes
-rw-r--r--nixos/npins/sources.json15
-rw-r--r--nixos/shared/prometheus-storagebox-exporter/default.nix24
-rw-r--r--nixos/shared/prometheus-storagebox-exporter/service.nix33
7 files changed, 92 insertions, 1 deletions
diff --git a/nixos/hosts/tente/default.nix b/nixos/hosts/tente/default.nix
index f0aa773..76bda08 100644
--- a/nixos/hosts/tente/default.nix
+++ b/nixos/hosts/tente/default.nix
@@ -128,6 +128,7 @@ in
monitoring.prometheusPort = ports.prometheus;
monitoring.prometheusNodeExporterPort = ports.prometheusNodeExporter;
exporters.sqlExporterPort = ports.prometheusSqlExporter;
+ exporters.storageboxExporterPort = ports.prometheusStorageboxExporter;
headscale.port = ports.headscale;
matrix.port = ports.matrix;
diff --git a/nixos/hosts/tente/exporters.nix b/nixos/hosts/tente/exporters.nix
index a2e799e..eb46015 100644
--- a/nixos/hosts/tente/exporters.nix
+++ b/nixos/hosts/tente/exporters.nix
@@ -9,10 +9,14 @@ in
sqlExporterPort = lib.mkOption {
type = lib.types.int;
};
+ storageboxExporterPort = lib.mkOption {
+ type = lib.types.int;
+ };
};
imports = [
<top/shared/prometheus-sql-exporter/service.nix>
+ <top/shared/prometheus-storagebox-exporter/service.nix>
];
config = {
@@ -30,6 +34,14 @@ in
};
};
+ age.secrets.hetzner-token.file = ./secrets/hetzner-token.age;
+
+ services.prometheus-storagebox-exporter = {
+ enable = true;
+ port = cfg.storageboxExporterPort;
+ hetznerTokenFile = config.age.secrets.hetzner-token.path;
+ };
+
monitoring.prometheusScrapeConfigs = [
{
job_name = "sql";
@@ -37,7 +49,12 @@ in
targets = [ "localhost:${toString cfg.sqlExporterPort}" ];
}];
}
- # TODO: add exporter for storagebox
+ {
+ job_name = "storagebox";
+ static_configs = [{
+ targets = [ "localhost:${toString cfg.storageboxExporterPort}" ];
+ }];
+ }
];
};
}
diff --git a/nixos/hosts/tente/ports.nix b/nixos/hosts/tente/ports.nix
index 133d0f7..69e0dbd 100644
--- a/nixos/hosts/tente/ports.nix
+++ b/nixos/hosts/tente/ports.nix
@@ -8,6 +8,7 @@ rec {
prometheus = 9090;
prometheusNodeExporter = 9002;
prometheusSqlExporter = 9003;
+ prometheusStorageboxExporter = 9004;
webUis = {
inherit
diff --git a/nixos/hosts/tente/secrets/hetzner-token.age b/nixos/hosts/tente/secrets/hetzner-token.age
new file mode 100644
index 0000000..48c64b2
--- /dev/null
+++ b/nixos/hosts/tente/secrets/hetzner-token.age
Binary files differ
diff --git a/nixos/npins/sources.json b/nixos/npins/sources.json
index b765191..d62673a 100644
--- a/nixos/npins/sources.json
+++ b/nixos/npins/sources.json
@@ -143,6 +143,21 @@
"revision": "6e73ff71a8976939c28ce9a0ddbeefe0801d0a37",
"url": null,
"hash": "1a3j3rsjvw6wqyayml5x5c7x18bvn45ldr2p280yn9pqdzihk480"
+ },
+ "prometheus-storagebox-exporter": {
+ "type": "GitRelease",
+ "repository": {
+ "type": "Git",
+ "url": "https://github.com/crstian19/prometheus-storagebox-exporter"
+ },
+ "pre_releases": false,
+ "version_upper_bound": null,
+ "release_prefix": null,
+ "submodules": false,
+ "version": "v0.3.0",
+ "revision": "0382d2fc9c26d69dab7be1e0b6bdb3e38e5e13c6",
+ "url": null,
+ "hash": "0qa0k7rkf92x14b707h1qrivj4xj0jd2zmrrp5bwarm4iipyid76"
}
},
"version": 5
diff --git a/nixos/shared/prometheus-storagebox-exporter/default.nix b/nixos/shared/prometheus-storagebox-exporter/default.nix
new file mode 100644
index 0000000..281290f
--- /dev/null
+++ b/nixos/shared/prometheus-storagebox-exporter/default.nix
@@ -0,0 +1,24 @@
+{
+ lib,
+ buildGoModule,
+}:
+let
+ sources = import <top/npins>;
+in
+buildGoModule {
+ pname = "storagebox_exporter";
+ version = sources.prometheus-storagebox-exporter.version;
+ src = sources.prometheus-storagebox-exporter;
+ vendorHash = "sha256-3aBklYmPHELcLG+3sOEDd9qkrJyDrC52LfhOOY/6sOc=";
+
+ meta = with lib; {
+ description = "Modern Prometheus exporter for Hetzner Storage Box with comprehensive metrics";
+ mainProgram = "prometheus-storagebox-exporter";
+ homepage = "https://github.com/crstian19/prometheus-storagebox-exporter";
+ license = licenses.mit;
+ };
+
+ postPatch = ''
+ substituteInPlace go.mod --replace 'go 1.25.5' 'go 1.25.4'
+ '';
+}
diff --git a/nixos/shared/prometheus-storagebox-exporter/service.nix b/nixos/shared/prometheus-storagebox-exporter/service.nix
new file mode 100644
index 0000000..74f0dd1
--- /dev/null
+++ b/nixos/shared/prometheus-storagebox-exporter/service.nix
@@ -0,0 +1,33 @@
+# TODO: submit Christian's storagebox exporter to nixpkgs
+{ config, lib, pkgs, ... }:
+
+let
+ storageboxExporter = pkgs.callPackage ./default.nix {};
+ cfg = config.services.prometheus-storagebox-exporter;
+in
+{
+ options.services.prometheus-storagebox-exporter = {
+ enable = lib.mkEnableOption "storagebox-exporter";
+ port = lib.mkOption {
+ type = lib.types.int;
+ };
+ hetznerTokenFile = lib.mkOption {
+ type = lib.types.path;
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ systemd.services.storagebox-exporter = {
+ serviceConfig = {
+ ExecStart = "${storageboxExporter}/bin/prometheus-storagebox-exporter";
+ DynamicUser = "true";
+ LoadCredential = "hetznerToken:${cfg.hetznerTokenFile}";
+ };
+ environment = {
+ HETZNER_TOKEN_FILE = "%d/hetznerToken";
+ LISTEN_ADDRESS = ":${toString cfg.port}";
+ };
+ wantedBy = ["multi-user.target"];
+ };
+ };
+}