aboutsummaryrefslogtreecommitdiff
path: root/prometheus_borgmatic_exporter/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'prometheus_borgmatic_exporter/__init__.py')
-rw-r--r--prometheus_borgmatic_exporter/__init__.py39
1 files changed, 22 insertions, 17 deletions
diff --git a/prometheus_borgmatic_exporter/__init__.py b/prometheus_borgmatic_exporter/__init__.py
index ac2721e..fea8dbd 100644
--- a/prometheus_borgmatic_exporter/__init__.py
+++ b/prometheus_borgmatic_exporter/__init__.py
@@ -284,12 +284,9 @@ def extract_archive_counts(
def fetch_repositories(
- borgmatic_bin: Path,
- borgmatic_config: Path,
- all_archives: bool,
+ borgmatic_bin: Path, borgmatic_configs: tuple[Path, ...], all_archives: bool
) -> tuple[list[types.BorgInfoReturnType], list[types.ArchiveCount]]:
- """
- Fetch repository and archive data from borgmatic.
+ """Fetch repository and archive data from borgmatic.
When all_archives is False, runs `borgmatic info --archive latest` and
`borgmatic list` in complementary intent: info provides per-repository
@@ -314,7 +311,11 @@ def fetch_repositories(
always populated regardless of the all_archives flag.
"""
verbose("Fetching repositories")
- borgmatic_cmd = [str(borgmatic_bin), "--config", str(borgmatic_config)]
+ borgmatic_cmd = [str(borgmatic_bin)]
+
+ for config in borgmatic_configs:
+ borgmatic_cmd.extend(["--config", str(config)])
+
info_command = [*borgmatic_cmd, "info", "--json"]
if all_archives:
@@ -473,14 +474,16 @@ def collect_archive_metrics(
)
@click.option(
"--borgmatic-config",
+ "borgmatic_configs",
+ multiple=True,
type=click.Path(
- exists=True,
- readable=True,
- dir_okay=False,
- allow_dash=False,
- path_type=Path,
+ exists=True, readable=True, dir_okay=True, allow_dash=False, path_type=Path
+ ),
+ help=(
+ "Configuration file or directory. "
+ "Can be specified multiple times. "
+ "If not specified, borgmatic's default configuration discovery is used."
),
- default="/etc/borgmatic/config.yaml",
)
@click.option(
"--textfile-collector-dir",
@@ -510,7 +513,7 @@ def collect_archive_metrics(
def prometheus_borgmatic_exporter(
ctx: click.Context,
borgmatic_bin: Path,
- borgmatic_config: Path,
+ borgmatic_configs: tuple[Path, ...],
textfile_collector_dir: Path,
all_archives_flag: bool,
quiet_flag: bool,
@@ -537,16 +540,18 @@ def prometheus_borgmatic_exporter(
debug("Effective configuration:")
debug(" borgmatic_bin:", str(borgmatic_bin))
- debug(" borgmatic_config:", str(borgmatic_config))
+ debug(
+ " borgmatic_configs:",
+ ", ".join(str(config) for config in borgmatic_configs)
+ or "<borgmatic defaults>",
+ )
debug(" textfile_collector_dir:", str(textfile_collector_dir))
debug(" all_archives:", str(all_archives_flag))
debug(" verbose:", str(verbose_flag))
debug(" quiet:", str(quiet_flag))
repositories, archive_counts = fetch_repositories(
- borgmatic_bin,
- borgmatic_config,
- all_archives_flag,
+ borgmatic_bin, borgmatic_configs, all_archives_flag
)
for repository in archive_counts: