use low level apt_pkg cache to get list of upgradable packages (#68476)
This commit is contained in:
parent
5ed3fa00cf
commit
896fa4abcb
|
@ -9,7 +9,7 @@ import shlex
|
|||
import subprocess
|
||||
import time
|
||||
|
||||
import apt
|
||||
import apt_pkg
|
||||
import dbus
|
||||
import psutil
|
||||
import requests
|
||||
|
@ -34,7 +34,6 @@ JOURNALD_IGNORED_ERRORS = {
|
|||
}
|
||||
|
||||
|
||||
apt_cache = apt.Cache()
|
||||
registry = CollectorRegistry()
|
||||
eo_errors = Gauge("eo_errors", "failed tests", ["ctn"], registry=registry)
|
||||
eo_certificates = Gauge("eo_certificates", "certificates", ["ctn", "name"], registry=registry)
|
||||
|
@ -157,9 +156,14 @@ def nginx(ctn):
|
|||
|
||||
|
||||
def packages(ctn):
|
||||
apt_pkg.init()
|
||||
cache = apt_pkg.Cache(None)
|
||||
depcache = apt_pkg.DepCache(cache)
|
||||
depcache.read_pinfile()
|
||||
depcache.init()
|
||||
n = 0
|
||||
for pkg in apt_cache.get_changes():
|
||||
if pkg.isUpgradable:
|
||||
for pkg in cache.packages:
|
||||
if pkg.current_ver is not None and not depcache.marked_install(pkg) and depcache.is_upgradable(pkg):
|
||||
n += 1
|
||||
eo_packages.labels(ctn, "upgradable").set(n)
|
||||
|
||||
|
|
Loading…
Reference in New Issue