Skip to content

Commit 0c110e9

Browse files
committed
Support 'logpath' flag to change log path
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]>
1 parent 5a280fd commit 0c110e9

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

atop.c

+9
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ unsigned long sampcnt;
312312
char screen;
313313
int linelen = 80;
314314
int generations = 28; /* By default, keep recent 30 days' log */
315+
char *logpath = "/var/log/atop"; /*support writing to other paths, to avoid system disk being fully occupied */
315316
char acctreason; /* accounting not active (return val) */
316317
char rawname[RAWNAMESZ];
317318
char rawreadflag;
@@ -354,6 +355,7 @@ void do_flags(char *, char *);
354355
void do_interval(char *, char *);
355356
void do_linelength(char *, char *);
356357
void do_generations(char *, char *);
358+
void do_logpath(char *, char *);
357359
void do_username(char *, char *);
358360
void do_procname(char *, char *);
359361
void do_maxcpu(char *, char *);
@@ -406,6 +408,7 @@ static struct {
406408
{ "interval", do_interval, 0, },
407409
{ "linelen", do_linelength, 0, },
408410
{ "generations", do_generations, 0, },
411+
{ "logpath", do_logpath, 0, },
409412
{ "username", do_username, 0, },
410413
{ "procname", do_procname, 0, },
411414
{ "maxlinecpu", do_maxcpu, 0, },
@@ -1164,6 +1167,12 @@ do_generations(char *name, char *val)
11641167
generations = get_posval(name, val);
11651168
}
11661169

1170+
void
1171+
do_logpath(char *name, char *val)
1172+
{
1173+
logpath = "/var/log/atop";
1174+
}
1175+
11671176
/*
11681177
** read RC-file and modify defaults accordingly
11691178
*/

atop.daily

+14
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,25 @@ if [ -f $ATOPRC ]; then
6060
fi
6161
fi
6262

63+
#e.g. logpath /data00/log/atop
64+
ATOPRC="/etc/atoprc"
65+
if [ -f $ATOPRC ]; then
66+
RCLOGPATH=`cat $ATOPRC | grep ^logpath -m 1 | awk '{print $2}'`
67+
if [ -n "$RCLOGPATH" ]; then
68+
LOGPATH=$RCLOGPATH
69+
mkdir -p $LOGPATH
70+
fi
71+
fi
72+
6373
# delete logfiles older than N days (configurable)
6474
# start a child shell that activates another child shell in
6575
# the background to avoid a zombie
6676
#
6777
( (sleep 3; find "$LOGPATH" -name 'atop_*' -mtime +"$LOGGENERATIONS" -exec rm {} \;)& )
78+
# In case we change the logpath, ensure consistent log storage status
79+
if [ "$LOGPATH" != "/var/log/atop" ];then
80+
( (sleep 3; find "/var/log/atop" -name 'atop_*' -mtime +"$LOGGENERATIONS" -exec rm {} \;)& )
81+
fi
6882

6983
# activate atop with an interval of S seconds (configurable),
7084
# replacing the current shell

man/atoprc.5

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ The length of a screen line when sending output to a file or pipe (default 80).
4747
The number of day logs need to keep, considering disk space usage and other needs.
4848
.PP
4949
.TP 4
50+
.B logpath
51+
The log path atop writes to. This is meaningful especially to avoid the root directory being fully occupied.
52+
.PP
53+
.TP 4
5054
.B username
5155
The default regular expression for the users for which active
5256
processes will be shown.
@@ -238,6 +242,8 @@ interval\ \ \ \ \ \ 5
238242
.br
239243
generations\ \ \ 3
240244
.br
245+
logpath\ \ \ \ \ \ \ /data00/log/atop
246+
.br
241247
username
242248
.br
243249
procname

0 commit comments

Comments
 (0)