-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainProcess
67 lines (53 loc) · 1.68 KB
/
mainProcess
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
#/bin/ash
# set -x
echo `date "+%Y-%m-%d %H:%M:%S"` " start agent">/dev/stdout
MAIIL_PRO_DIR=/progs # servce log path
PORT=3903 # port
POLL_LOG_INTERVAL=15s # poll_log_interval
BEFORE_LOG_PAHT=" "
start(){
mtail $LOGPATH -progs $MAIIL_PRO_DIR -port=$PORT -poll_log_interval=$POLL_LOG_INTERVAL -logtostderr &
}
load_log_path(){
# load service log path
LOGPATH=
for file in `ls ${MAIIL_PRO_DIR} | grep ".mtail"`
do
_LOGPATH=`grep log_filepath ${MAIIL_PRO_DIR}/${file} | grep log_filepath| sed s/[[:space:]]//g | awk -F = '{printf(" -logs %s ",$2)}'`
LOGPATH="${LOGPATH} ${_LOGPATH}"
done
echo `date "+%Y-%m-%d %H:%M:%S"` " LOGPATH="$LOGPATH
}
while [ "1" = "1" ]
do
load_log_path
# configuration changes
if [ ${#LOGPATH} -gt 2 ] && [ "${BEFORE_LOG_PAHT}" != "${LOGPATH}" ]
then
echo `date "+%Y-%m-%d %H:%M:%S"` " reload agent config"
pkill mtail
start
BEFORE_LOG_PAHT=${LOGPATH}
sleep 10s
fi
# Check if process is alive when logpath is not empty
pid=$(ps aux | grep mtail | grep -v grep | awk '{print $1}')
if [ "$pid" == "" ] && [ ${#LOGPATH} -ne 0 ]
then
echo `date "+%Y-%m-%d %H:%M:%S"` " restart agent"
start
fi
if [ "$pid" == "" ]
then
echo `date "+%Y-%m-%d %H:%M:%S"` " agent is dead..."
else
echo `date "+%Y-%m-%d %H:%M:%S"` " agent is running..."
fi
# When monitoring is deleted
if [ ${#LOGPATH} -eq 1 ] && [ "${#BEFORE_LOG_PAHT}" -ne 0 ] && [ "$pid" != "" ]
then
echo `date "+%Y-%m-%d %H:%M:%S"` " kill agent "
kill -9 $pid
fi
sleep 1m
done