The atop
performance monitoring tool by default stores daily log files in /var/log/atop/
with a 28-day retention period. This can quickly accumulate to several gigabytes of disk space (3.5GB in your case). The binary log files (typically named atop_YYYYMMDD
) contain system performance metrics collected at regular intervals.
There are two primary ways to control atop's logging behavior:
# Method 1: Configure log rotation in /etc/atop/atop.daily
# This controls the cron job that rotates atop logs
LOGGENERATIONS=7 # Keep logs for 7 days instead of 28
LOGPATH="/var/log/atop" # Verify log directory
INTERVAL=600 # Set collection interval in seconds (default 600)
# Method 2: Edit /etc/default/atop (Debian/Ubuntu) or /etc/sysconfig/atop (RHEL)
# Set these parameters:
INTERVAL=300 # 5-minute collection interval
LOGGEN=14 # Keep logs for 14 days
To immediately clean up old log files while waiting for configuration changes to take effect:
# Remove logs older than 7 days
find /var/log/atop -type f -name 'atop_*' -mtime +7 -exec rm {} \;
# Alternative: Keep only the most recent N files
ls -t /var/log/atop/atop_* | tail -n +15 | xargs rm
For a permanent solution, modify the atop configuration file (location varies by distro):
# On Debian/Ubuntu systems:
sudo nano /etc/default/atop
# Add or modify these lines:
INTERVAL=300
LOGGEN=7
# On RHEL/CentOS systems:
sudo nano /etc/sysconfig/atop
# Add or modify:
OPTS="-a -w /var/log/atop/atop_$(date +%Y%m%d) 300 7"
After making changes, restart the atop service:
sudo systemctl restart atop
# Or if running as cron job:
sudo /etc/init.d/atop restart
Check the new log rotation behavior after 24 hours by verifying the number of log files in /var/log/atop/
.
By default, atop
follows a strict daily logging pattern where it:
- Creates new log files at midnight (named
atop_YYYYMMDD
) - Compresses files older than 28 days
- Stores everything in
/var/log/atop/
The primary configuration file controls log retention. Edit with root privileges:
sudo nano /etc/default/atop
Key parameters to modify:
# Reduce retention from 28 days to 7 days
LOGGENERATIONS=7
# Decrease log interval from default 600s (10 minutes)
INTERVAL=1800 # 30 minutes
# Alternative: Disable daily logging completely
LOGOPTS="-R"
For more granular control, create a logrotate configuration:
sudo nano /etc/logrotate.d/atop
Add these rotation rules:
/var/log/atop/atop_* {
daily
missingok
rotate 7
compress
delaycompress
notifempty
size 100M
}
To immediately reclaim space:
# Remove logs older than 7 days
find /var/log/atop -type f -mtime +7 -exec rm {} \;
# Alternative: Keep only last 10 files
ls -t /var/log/atop/atop_* | tail -n +11 | xargs rm -f
After modifying configurations:
# Restart atop service
sudo systemctl restart atop
# Check active configuration
atop -r /var/log/atop/atop_$(date +%Y%m%d) -v | head -n 20