how auto-rotate atop logs

6,524

In RH/CentOS atop is not being regulated by logrotate.

In /usr/share/atop/atop.daily there is an example script to deal with atop log file rotation.

The script as a find line deleting logs older than 28 days as in:

# delete logfiles older than four weeks
# start a child shell that activates another child shell in
# the background to avoid a zombie
#
( (sleep 3; find $LOGPATH -name 'atop_*' -mtime +28 -exec rm {} \;)& )

You can copy that script to /etc/cron.daily and change the number of days to 5.

( (sleep 3; find $LOGPATH -name 'atop_*' -mtime +5 -exec rm {} \;)& )

Dealing with daily files can also be a bit inconvenient. Using the above script, if you do not intend in doing a pure daily rotation, you can also edit /etc/sysconfig/atop and change the duration, for instance for 10 minutes, as in:

INTERVAL=600

As an alternative, if you do want to keep rotating it daily, you can create a logrotate file at /etc/logrotate.d/atop as in:

/var/log/atop/atop_20[0-9][0-9][0-9][0-9][0-9][0-9] {
    missingok
    daily
    nodateext
    rotate 5
    ifempty
    nocreate
    postrotate
      /usr/bin/find /var/log/atop/ -maxdepth 1 -mount -name atop_20\[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\]\[0-9\]\* -mtime +40 -exec /bin/rm {} \;
    endscript
    }

If you are doing the logrotate version, you need to keep the daily files, and do not change the INTERVAL parameter.

Share:
6,524
yael
Author by

yael

Updated on September 18, 2022

Comments

  • yael
    yael almost 2 years

    we can see that atop logs are created on each day and that take a lot of space

    ls -l /var/log/atop/
    total 1634632
    -rw-r--r-- 1 root root 127992086 Aug 30 01:49 atop_20180829
    -rw-r--r-- 1 root root 262277153 Aug 31 00:00 atop_20180830
    -rw-r--r-- 1 root root 321592670 Sep  1 00:00 atop_20180831
    -rw-r--r-- 1 root root 330041977 Sep  2 00:00 atop_20180901
    -rw-r--r-- 1 root root 269040388 Sep  3 00:00 atop_20180902
    -rw-r--r-- 1 root root 274807097 Sep  4 00:00 atop_20180903
    -rw-r--r-- 1 root root  85426960 Sep  4 06:03 atop_20180904
    -rw-r--r-- 1 root root         0 Sep  4 06:03 daily.log
    

    how to limit the atop log for example to only 5 logs ( 5 last days )

    • yael
      yael almost 6 years
      this isnt logical , wht atop not include conf for this?
    • Ulrich Schwarz
      Ulrich Schwarz almost 6 years
      Please provide ls /etc/logrotate.d. There might be a file atop in there which then governs how logrotate treats the log files.
  • yael
    yael almost 6 years
    regrading the second part , sorry but not understand to which value to change the INTERVAL=? , in order to keep the log for 5 days
  • Rui F Ribeiro
    Rui F Ribeiro almost 6 years
    @yael Edited the question.