Skip to content

Commit 1e66e23

Browse files
author
Gabriel Filion
committed
Expose number of obsolete packages
Packages are obsolete if they either: * don't have a candidate version * their candidate version does not have an origin. * their candidate version has a single origin that points to local storage Signed-off-by: Gabriel Filion <[email protected]>
1 parent ef6b6cd commit 1e66e23

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: apt_info.py

+15
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ def _write_held_upgrades(registry, cache):
8080
g.labels(change.labels['origin'], change.labels['arch']).set(change.count)
8181

8282

83+
def _write_obsolete_packages(registry, cache):
84+
# This corresponds to the apt filter "?obsolete"
85+
obsoletes = [p for p in cache if p.is_installed and (
86+
p.candidate is None or
87+
not p.candidate.origins or
88+
(len(p.candidate.origins) == 1 and
89+
p.candidate.origins[0].origin in ['', "/var/lib/dpkg/status"])
90+
)]
91+
92+
g = Gauge('apt_obsolete_packages', "Apt packages which are obsolete",
93+
registry=registry)
94+
g.set(len(obsoletes))
95+
96+
8397
def _write_autoremove_pending(registry, cache):
8498
autoremovable_packages = {p for p in cache if p.is_auto_removable}
8599
g = Gauge('apt_autoremove_pending', "Apt packages pending autoremoval.",
@@ -118,6 +132,7 @@ def _main():
118132
registry = CollectorRegistry()
119133
_write_pending_upgrades(registry, cache)
120134
_write_held_upgrades(registry, cache)
135+
_write_obsolete_packages(registry, cache)
121136
_write_autoremove_pending(registry, cache)
122137
_write_cache_timestamps(registry)
123138
_write_reboot_required(registry)

0 commit comments

Comments
 (0)