Page 1 of 1

Configuring atop with custom log Interval and automated log cleanup

Posted: Wed Nov 27, 2024 4:29 pm
by isscbta
This guide provides step-by-step instructions to install Atop, configure it to log at a custom interval, and set up automatic log file cleanup.

Installation

Update your package lists and install Atop:

Code: Select all

apt update
apt install -y atop
Configuring Atop

We will set the logging interval to 10 seconds.

Update the Atop systemd service file

Code: Select all

sed -i “s|Environment=LOGINTERVAL=.*|Environment=LOGINTERVAL=10|g” /lib/systemd/system/atop.service
sed -i “s|${LOGINTERVAL}|10|g” /lib/systemd/system/atop.service
if ! grep -q ‘LOGINTERVAL’ /lib/systemd/system/atop.service; then
INIVAL=‘Environment=“LOGINTERVAL=600”’
sed -i “s|Service|[Service]\n$INIVAL|g” /lib/systemd/system/atop.service
fi
Update the Atop default configuration

Code: Select all

sed -i “s#LOGINTERVAL=.*#LOGINTERVAL=10#g” /etc/default/atop
if ! grep -q ‘LOGINTERVAL’ /etc/default/atop; then
echo ‘LOGINTERVAL=10’ >> /etc/default/atop
fi
Reload and restart Atop

Code: Select all

systemctl daemon-reload
systemctl restart atop
Setting Up Automatic Log Cleanup

Add a cron job to delete Atop logs older than 2 days. This job runs daily at 4:09 AM:

Code: Select all

crontab -l | { cat; echo “9 4 * * * find /var/log/atop/ -mtime +2 -delete”; } | crontab -
Viewing Logs at a Specific Time

To view Atop logs for a specific minute, for example, 13:40:

Code: Select all

atop -Af1 -b 13:40 -r /var/log/atop/atop_20241126
  • Use ‘t’ to go forward in time.
  • Use ‘T’ to go back in time.
  • To analyze specific times, press ‘b’ and enter the desired time.