node-exporter-textfile-collector-scripts icon indicating copy to clipboard operation
node-exporter-textfile-collector-scripts copied to clipboard

apt_info.py - wrong cache timestamps

Open RomainMou opened this issue 1 year ago • 0 comments

Hi,

Since https://github.com/prometheus-community/node-exporter-textfile-collector-scripts/commit/feb943f6df8cbc536eaf7fca59a088d59bb39e82, I have encountered multiple issues with the cache timestamp:

  • at least on debian 12 cloud images, APT::Periodic::Update-Package-Lists doesn't mean that /var/lib/apt/periodic/update-success-stamp exists:

    >>> import apt_pkg
    >>> apt_pkg.init_config()
    >>> apt_pkg.config.find_b("APT::Periodic::Update-Package-Lists")
    True
    
    user@server:~# ls /var/lib/apt/periodic/
    download-upgradeable-stamp  unattended-upgrades-stamp  update-stamp  upgrade-stamp
    

    This leads to a null timestamp in the metric (apt_package_cache_timestamp_seconds 0.0). Maybe we can fallback on the other method if the file doesn't exist?

  • The mtime of /var/lib/apt/lists is not necessarily updated when running apt update (perhaps only if there are modifications?). This behavior differs from the previous use of /var/cache/apt/pkgcache.bin, which was consistently modified upon each update. Perhaps /var/lib/apt/lists/partial could serve as a suitable substitute in this case?

    user@server:~ date 
    Wed Dec 13 20:35:39 UTC 2023
    
    user@server:~ sudo apt update
    
    user@server:~ sudo ls -la /var/lib/apt/lists | grep "Dec 13"
    drwxr-xr-x 4 root root     4096 Dec 13 16:44 .
    drwx------ 2 _apt root     4096 Dec 13 20:35 partial
    
    user@servfer:~ sudo ls -la /var/cache/apt/pkgcache.bin       
    -rw-r--r-- 1 root root 35241413 Dec 13 20:35 /var/cache/apt/pkgcache.bin
    

RomainMou avatar Dec 13 '23 21:12 RomainMou