From e56dd86161ddc76292130b0ae1f030c0b7c1261e Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Mon, 26 Dec 2022 18:22:56 +0200 Subject: [PATCH] Add email, update README and include job in labels --- README.md | 42 +++++++++++++++++++++++++++--- pyproject.toml | 8 +++--- restic_exporter/restic_exporter.py | 2 +- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 729e3a4..81db5bd 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,53 @@ # restic_exporter +Convert the JSON output of a restic backup job to metrics that Prometheus Node Exporter would understand. +The metrics will be shown in the standard output, so then you have to direct them to a file in the +Prometheus Node Exporter folder specify with the [textfile-collector](https://github.com/prometheus/node_exporter#textfile-collector). + ## Requirements ## Installation ### Linux - `sudo python3 setup.py install` + ```bash +sudo python3 setup.py install +``` ### Windows (from PowerShell) - `& $(where.exe python).split()[0] setup.py install` + ```powershell +& $(where.exe python).split()[0] setup.py install +``` ## Usage - `restic_exporter.py [--debug-level|-d CRITICAL|ERROR|WARNING|INFO|DEBUG|NOTSET] # Other parameters` + ``` +restic_exporter.py [OPTIONS] + +Options: + -d, --debug-level [CRITICAL|ERROR|WARNING|INFO|DEBUG|NOTSET] + Set the debug level for the standard output. + -l, --log-file TEXT File to store all debug messages. + -j, --json-file TEXT JSON file containing the output of restic + [required] + -n, --job-name TEXT Restic job name to attach to the exported + metrics [required] + -a, --extra-labels TEXT Pairs key=value separated by commas with + extra labels to add to the summary + -m, --metric-name TEXT Metric name. Spaces will be replaced with + underscore (_). + -d, --metric-description TEXT Metric description. + --config FILE Read configuration from FILE. + --help Show this message and exit. +``` + +For example, you run: +```bash +restic backup --repo /var/restic_backups --json /home > /tmp/my_restic_result.json +``` +Then assume your Prometheus Node Exporter is running with --collector.textfile.directory=/var/lib/node_exporter (this is set in /etc/default/prometheus-node-exporter in Ubuntu for example. +In this case of using the folder /var/lib/node_exporter, then you would run restic_exporter.py with this parameters: +```bash +restic_exporter.py --json-file /tmp/my_restic_result.json --job-name 'home_folders' > /var/lib/node_exporter/restic_home_folders.prom +``` diff --git a/pyproject.toml b/pyproject.toml index f945b96..a37e2e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,14 +3,14 @@ requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" [project.urls] -Homepage = "" +Homepage = "https://susurrando.com" [project] name = "restic_exporter" -version = "0.0.1" +version = "0.0.2" description = "Export to node exporter the summary of a restic backup" readme = "README.md" -authors = [{ name = "Antonio J. Delgado", email = "" }] +authors = [{ name = "Antonio J. Delgado", email = "ad@susurrando.com" }] license = { file = "LICENSE" } classifiers = [ "License :: OSI Approved :: GPLv3 License", @@ -22,4 +22,4 @@ dependencies = [ "click", "click_config_file", ] -requires-python = ">=3" \ No newline at end of file +requires-python = ">=3" diff --git a/restic_exporter/restic_exporter.py b/restic_exporter/restic_exporter.py index 985a4aa..e5aa1f8 100644 --- a/restic_exporter/restic_exporter.py +++ b/restic_exporter/restic_exporter.py @@ -26,7 +26,7 @@ class restic_exporter: self.metric_name = metric_name.replace(' ', '_') self.metric_description = metric_description - self.labels= {} + self.labels= {"job_name": job_name} if extra_labels: self.labels = {