Skip to content

Commit 4f598da

Browse files
kennethso168allamiro
authored andcommitted
Improve heuristic for the apt update last run time (prometheus-community#208)
As suggested by prometheus-community#194 and this fixes it Signed-off-by: kennethso168 <[email protected]>
1 parent 38f6c78 commit 4f598da

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Diff for: apt_info.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,16 @@ def _write_autoremove_pending(registry, cache):
9090
def _write_cache_timestamps(registry):
9191
g = Gauge('apt_package_cache_timestamp_seconds', "Apt update last run time.", registry=registry)
9292
apt_pkg.init_config()
93-
if apt_pkg.config.find_b("APT::Periodic::Update-Package-Lists"):
93+
if (
94+
apt_pkg.config.find_b("APT::Periodic::Update-Package-Lists") and
95+
os.path.isfile("/var/lib/apt/periodic/update-success-stamp")
96+
):
9497
# if we run updates automatically with APT::Periodic, we can
95-
# check this timestamp file
98+
# check this timestamp file if it exists
9699
stamp_file = "/var/lib/apt/periodic/update-success-stamp"
97100
else:
98-
# if not, let's just fallback on the lists directory
99-
stamp_file = '/var/lib/apt/lists'
101+
# if not, let's just fallback on the partial file of the lists directory
102+
stamp_file = '/var/lib/apt/lists/partial'
100103
try:
101104
g.set(os.stat(stamp_file).st_mtime)
102105
except OSError:

0 commit comments

Comments
 (0)