Skip to content

Commit

Permalink
Improve heuristic for the apt update last run time (prometheus-commun…
Browse files Browse the repository at this point in the history
…ity#208)

As suggested by prometheus-community#194 and this fixes it

Signed-off-by: kennethso168 <kennethso168@gmail.com>
  • Loading branch information
kennethso168 authored and Alex Kraker committed May 11, 2024
1 parent ff69095 commit e804e31
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions apt_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ def _write_autoremove_pending(registry, cache):
def _write_cache_timestamps(registry):
g = Gauge('apt_package_cache_timestamp_seconds', "Apt update last run time.", registry=registry)
apt_pkg.init_config()
if apt_pkg.config.find_b("APT::Periodic::Update-Package-Lists"):
if (
apt_pkg.config.find_b("APT::Periodic::Update-Package-Lists") and
os.path.isfile("/var/lib/apt/periodic/update-success-stamp")
):
# if we run updates automatically with APT::Periodic, we can
# check this timestamp file
# check this timestamp file if it exists
stamp_file = "/var/lib/apt/periodic/update-success-stamp"
else:
# if not, let's just fallback on the lists directory
stamp_file = '/var/lib/apt/lists'
# if not, let's just fallback on the partial file of the lists directory
stamp_file = '/var/lib/apt/lists/partial'
try:
g.set(os.stat(stamp_file).st_mtime)
except OSError:
Expand Down

0 comments on commit e804e31

Please sign in to comment.