Skip to content

Commit

Permalink
report the apt cache timestamp
Browse files Browse the repository at this point in the history
We use the `pkgcache.bin` modification time as a heuristic, but there
might be a better way to do this.

We also silently ignore errors when pulling that file to avoid broken
systems from breaking the other metrics. I believe this will lead to a
null metric which is probably what we want anyway.
  • Loading branch information
anarcat committed Oct 13, 2023
1 parent 34dd42e commit c0dd4bd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apt_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def _write_autoremove_pending(registry, cache):
g.set(len(autoremovable_packages))


def _write_cache_timestamps(registry):
g = Gauge('apt_update_timestamp_seconds', "Apt update last run time.", registry=registry)
try:
g.set(os.stat('/var/cache/apt/pkgcache.bin').st_mtime)
except OSError:
pass


def _write_reboot_required(registry):
g = Gauge('node_reboot_required', "Node reboot is required for software updates.",
registry=registry)
Expand All @@ -96,6 +104,7 @@ def _main():
_write_pending_upgrades(registry, cache)
_write_held_upgrades(registry, cache)
_write_autoremove_pending(registry, cache)
_write_cache_timestamps(registry)
_write_reboot_required(registry)
print(generate_latest(registry).decode(), end='')

Expand Down

0 comments on commit c0dd4bd

Please sign in to comment.