diff options
Diffstat (limited to 'prometheus_pacman_exporter')
| -rw-r--r-- | prometheus_pacman_exporter/__init__.py | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/prometheus_pacman_exporter/__init__.py b/prometheus_pacman_exporter/__init__.py index baf69dd..23ce5a2 100644 --- a/prometheus_pacman_exporter/__init__.py +++ b/prometheus_pacman_exporter/__init__.py @@ -15,7 +15,7 @@ from cloup.constraints import If, require_all from prometheus_client import write_to_textfile from . import metrics -from .cli import FlexibleColorOption, debug, error, msg +from .cli import FlexibleColorOption, debug, error, msg, verbose VERSION = "1.0.0" DESCRIPTION = "Collect pacman package metrics and export them for Prometheus." @@ -191,29 +191,62 @@ def prometheus_pacman_exporter( debug(" verbose:", str(verbose_flag), err=True) debug(" quiet:", str(quiet_flag), err=True) - pacman = ["pacman", "--query"] + pacman_base_command = ["pacman", "--query"] queries = [ - ([*pacman], metrics.INSTALLED_PACKAGES), - ([*pacman, "--explicit"], metrics.EXPLICIT_PACKAGES), - ([*pacman, "--deps"], metrics.DEPENDS_PACKAGES), - ([*pacman, "--unrequired"], metrics.UNREQUIRED_PACKAGES), - ([*pacman, "--foreign"], metrics.FOREIGN_PACKAGES), - ([*pacman, "--native"], metrics.NATIVE_PACKAGES), - ([*pacman, "--deps", "--unrequired"], metrics.ORPHAN_PACKAGES), + ([*pacman_base_command], "installed packages", metrics.INSTALLED_PACKAGES), ( - ["checkupdates"] if use_checkupdates_flag else [*pacman, "--upgrades"], + [*pacman_base_command, "--explicit"], + "explicitly installed packages", + metrics.EXPLICIT_PACKAGES, + ), + ( + [*pacman_base_command, "--deps"], + "packages installed as dependencies", + metrics.DEPENDS_PACKAGES, + ), + ( + [*pacman_base_command, "--unrequired"], + "unrequired packages", + metrics.UNREQUIRED_PACKAGES, + ), + ( + [*pacman_base_command, "--foreign"], + "foreign packages", + metrics.FOREIGN_PACKAGES, + ), + ( + [*pacman_base_command, "--native"], + "native packages", + metrics.NATIVE_PACKAGES, + ), + ( + [*pacman_base_command, "--deps", "--unrequired"], + "orphan packages", + metrics.ORPHAN_PACKAGES, + ), + ( + ["checkupdates"] + if use_checkupdates_flag + else [*pacman_base_command, "--upgrades"], + "updateable packages", metrics.UPDATEABLE_PACKAGES, ), ] if aur_flag: queries.append( - (shlex.split(cast(str, aur_command)), metrics.AUR_UPDATEABLE_PACKAGES) + ( + shlex.split(cast(str, aur_command)), + "AUR updateable packages", + metrics.AUR_UPDATEABLE_PACKAGES, + ) ) - for command, metric in queries: + for command, description, metric in queries: output = run_command(command) - metric.set(len(output.stdout.splitlines())) + value = len(output.stdout.splitlines()) + verbose(f"Setting {description}:", str(value), err=True) + metric.set(value) metrics_file = textfile_collector_dir / "pacman.prom" write_to_textfile(str(metrics_file.absolute()), metrics.REGISTRY) |
