From 69f015e4f4b21d7fe249ea33243586e3ff2f800c Mon Sep 17 00:00:00 2001 From: Finn Landweber Date: Wed, 21 Feb 2024 10:52:00 +0100 Subject: [PATCH 1/2] prometheus-borgmatic-exporter: init at 0.2.5 --- .../prometheus-borgmatic-exporter/package.nix | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 pkgs/by-name/pr/prometheus-borgmatic-exporter/package.nix diff --git a/pkgs/by-name/pr/prometheus-borgmatic-exporter/package.nix b/pkgs/by-name/pr/prometheus-borgmatic-exporter/package.nix new file mode 100644 index 000000000000..ad02307ffa0e --- /dev/null +++ b/pkgs/by-name/pr/prometheus-borgmatic-exporter/package.nix @@ -0,0 +1,47 @@ +{ + lib, + fetchFromGitHub, + python3Packages, + borgmatic, +}: +python3Packages.buildPythonApplication rec { + pname = "prometheus-borgmatic-exporter"; + version = "0.2.5"; + pyproject = true; + + src = fetchFromGitHub { + owner = "maxim-mityutko"; + repo = "borgmatic-exporter"; + rev = "v${version}"; + hash = "sha256-SgP1utu4Eqs9214pYOT9wP0Ms7AUQH1A3czQF8+qBRo="; + }; + + nativeCheckInputs = with python3Packages; [ + pytestCheckHook + pytest-mock + ]; + + buildInputs = [python3Packages.poetry-core]; + + propagatedBuildInputs = + [ borgmatic ] + ++ (with python3Packages; [ + flask + arrow + click + loguru + pretty-errors + prometheus-client + timy + waitress + ]); + + meta = with lib; { + description = "Prometheus exporter for Borgmatic"; + homepage = "https://github.com/maxim-mityutko/borgmatic-exporter"; + license = licenses.mit; + maintainers = with maintainers; [ flandweber ]; + mainProgram = "borgmatic-exporter"; + platforms = platforms.unix; + }; +} From 0d58b75cba5cb091ae35916192deb33b1c2ad49d Mon Sep 17 00:00:00 2001 From: Finn Landweber Date: Fri, 23 Feb 2024 15:48:13 +0100 Subject: [PATCH 2/2] added prometheus-borgmatic-exporter module --- .../monitoring/prometheus/exporters.nix | 1 + .../prometheus/exporters/borgmatic.nix | 34 +++++++++++++++++++ nixos/tests/prometheus-exporters.nix | 20 +++++++++++ 3 files changed, 55 insertions(+) create mode 100644 nixos/modules/services/monitoring/prometheus/exporters/borgmatic.nix diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 0a9d4ef98522..723116d2547b 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -27,6 +27,7 @@ let "bird" "bitcoin" "blackbox" + "borgmatic" "buildkite-agent" "collectd" "deluge" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/borgmatic.nix b/nixos/modules/services/monitoring/prometheus/exporters/borgmatic.nix new file mode 100644 index 000000000000..573230c3afca --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/borgmatic.nix @@ -0,0 +1,34 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.services.prometheus.exporters.borgmatic; +in +{ + port = 9996; + extraOpts.configFile = lib.mkOption { + type = lib.types.path; + default = "/etc/borgmatic/config.yaml"; + description = '' + The path to the borgmatic config file + ''; + }; + + serviceOpts = { + serviceConfig = { + DynamicUser = false; + ProtectSystem = false; + ProtectHome = lib.mkForce false; + ExecStart = '' + ${pkgs.prometheus-borgmatic-exporter}/bin/borgmatic-exporter run \ + --port ${toString cfg.port} \ + --config ${toString cfg.configFile} \ + ${lib.concatMapStringsSep " " (f: lib.escapeShellArg f) cfg.extraFlags} + ''; + }; + }; +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index 37f25546da69..fba6bd57d9c4 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -177,6 +177,26 @@ let ''; }; + borgmatic = { + exporterConfig = { + enable = true; + user = "root"; + }; + metricProvider = { + services.borgmatic.enable = true; + services.borgmatic.settings.source_directories = [ "/home" ]; + services.borgmatic.settings.repositories = [ { label = "local"; path = "/var/backup"; } ]; + services.borgmatic.settings.keep_daily = 10; + }; + exporterTest = '' + succeed("borgmatic rcreate -e none") + succeed("borgmatic") + wait_for_unit("prometheus-borgmatic-exporter.service") + wait_for_open_port(9996) + succeed("curl -sSf localhost:9996/metrics | grep 'borg_total_backups{repository=\"/var/backup\"} 1'") + ''; + }; + collectd = { exporterConfig = { enable = true;