Skip to content

Commit 8eaa8c7

Browse files
committed
No longer use a month-by-month directory structure when HISTORY is
greater than 28 This patch updates sa1 and sa2 shell scripts in order to no longer use the tree of directories that used to be created in the /var/log/sa directory when HISTORY was greater than 28. Now, when HISTORY is greater than 28, sadc is called with option -D to create data files named saYYYYMMDD. All these files are located in the same directory. This patch also updates the sysstat parameters file to add a new variable: SA_DIR, which gives the directory where sa and sar files are saved. Signed-off-by: Sebastien GODARD <[email protected]>
1 parent 986fbed commit 8eaa8c7

File tree

3 files changed

+28
-62
lines changed

3 files changed

+28
-62
lines changed

sa1.in

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,16 @@
1010
# Used only if ${SYSCONFIG_DIR}/sysstat doesn't exist!
1111
HISTORY=0
1212
SADC_OPTIONS=""
13-
DDIR=@SA_DIR@
14-
DATE=`date +%d`
15-
CURRENTFILE=sa${DATE}
16-
CURRENTDIR=`date +%Y%m`
13+
SA_DIR=@SA_DIR@
1714
SYSCONFIG_DIR=@SYSCONFIG_DIR@
1815
umask 0022
1916

2017
[ -r ${SYSCONFIG_DIR}/sysstat ] && . ${SYSCONFIG_DIR}/sysstat
18+
[ -d ${SA_DIR} ] || SA_DIR=@SA_DIR@
19+
2120
if [ ${HISTORY} -gt 28 ]
2221
then
23-
cd ${DDIR} || exit 1
24-
[ -d ${CURRENTDIR} ] || mkdir -p ${CURRENTDIR}
25-
# If ${CURRENTFILE} exists and is a regular file, then make sure
26-
# the file was modified this day (and not e.g. month ago)
27-
# and move it to ${CURRENTDIR}
28-
[ ! -L ${CURRENTFILE} ] &&
29-
[ -f ${CURRENTFILE} ] &&
30-
[ "`date +%Y%m%d -r ${CURRENTFILE}`" = "${CURRENTDIR}${DATE}" ] &&
31-
mv -f ${CURRENTFILE} ${CURRENTDIR}/${CURRENTFILE}
32-
touch ${CURRENTDIR}/${CURRENTFILE}
33-
# Remove the "compatibility" link and recreate it to point to
34-
# the (new) current file
35-
rm -f ${CURRENTFILE}
36-
ln -s ${CURRENTDIR}/${CURRENTFILE} ${CURRENTFILE}
37-
else
38-
# If ${CURRENTFILE} exists, is a regular file and is from a previous
39-
# month then delete it so that it is recreated by sadc afresh
40-
[ -f ${CURRENTFILE} ] && [ "`date +%Y%m -r ${CURRENTFILE}`" -lt "${CURRENTDIR}" ] && rm -f ${CURRENTFILE}
22+
SADC_OPTIONS="${SADC_OPTIONS} -D"
4123
fi
4224

4325
ENDIR=@SA_LIB_DIR@
@@ -48,8 +30,7 @@ then
4830
# Note: Stats are written at the end of previous file *and* at the
4931
# beginning of the new one (when there is a file rotation) only if
5032
# outfile has been specified as '-' on the command line...
51-
exec ${ENDIR}/sadc -F -L ${SADC_OPTIONS} 1 1 -
33+
exec ${ENDIR}/sadc -F -L ${SADC_OPTIONS} 1 1 ${SA_DIR}
5234
else
53-
exec ${ENDIR}/sadc -F -L ${SADC_OPTIONS} $* -
35+
exec ${ENDIR}/sadc -F -L ${SADC_OPTIONS} $* ${SA_DIR}
5436
fi
55-

