journald filling /var/log: cap it and find the noisy unit
In short
Run journalctl --disk-usage to see how much space the journal takes, set SystemMaxUse= in /etc/systemd/journald.conf to cap it, and use journalctl --since to find the unit writing the most. A single unit logging in a loop is the usual cause.
The symptom
/var (or /, when /var is not its own filesystem) fills up, and du -sh /var/log/* points at /var/log/journal.
Diagnose it in two commands
The first command says how big the journal is, the second which program writes the most (it counts the last hour’s lines by their program name, the fifth field of the default format):
$ journalctl --disk-usage
Archived and active journals take up 7.8G in the file system.
$ journalctl --since "1 hour ago" -o short \
| awk '{print $5}' | sed 's/\[[0-9]*\]:$//; s/:$//' | sort | uniq -c | sort -rn | head
48211 payments-worker
904 nginx
213 sshd
A program far above the rest is the one to look at. The name is usually the unit’s name; to read one unit, add -u <unit>: journalctl -u payments-worker.service --since "1 hour ago".
Causes and how to tell them apart
| Cause | How to tell | Fix |
|---|---|---|
| No cap set, persistent journal | journalctl --disk-usage is several GB, /var/log/journal exists and SystemMaxUse= is unset |
Set SystemMaxUse= and restart journald |
| One unit logging in a loop | One program’s lines dominate the output above | Fix or quieten the unit; LogRateLimitIntervalSec= and LogRateLimitBurst= in its unit file bound it meanwhile |
| Debug logging left on | Many lines at debug priority: journalctl -p debug --since today |
Lower the application’s log level |
| Cap set above the free space | SystemMaxUse= is larger than the space /var has |
Lower the cap: journald also keeps SystemKeepFree= free |
Left unset, SystemMaxUse= defaults to 10% of the filesystem and SystemKeepFree= to 15%, each capped at 4 GB, and journald uses the smaller of the two limits. On a small root volume that is already a large share.
Fix it
Cap the journal, restart journald, then trim what is already there:
# /etc/systemd/journald.conf
[Journal]
SystemMaxUse=1G
$ sudo systemctl restart systemd-journald
$ sudo journalctl --vacuum-size=1G
Only archived journal files are deleted, so the journal can still sit above the cap right after a vacuum. For a runaway unit, the cap only treats the symptom: fix the unit.
Stop it coming back
Keep the cap in configuration management so a rebuilt host has it. Alert on the filesystem before it is full rather than after, and look at the noisiest unit with the command above each week.
What WatchTower15 shows
The agent reports the space used on each mounted filesystem and raises the disk alarms per mount, so /var filling is caught on its own: Volume is full warns at 85% and is critical at 95%, and Volume is filling up warns when the volume will be full within 7 days. Its log collection reads the systemd journal, so the noisy unit is one search away. See Alarms & alerting for the volume rules and Logs for how the journal is collected.