Created
October 15, 2022 13:50
-
-
Save SmartFinn/b6e865febc06505d7937675ecacf0663 to your computer and use it in GitHub Desktop.
Collect journald stats for prometheus-node-exporter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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