Page MenuHomeVyOS Platform

Increase rotation for atop.acct
Closed, ResolvedPublicBUG

Description

We have an accounting file atop.acct stored in /run/atop/atop.acct. This rotates one per month.
If we have very often command execution from CLI via SSH (some automated process) then we have issue with full utilisation /run partition

[email protected]:~$ df -lh
Filesystem Size Used Avail Use% Mounted on
tmpfs      400M 392M 8.0M  99% /run

[email protected]:~$ sudo ls -lh /run/atop/atop.acct
-rw------- 1 root root 192M Dec 23 08:45 /run/atop/atop.acct

I think in this case we have a workaround, but I hope we can change reduce rotation time by default.
create script /config/scripts/fix_atop.sh and add

#!/bin/bash
sudo killall atop
sudo /usr/sbin/invoke-rc.d atop _cron

add permission for executing script

chmod +x /config/scripts/fix_atop.sh

and add cron rules

set system task-scheduler task ATOP_FIX executable path '/config/scripts/fix_atop.sh'
set system task-scheduler task ATOP_FIX interval '60m'

Details

Difficulty level
Unknown (require assessment)
Version
1.2.3
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Unspecified (possibly destroys the router)

Event Timeline

Why we not fix just logrotate config for it?

When using logrotate we can take full owership about the resources that will be used for number of files and its size - so i think this will be the best approach.

logrotate supports handling binary files (see https://stackoverflow.com/a/26037557)

syncer triaged this task as Normal priority.Feb 8 2020, 3:07 PM
Dmitry changed the task status from Open to In progress.Mar 20 2020, 9:33 PM

Thanks @syncer and @c-po . As I understand logrotate run once per day. I hope this will be enough

[email protected]:~# ls /etc/cron.daily/ | grep logro
logrotate
[email protected]:~# cat /etc/crontab | grep daily
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

So, now I have logrotate script for atop on my test router

cat /etc/logrotate.d/atop 
/run/atop/atop.acct {
	rotate 0
	nomissingok
	size 50M
	postrotate
		/etc/init.d/atop restart
	endscript
}

With manually run, seems all works

logrotate /etc/logrotate.d/atop --verbose
reading config file /etc/logrotate.d/atop

Handling 1 logs

rotating pattern: /run/atop/atop.acct  52428800 bytes (no old logs will be kept)
empty log files are rotated, old logs are removed
considering log /run/atop/atop.acct
  log needs rotating
rotating log /run/atop/atop.acct, log->rotateCount is 0
dateext suffix '-20200320'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /run/atop/atop.acct.1 to /run/atop/atop.acct.2 (rotatecount 1, logstart 1, i 1), 
old log /run/atop/atop.acct.1 does not exist
renaming /run/atop/atop.acct.0 to /run/atop/atop.acct.1 (rotatecount 1, logstart 1, i 0), 
old log /run/atop/atop.acct.0 does not exist
log /run/atop/atop.acct.2 doesn't exist -- won't try to dispose of it
renaming /run/atop/atop.acct to /run/atop/atop.acct.1
disposeName will be /run/atop/atop.acct.1
running postrotate script
Restarting atop (via systemctl): atop.service.
removing old log /run/atop/atop.acct.1

Nice. What is atop actually used for?

Sometimes we use this for detecting memleak and some clients issues with high CPU load. When we get users /var/log/atop* then we can reproduce locally and find wrong process, memleaking etc.

Following script more appreciated

/run/atop/atop.acct {
	rotate 0
	nomissingok
	size 100M
	postrotate
		PIDFILE=/run/atop.pid
		if [ -e $PIDFILE ] && \
			ps -p `cat $PIDFILE` | grep 'atop$' > /dev/null
		then
			kill -15 `cat $PIDFILE`
			rm $PIDFILE
		fi
		sleep 1
		/etc/init.d/atop restart
	endscript
}
Dmitry claimed this task.
Dmitry edited projects, added VyOS 1.2 Crux (VyOS 1.2.6); removed VyOS 1.3 Equuleus.