[Backport release-24.05] borgmatic-exporter: init at 0.2.5 (#329180)

This commit is contained in:
Sefa Eyeoglu 2024-11-10 12:48:13 +01:00 committed by GitHub
commit 9256f7c71a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 102 additions and 0 deletions

View File

@ -27,6 +27,7 @@ let
"bird"
"bitcoin"
"blackbox"
"borgmatic"
"buildkite-agent"
"collectd"
"dmarc"

View File

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

View File

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

View File

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