Skip to content

Commit

Permalink
Support 'generations' flag to mark days of logs we want to keep
Browse files Browse the repository at this point in the history
The "generations" flag indicates days of logs we'd like to keep
considering disk space usage. Users can define this flag in atoprc
according to their own needs.

Signed-off-by: Fei Li <[email protected]>
  • Loading branch information
ShirleyFei committed Mar 7, 2023
1 parent eb158ef commit 9837813
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions atop.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ unsigned long interval = 10;
unsigned long sampcnt;
char screen;
int linelen = 80;
int generations = 28; /* By default, keep recent 30 days' log */
char acctreason; /* accounting not active (return val) */
char rawname[RAWNAMESZ];
char rawreadflag;
Expand Down Expand Up @@ -200,6 +201,7 @@ static void readrc(char *, int);

static void do_interval(char *, char *);
static void do_linelength(char *, char *);
static void do_generations(char *, char *);

static struct {
char *tag;
Expand All @@ -209,6 +211,7 @@ static struct {
{ "flags", do_flags, 0, },
{ "interval", do_interval, 0, },
{ "linelen", do_linelength, 0, },
{ "generations", do_generations, 0, },
{ "username", do_username, 0, },
{ "procname", do_procname, 0, },
{ "maxlinecpu", do_maxcpu, 0, },
Expand Down Expand Up @@ -975,6 +978,12 @@ do_linelength(char *name, char *val)
linelen = get_posval(name, val);
}

static void
do_generations(char *name, char *val)
{
generations = get_posval(name, val);
}

/*
** read RC-file and modify defaults accordingly
*/
Expand Down
9 changes: 9 additions & 0 deletions atop.daily
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ then
rm "$PIDFILE"
fi

#e.g. generations 5
ATOPRC="/etc/atoprc"
if [ -f $ATOPRC ]; then
RCGENERATIONS=`cat $ATOPRC | grep -w '^generations' -m 1 | awk '{print $2}'`
if [ -n "$RCGENERATIONS" ]; then
LOGGENERATIONS=$RCGENERATIONS
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
Expand Down
6 changes: 6 additions & 0 deletions man/atoprc.5
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ The default interval value in seconds.
The length of a screen line when sending output to a file or pipe (default 80).
.PP
.TP 4
.B generations
The number of day logs need to keep, considering disk space usage and other needs.
.PP
.TP 4
.B username
The default regular expression for the users for which active
processes will be shown.
Expand Down Expand Up @@ -232,6 +236,8 @@ flags\ \ \ \ \ \ \ \ \ Aaf
.br
interval\ \ \ \ \ \ 5
.br
generations\ \ \ 3
.br
username
.br
procname
Expand Down

0 comments on commit 9837813

Please sign in to comment.