From 98378130a734ba1c5c19a64e249e508c1b55973e Mon Sep 17 00:00:00 2001 From: Fei Li Date: Thu, 12 Sep 2019 18:18:36 +0800 Subject: [PATCH] Support 'generations' flag to mark days of logs we want to keep 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 --- atop.c | 9 +++++++++ atop.daily | 9 +++++++++ man/atoprc.5 | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/atop.c b/atop.c index de880549..bd885309 100644 --- a/atop.c +++ b/atop.c @@ -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; @@ -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; @@ -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, }, @@ -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 */ diff --git a/atop.daily b/atop.daily index 55737fda..3625282f 100755 --- a/atop.daily +++ b/atop.daily @@ -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 diff --git a/man/atoprc.5 b/man/atoprc.5 index cb9fab19..672c0989 100644 --- a/man/atoprc.5 +++ b/man/atoprc.5 @@ -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. @@ -232,6 +236,8 @@ flags\ \ \ \ \ \ \ \ \ Aaf .br interval\ \ \ \ \ \ 5 .br +generations\ \ \ 3 +.br username .br procname