diff options
| author | Dennis Fink | 2026-09-27 12:52:04 +0200 |
|---|---|---|
| committer | Dennis Fink | 2026-09-27 12:52:04 +0200 |
| commit | dab9faa18b9d4cb06a88acf8842ce525434dd890 (patch) | |
| tree | 8f11e86db1153396fe31b1a1183c71dd1fb12dbe /prometheus_pacman_exporter | |
| parent | cb9dc38c1235065346dd9aa6783de8d7d72a8317 (diff) | |
| download | prometheus-pacman-exporter-dab9faa18b9d4cb06a88acf8842ce525434dd890.tar.gz prometheus-pacman-exporter-dab9faa18b9d4cb06a88acf8842ce525434dd890.zip | |
feat(cli): report collected package counts
Add human-readable descriptions to package queries and emit each
collected count when verbose output is enabled.
Rename the pacman query command variable to clarify that it is reused as
the base command for multiple package queries.
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) |
