1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
#! /bin/sh
# PCP QA Test No. 314
# Exercise pmie_daily functionality - log rotation
#
# Copyright (c) 2007 Aconex. All Rights Reserved.
#
seq=`basename $0`
echo "QA output created by $seq"
# get standard filters
. ./common.product
. ./common.filter
. ./common.check
_cleanup()
{
cd $here
if $was_running
then
# don't trigger systemctl "request repeated too quickly" snarfoo
#
sleep 2
_restore_auto_restart pmie
_service pmie start >>$seq_full 2>&1
else
_service pmie stop >>$seq_full 2>&1
$sudo $PCP_BINADM_DIR/pmsignal -a -s TERM pmie >>$seq_full 2>&1
_wait_pmie_end
fi
$sudo rm -fr $tmp.*
$sudo rm -fr /tmp/$seq;
}
# wait for a file to appear ...
#
_wait_for()
{
_i=0
while [ ! -f "$1" ]
do
_i=`expr $_i + 1`
if [ "$_i" -ge 100 ]
then
echo "_wait_for: failed to see file $1 after 100 iterations"
return
fi
pmsleep 0.1
done
}
signal=$PCP_BINADM_DIR/pmsignal
status=1 # failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15
date >>$seq_full
was_running=false
[ -f $PCP_RUN_DIR/pmie.pid ] && was_running=true
if $was_running
then
_stop_auto_restart pmie
fi
# create a pmie config file, causing frequent output (to log)
cat > $tmp.config << EOF1
delta = 0.2 seconds;
fetched = simple.numfetch;
EOF1
echo "=== pmie config ===" >>$seq_full
cat $tmp.config >>$seq_full
# create pmie control files and test out various good/bad conditions
cat > $tmp.control << EOF2
\$version=1.0
LOCALHOSTNAME n /tmp/$seq/1.good.log -v -c $tmp.config
EOF2
echo "=== pmie control ===" >>$seq_full
cat $tmp.control >>$seq_full
# real QA test starts here
if ! _service pmie stop >>$seq_full; then _exit 1; fi
_wait_pmie_end || _exit 1
$sudo $signal -a -s TERM pmie 2>/dev/null
$sudo rm -fr /tmp/$seq && mkdir /tmp/$seq || exit 1
$sudo chown -R $PCP_USER:$PCP_GROUP /tmp/$seq
pmstore simple.numfetch 0 >/dev/null
# fire em all up
echo "Starting pmie process"
echo "=== pmie_check ===" >>$seq_full
touch $tmp.log
$sudo chown $PCP_USER:$PCP_GROUP $tmp.log
$sudo -u $PCP_USER -g $PCP_GROUP $PCP_BINADM_DIR/pmie_check -c $tmp.control -VV -l $tmp.log
$sudo cat $tmp.log >>$seq_full
_wait_for /tmp/$seq/1.good.log
ps $PCP_PS_ALL_FLAGS | grep '[p]mie' >>$seq_full
sleep 6 # fill original log a bit
cat /tmp/$seq/1.good.log >>$seq_full
ps $PCP_PS_ALL_FLAGS | grep '[p]mie' >>$seq_full
echo "Rotate, rotate..."
previous=`pmdate -1d %Y%m%d`
echo "=== pmie_daily ===" >>$seq_full
$sudo -u $PCP_USER -g $PCP_GROUP $PCP_BINADM_DIR/pmie_daily -c $tmp.control -VV -l $tmp.log
$sudo cat $tmp.log >>$seq_full
_wait_for /tmp/$seq/1.good.log
ps $PCP_PS_ALL_FLAGS | grep '[p]mie' >>$seq_full
sleep 3 # fill rotated log a bit
echo "Shutdown pmie process"
echo "=== pmie_check ===" >>$seq_full
$sudo -u $PCP_USER -g $PCP_GROUP $PCP_BINADM_DIR/pmie_check -c $tmp.control -s -VV -l $tmp.log
$sudo cat $tmp.log >>$seq_full
ps $PCP_PS_ALL_FLAGS | grep '[p]mie' >>$seq_full
ls -l /tmp/$seq >>$seq_full
grep rotated /tmp/$seq/1.good.log >/dev/null \
|| echo "First log not rotated?"
grep started /tmp/$seq/1.good.log.$previous >/dev/null \
|| echo "Previous log not started?"
# look for data in each log file, checking rotation actually did something
oldlines=`wc -l < /tmp/$seq/1.good.log.$previous 2>/dev/null || echo 0`
newlines=`wc -l < /tmp/$seq/1.good.log 2>/dev/null || echo 0`
# 5 samples / sec x ~6 sec x 2 lines per sample + 6 lines for header and footer
# so 66
_within_tolerance "Old logfile line count" "$oldlines" 66 %75 -v
# 5 samples / sec x ~3 sec x 2 lines per sample + 6 lines for header and footer
# so 36
_within_tolerance "New logfile line count" "$newlines" 36 %75 -v
echo "=== previous log ($oldlines lines) ===" >>$seq_full
cat /tmp/$seq/1.good.log.$previous >>$seq_full
echo "=== current log ($newlines lines) ===" >>$seq_full
cat /tmp/$seq/1.good.log >>$seq_full
# success, all done
status=0
exit
|