2

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 )

2
  • this isnt logical , wht atop not include conf for this? Commented Sep 4, 2018 at 6:21
  • Please provide ls /etc/logrotate.d. There might be a file atop in there which then governs how logrotate treats the log files. Commented Sep 4, 2018 at 7:21

2 Answers 2

6

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.

2
  • regrading the second part , sorry but not understand to which value to change the INTERVAL=? , in order to keep the log for 5 days Commented Sep 4, 2018 at 9:07
  • @yael Edited the question. Commented Sep 4, 2018 at 9:25
0

Found this solution after reading and spending somes times with atop.

#!/bin/sh

LOGOPTS=""                              # default options
LOGINTERVAL=600                         # default interval in seconds
LOGGENERATIONS=28                       # default number of days
LOGPATH=/var/log/atop                   # default log location

# allow administrator to overrule the variables
# defined above
#
DEFAULTSFILE=/etc/sysconfig/atop                # possibility to overrule vars

if [ -e "$DEFAULTSFILE" ]
then
        . "$DEFAULTSFILE"

        # validate overruled variables
        # (LOGOPTS and LOGINTERVAL are implicitly by atop)
        #
        case "$LOGGENERATIONS" in
            ''|*[!0-9]*)
                echo non-numerical value for LOGGENERATIONS >&2
                exit 1;;
        esac
fi

CURDAY=`date +%Y%m%d`
BINPATH=/usr/bin
PIDFILE=/var/run/atop.pid

# verify if atop still runs for daily logging
#
if [ -e "$PIDFILE" ] && ps -p `cat "$PIDFILE"` | grep 'atop$' > /dev/null
then
        kill -USR2 `cat "$PIDFILE"`       # final sample and terminate

        CNT=0

        while ps -p `cat "$PIDFILE"` > /dev/null
        do
                CNT=$((CNT + 1))

                if [ $CNT -gt 5 ]
                then
                        break;
                fi

                sleep 1
        done

        rm "$PIDFILE"
fi

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

# activate atop with an interval of S seconds (configurable),
# replacing the current shell
#
exec gzip $LOGPATH/atop_$[CURDAY -1]
echo $$ > $PIDFILE
exec systemctl restart atop > "$LOGPATH/daily.log" 2>&1

Add this in /etc/crond.daily/atop.daily

Hope this help

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.