Skip to content

Commit

Permalink
Support 'logpath' flag to change log path
Browse files Browse the repository at this point in the history
The "logpath" indicates log path atop writes. Users can define this
flag in atoprc to change the logpath according to their own needs.
This is meaningful especially to avoid the system disk being fully
occupied.

Signed-off-by: Fei Li <[email protected]>
  • Loading branch information
ShirleyFei committed Nov 17, 2021
1 parent 5a280fd commit 0c110e9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions atop.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ unsigned long sampcnt;
char screen;
int linelen = 80;
int generations = 28; /* By default, keep recent 30 days' log */
char *logpath = "/var/log/atop"; /*support writing to other paths, to avoid system disk being fully occupied */
char acctreason; /* accounting not active (return val) */
char rawname[RAWNAMESZ];
char rawreadflag;
Expand Down Expand Up @@ -354,6 +355,7 @@ void do_flags(char *, char *);
void do_interval(char *, char *);
void do_linelength(char *, char *);
void do_generations(char *, char *);
void do_logpath(char *, char *);
void do_username(char *, char *);
void do_procname(char *, char *);
void do_maxcpu(char *, char *);
Expand Down Expand Up @@ -406,6 +408,7 @@ static struct {
{ "interval", do_interval, 0, },
{ "linelen", do_linelength, 0, },
{ "generations", do_generations, 0, },
{ "logpath", do_logpath, 0, },
{ "username", do_username, 0, },
{ "procname", do_procname, 0, },
{ "maxlinecpu", do_maxcpu, 0, },
Expand Down Expand Up @@ -1164,6 +1167,12 @@ do_generations(char *name, char *val)
generations = get_posval(name, val);
}

void
do_logpath(char *name, char *val)
{
logpath = "/var/log/atop";
}

/*
** read RC-file and modify defaults accordingly
*/
Expand Down
14 changes: 14 additions & 0 deletions atop.daily
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,25 @@ if [ -f $ATOPRC ]; then
fi
fi

#e.g. logpath /data00/log/atop
ATOPRC="/etc/atoprc"
if [ -f $ATOPRC ]; then
RCLOGPATH=`cat $ATOPRC | grep ^logpath -m 1 | awk '{print $2}'`
if [ -n "$RCLOGPATH" ]; then
LOGPATH=$RCLOGPATH
mkdir -p $LOGPATH
fi
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 {} \;)& )
# In case we change the logpath, ensure consistent log storage status
if [ "$LOGPATH" != "/var/log/atop" ];then
( (sleep 3; find "/var/log/atop" -name 'atop_*' -mtime +"$LOGGENERATIONS" -exec rm {} \;)& )
fi

# activate atop with an interval of S seconds (configurable),
# replacing the current shell
Expand Down
6 changes: 6 additions & 0 deletions man/atoprc.5
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ The length of a screen line when sending output to a file or pipe (default 80).
The number of day logs need to keep, considering disk space usage and other needs.
.PP
.TP 4
.B logpath
The log path atop writes to. This is meaningful especially to avoid the root directory being fully occupied.
.PP
.TP 4
.B username
The default regular expression for the users for which active
processes will be shown.
Expand Down Expand Up @@ -238,6 +242,8 @@ interval\ \ \ \ \ \ 5
.br
generations\ \ \ 3
.br
logpath\ \ \ \ \ \ \ /data00/log/atop
.br
username
.br
procname
Expand Down

0 comments on commit 0c110e9

Please sign in to comment.