sa2.in

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,37 @@ S_TIME_FORMAT=ISO ; export S_TIME_FORMAT
99
umask 0022
1010
prefix=@prefix@
1111
exec_prefix=@exec_prefix@
12-
# Add a trailing slash so that 'find' can go through this directory if it's a symlink
13-
DDIR=@SA_DIR@/
12+
SA_DIR=@SA_DIR@
1413
SYSCONFIG_DIR=@SYSCONFIG_DIR@
15-
YESTERDAY=@YESTERDAY@
16-
DATE=`date ${YESTERDAY} +%d`
17-
CURRENTFILE=sa${DATE}
18-
CURRENTRPT=sar${DATE}
1914
HISTORY=@HISTORY@
2015
COMPRESSAFTER=@COMPRESSAFTER@
2116
ZIP="@ZIP@"
17+
YESTERDAY=@YESTERDAY@
18+
DATE=`date ${YESTERDAY} +%d`
19+
2220
[ -r ${SYSCONFIG_DIR}/sysstat ] && . ${SYSCONFIG_DIR}/sysstat
21+
[ -d ${SA_DIR} ] || SA_DIR=@SA_DIR@
22+
2323
if [ ${HISTORY} -gt 28 ]
2424
then
25-
CURRENTDIR=`date ${YESTERDAY} +%Y%m`
26-
cd ${DDIR} || exit 1
27-
[ -d ${CURRENTDIR} ] || mkdir -p ${CURRENTDIR}
28-
# Check if ${CURRENTFILE} is the correct file created at ${DATE}
29-
# Note: using `-ge' instead of `=' since the file could have
30-
# the next day time stamp because of the file rotating feature of sadc
31-
[ -f ${CURRENTFILE} ] &&
32-
[ "`date +%Y%m%d -r ${CURRENTFILE}`" -ge "${CURRENTDIR}${DATE}" ] || exit 0
33-
# If the file is a regular file, then move it to ${CURRENTDIR}
34-
[ ! -L ${CURRENTFILE} ] &&
35-
mv -f ${CURRENTFILE} ${CURRENTDIR}/${CURRENTFILE} &&
36-
ln -s ${CURRENTDIR}/${CURRENTFILE} ${CURRENTFILE}
37-
touch ${CURRENTDIR}/${CURRENTRPT}
38-
# Remove the "compatibility" link and recreate it to point to
39-
# the (new) current file
40-
rm -f ${CURRENTRPT}
41-
ln -s ${CURRENTDIR}/${CURRENTRPT} ${CURRENTRPT}
42-
CURRENTDIR=${DDIR}/${CURRENTDIR}
43-
else
44-
CURRENTDIR=${DDIR}
25+
DATE=`date ${YESTERDAY} +%Y%m%d`
4526
fi
46-
RPT=${CURRENTDIR}/${CURRENTRPT}
27+
CURRENTFILE=sa${DATE}
28+
CURRENTRPT=sar${DATE}
29+
30+
RPT=${SA_DIR}/${CURRENTRPT}
31+
DFILE=${SA_DIR}/${CURRENTFILE}
4732
ENDIR=@bindir@
48-
DFILE=${CURRENTDIR}/${CURRENTFILE}
33+
4934
[ -f "$DFILE" ] || exit 0
5035
cd ${ENDIR}
51-
[ -L ${RPT} ] && rm -f ${RPT}
5236
${ENDIR}/sar $* -f ${DFILE} > ${RPT}
53-
find ${DDIR} \( -name 'sar??' -o -name 'sa??' -o -name 'sar??.xz' -o -name 'sa??.xz' -o -name 'sar??.gz' -o -name 'sa??.gz' -o -name 'sar??.bz2' -o -name 'sa??.bz2' \) \
37+
38+
find ${SA_DIR} \( -name 'sar??' -o -name 'sa??' -o -name 'sar??.xz' -o -name 'sa??.xz' -o -name 'sar??.gz' -o -name 'sa??.gz' -o -name 'sar??.bz2' -o -name 'sa??.bz2' \) \
39+
-mtime +"${HISTORY}" -exec rm -f {} \;
40+
find ${SA_DIR} \( -name 'sar????????' -o -name 'sa????????' -o -name 'sar????????.xz' -o -name 'sa????????.xz' -o -name 'sar????????.gz' -o -name 'sa????????.gz' -o -name 'sar????????.bz2' -o -name 'sa????????.bz2' \) \
5441
-mtime +"${HISTORY}" -exec rm -f {} \;
55-
find ${DDIR} \( -name 'sar??' -o -name 'sa??' \) -type f -mtime +"${COMPRESSAFTER}" \
42+
find ${SA_DIR} \( -name 'sar??' -o -name 'sa??' -o -name 'sar????????' -o -name 'sa????????' \) -type f -mtime +"${COMPRESSAFTER}" \
5643
-exec ${ZIP} {} \; > /dev/null 2>&1
57-
# Remove broken links
58-
for f in `find ${DDIR} \( -name 'sar??' -o -name 'sa??' \) -type l`; do
59-
[ -e $f ] || rm -f $f
60-
done
61-
cd ${DDIR}
62-
rmdir [0-9]????? > /dev/null 2>&1
6344
exit 0
45+

sysstat.sysconfig.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ COMPRESSAFTER=@COMPRESSAFTER@
1212
# which are used for the generation of log files.
1313
SADC_OPTIONS="@COLLECT_ALL@"
1414

15+
# Directory where sa and sar files are saved.
16+
SA_DIR=@SA_DIR@
17+

0 commit comments

Comments
 (0)