node_exporter's conntrack collector reads the per-CPU counters from /proc/net/stat/nf_conntrack, which Ubuntu's kernels (24.04, 26.04) don't build. The collector fails there and drop counters are missing. The new role writes conntrack.prom from `conntrack -S` every minute, with the same metric names and types node_exporter uses, plus the table size and limit. write-textfile moves to its own write_textfile role, which apt_info and conntrack_stats depend on. Version 0.2.0.
abh.textfile_collectors
Ansible collection that installs textfile collector scripts for Prometheus
node_exporter, each with a systemd timer writing a .prom file into the
textfile collector directory.
Scripts under roles/*/files/upstream/ are unmodified copies from
node-exporter-textfile-collector-scripts
(Apache-2.0, license in roles/*/files/upstream/LICENSE); the others are
local to this collection. The distro
package prometheus-node-exporter-collectors would be simpler, but on
Ubuntu 24.04 it depends on the distro prometheus-node-exporter, which
conflicts with a node_exporter installed by prometheus.prometheus.
Roles
apt_info
Runs apt_info.py every 15 minutes, after dpkg runs, and after a successful
apt update. It writes apt.prom with:
apt_upgrades_pending,apt_upgrades_held(by origin and arch)apt_autoremove_pending,apt_packages_obsoleteapt_packages_per_originapt_package_cache_timestamp_secondsnode_reboot_required(whether/run/reboot-requiredexists)
The script doesn't run apt update; Ubuntu's apt-daily.timer does.
Variables (see roles/apt_info/defaults/main.yml):
| Variable | Default |
|---|---|
apt_info_textfile_dir |
{{ node_exporter_textfile_dir }} |
apt_info_interval |
15min |
apt_info_exclude |
[] |
apt_info_install_dir |
/usr/local/lib/textfile-collectors |
With prometheus.prometheus.node_exporter in the same play, the directory
comes from that role. Elsewhere, set apt_info_textfile_dir.
- hosts: all
become: true
roles:
- prometheus.prometheus.node_exporter
- abh.textfile_collectors.apt_info
conntrack_stats
Runs conntrack_stats.py every minute. It writes conntrack.prom with
node_nf_conntrack_entries, node_nf_conntrack_entries_limit and the
node_nf_conntrack_stat_* counters (drop, early_drop, insert_failed, ...),
summed over all CPUs, under the same names and types node_exporter uses.
node_exporter reads those counters from /proc/net/stat/nf_conntrack, which
only exists on kernels built with CONFIG_NF_CONNTRACK_PROCFS. Ubuntu's
kernels (24.04, 26.04) are not, so node_exporter's conntrack collector
fails there; this role gets the counters from conntrack -S over netlink
instead. Use it only on such hosts, and disable node_exporter's conntrack
collector there, or the entries metrics are collected twice and the
textfile collector reports an error.
| Variable | Default |
|---|---|
conntrack_stats_textfile_dir |
{{ node_exporter_textfile_dir }} |
conntrack_stats_interval |
1min |
conntrack_stats_install_dir |
/usr/local/lib/textfile-collectors |
write_textfile
Installs write-textfile, the helper the other roles' units use to publish
a script's output as a .prom file. The textfile directory usually belongs
to the exporter user while the units run as root, so it creates the
temporary file with O_EXCL|O_NOFOLLOW and renames it into place. The
other roles depend on it; there's no need to list it in a play.
Installing
From git, in collections/requirements.yml:
collections:
- name: https://gitea.develooper.com/ask/ansible-textfile-collectors.git
type: git
version: v0.2.0
Updating the upstream scripts
UPSTREAM records the upstream commit and the sha256 of each copied file.
make update # pin the upstream default branch
make update REF=<sha> # or a specific commit, branch or tag
make check # local files match UPSTREAM; collection builds
make verify # the pinned commit still serves those files
make update refuses to run if a local copy was edited, prints the upstream
commits that touched the files, and leaves the change for review. Bump
version in galaxy.yml and tag a release after updating.