Skip to content

Instantly share code, notes, and snippets.

@SmartFinn
Created October 15, 2022 13:50
Show Gist options
  • Save SmartFinn/b6e865febc06505d7937675ecacf0663 to your computer and use it in GitHub Desktop.
Save SmartFinn/b6e865febc06505d7937675ecacf0663 to your computer and use it in GitHub Desktop.
Collect journald stats for prometheus-node-exporter
#!/bin/bash
#
# Description: Expose metrics from journald.
#
# Author: Sergei Eremenko (https://github.com/SmartFinn)
echo '# HELP journald_disk_usage Disk usage of all journal files in bytes.'
echo '# TYPE journald_disk_usage counter'
if [ -d /run/log/journal ]; then
echo 'journald_disk_usage{storage="temprary"}' \
"$(($(du -bs --threshold=512 /run/log/journal/ | cut -f1 -d$'\t')))"
else
echo 'journald_disk_usage{storage="temprary"} 0'
fi
if [ -d /var/log/journal ]; then
echo 'journald_disk_usage{storage="persistent"}' \
"$(($(du -bs --threshold=512 /var/log/journal/ | cut -f1 -d$'\t')))"
else
echo 'journald_disk_usage{storage="persistent"} 0'
fi
echo '# HELP journald_events_total Total number of journal entries.'
echo '# TYPE journald_events_total counter'
echo 'journald_events_total' \
"$(journalctl --output=cat --output-fields=_BOOT_ID | wc -l)"
[Unit]
Description=Collect journald stats for prometheus-node-exporter
[Service]
Type=oneshot
Environment=TMPDIR=/var/lib/node_exporter/textfile_collector
ExecStart=/bin/bash -c "/usr/share/node-exporter-textfile-collector/journald_stats.sh | sponge /var/lib/node_exporter/textfile_collector/journald_stats.prom"
[Unit]
Description=Run journald_stats.sh every minute
[Timer]
OnBootSec=0
OnUnitActiveSec=1min
[Install]
WantedBy=timers.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment