From 96287919c311a17ff3c5e3d4b5ebb4507a8ddadf Mon Sep 17 00:00:00 2001 From: Gerlof Langeveld Date: Sat, 9 Jun 2018 12:06:49 +0200 Subject: [PATCH] Modify default values in atop.daily script Add possibility to override all necessary default values in the atop.daily script, i.e. variable LOGOPTS, LOGINTERVAL and LOGGENERATIONS. --- atop.daily | 47 ++++++++++++++++++++++++++++++++--------------- man/atop.1 | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 76 insertions(+), 22 deletions(-) diff --git a/atop.daily b/atop.daily index 3539e62..57a9507 100755 --- a/atop.daily +++ b/atop.daily @@ -1,21 +1,42 @@ #!/bin/bash +LOGOPTS="-R" # default options +LOGINTERVAL=600 # default interval in seconds +LOGGENERATIONS=28 # default number of days + +# allow administrator to overrule the variables +# defined above +# +DEFAULTSFILE=/etc/default/atop # possibility to overrule vars + +if [ -e "$DEFAULTSFILE" ] +then + . "$DEFAULTSFILE" + + # validate overruled variables + # (LOGOPTS and LOGINTERVAL are implicitly by atop) + # + case "$LOGGENERATIONS" in + ''|*[!0-9]*) + echo non-numerical value for LOGGENERATIONS >&2 + exit 1;; + esac +fi + CURDAY=`date +%Y%m%d` LOGPATH=/var/log/atop BINPATH=/usr/bin PIDFILE=/var/run/atop.pid -DEFAULTSFILE=/etc/default/atop -INTERVAL=600 # interval 10 minutes # verify if atop still runs for daily logging # -if [ -e $PIDFILE ] && ps -p `cat $PIDFILE` | grep 'atop$' > /dev/null +if [ -e "$PIDFILE" ] && ps -p `cat "$PIDFILE"` | grep 'atop$' > /dev/null then - kill -USR2 `cat $PIDFILE` # final sample and terminate + kill -USR2 `cat "$PIDFILE"` # final sample and terminate CNT=0 - while ps -p `cat $PIDFILE` > /dev/null + while ps -p `cat "$PIDFILE"` > /dev/null do let CNT+=1 @@ -27,21 +48,17 @@ then sleep 1 done - rm $PIDFILE -fi - -ATOPOPTS="-R" -if [ -e "$DEFAULTSFILE" ]; then - . "$DEFAULTSFILE" + rm "$PIDFILE" fi -# delete logfiles older than four weeks +# 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 +28 -exec rm {} \;)& ) +( (sleep 3; find "$LOGPATH" -name 'atop_*' -mtime +"$LOGGENERATIONS" -exec rm {} \;)& ) -# activate atop with interval of 10 minutes, replacing the current shell +# activate atop with an interval of S seconds (configurable), +# replacing the current shell # echo $$ > $PIDFILE -exec $BINPATH/atop $ATOPOPTS -w $LOGPATH/atop_$CURDAY $INTERVAL > $LOGPATH/daily.log 2>&1 +exec $BINPATH/atop $LOGOPTS -w "$LOGPATH"/atop_"$CURDAY" "$LOGINTERVAL" > "$LOGPATH/daily.log" 2>&1 diff --git a/man/atop.1 b/man/atop.1 index 17ad69f..7866e49 100644 --- a/man/atop.1 +++ b/man/atop.1 @@ -1,4 +1,4 @@ -.TH ATOP 1 "March 2017" "Linux" +.TH ATOP 1 "June 2018" "Linux" .SH NAME .B atop - Advanced System & Process Monitor @@ -859,11 +859,29 @@ This scripts takes care that .B atop is activated every day at midnight to write compressed binary data to the file .BI /var/log/atop/atop_ YYYYMMDD -with an interval of 10 minutes. -.br -Furthermore the script removes all raw files which are older than four weeks. -.br -The script is activated via the +with an interval of 10 minutes by default. The +.B -R +flag is passed by default to gather information about the proportional +set size of every process. +.br +Furthermore the script removes all raw files which are by default +older than 28 days. +.br +The mentioned default values can be overruled by creating the file +.B /etc/default/atop +that might contain other values for +.B LOGOPTS +(by default the +.B -R +flag), +.B LOGINTERVAL +(in seconds, by default 600), and +.B LOGGENERATIONS +(in days, by default 28). +.PP +The +.B atop.daily +script is activated via the .B cron daemon using the file .I /etc/cron.d/atop @@ -2092,6 +2110,25 @@ Configuration file containing personal default values. See related man-page. .PP .TP 5 +.B /etc/default/atop +Configuration file to overrule the settings of +.I atop +that runs in the background to create the daily logfile. +This file is not created or overwritten when +.I atop +is installed, so it has to be created manually to override +the default settings. +The default settings are: +.TP 8 +\ +.br +LOGOPTS="-R" +.br +LOGINTERVAL=600 +.br +LOGGENERATIONS=28 +.PP +.TP 5 .BI /var/log/atop/atop_ YYYYMMDD Raw file, where .I YYYYMMDD @@ -2123,7 +2160,7 @@ after reading the standard process accounting records. .B netatopd(8), .B logrotate(8) .br -.B http://www.atoptool.nl +.B https://www.atoptool.nl .SH AUTHOR Gerlof Langeveld (gerlof.langeveld@atoptool.nl) .br