Generate a Prometheus file from the state of your APT repositories.
Scrape this file using the node_exporter textfile collector.
These metrics are exported:
| Name | Type | Description |
|---|---|---|
| apt_upgrades_total | gauge | Total number of packages to be upgraded |
| apt_security_upgrades_total | gauge | Number of security related packages to be upgraded |
| apt_reboot_needed | gauge | Indicates if a system reboot is needed (1 for yes, 0 for no) |
| apt_refresh_time_seconds | gauge | Indicates the last time the prometheus file was refreshed (unix time) |
A hostname label is added to all metrics.
The number of security upgrades depends on the repositories you use. It is based on packages from repositories with security in their name.
Run this script during the automatic package refresh: add a similar configuration file to the /etc/apt/apt.conf.d/ directory.
APT::Periodic::Update-Package-Lists "1";
APT::Update::Post-Invoke-Success {
"/path/apt_exporter/apt_exporter -quiet -output /path/collector-files/apt.prom || true"
};
DPkg::Post-Invoke {
"/path/apt_exporter/apt_exporter -quiet -output /path/collector-files/apt.prom || true"
};
It also means the script will run as the root user.
Run this script in a crontab, or as a systemd timer.
/path/apt_exporter/apt_exporter -quiet -output /path/collector-files/apt.prom