Back to Engineering Blog
Infrastructure & Reliability 3 min read

Logrotate Can't Rotate a Filename That's Unique Every Day

Disks on the log collector kept filling despite a seven-day retention policy. rsyslog's per-day filenames meant logrotate renamed each file out of its own glob and lost track of it. A small mtime-based prune and a daily timer fixed it.

Jason NevillBy , Houston, TX
#rsyslog#logrotate#Retention#Monitoring

Key Architectural Takeaways

  • logrotate cannot enforce retention on a filename that is unique per day, because it renames a file out of its own glob on first touch.
  • An mtime-based prune script with a timer is simpler and enforceable.
  • 'Installed on day one' is a claim; confirm exporters and agents with the monitoring system, not the build notes.

The challenge

Disk-almost-full faults fired on the central log collector and the central CrowdSec host. The collector's retention policy was seven days, but disks kept filling. Rather than accept the drafted remediation plans, we looked for root causes.

Root cause

rsyslog's dynaFile setting names the file for each day, so the name is unique per day. logrotate works by matching a glob, renaming the file and compressing it. For a permanently unique per-day filename, the first rotation renames the file out of its own glob, so logrotate never sees it again and cannot expire it. Retention was never enforced. On the collector, 352 of 730 files were older than seven days.

The fix

We replaced logrotate for this directory with a direct mtime-based prune script and a daily timer, in the rsyslog server role. Verified live: the collector went from 90% to 78% used, and the CrowdSec host from 90% to 71%, helped by about 2 GB freed with apt-get clean. A USB drive for the collector had been suggested, and we deliberately did not build it. It was not needed to close the faults. It stays an option if much longer retention is wanted.

A "host down" that was not what it looked like

A fault flagged a content host as down, though it pinged. Prometheus confirmed up = 0 for real: node_exporter, the Wazuh agent and Netdata had never actually been installed on that host, contradicting the build note's claim that they were added with the build. We deployed all three through the fleet playbooks and verified up = 1 from Prometheus.

What we denied

Three of the drafted remediation proposals for the disk faults were denied with evidence. One invented a command that does not exist, and another recommended a forced fsck -y on a live root filesystem. The human review step earned its keep.

Takeaway

When a policy is set but the symptom persists, test whether the mechanism can enforce it at all. And treat "installed" as unproven until the monitoring system says it sees the host.

Follow the build on LinkedIn or by RSS.

All Articles

Follow the build

Questions about the build, or spotted something we got wrong? Find us on LinkedIn and GitHub.