start-analysis.sh 3.8 KB
Newer Older
Z
zhang.xin 已提交
1 2
#!/bin/bash

Z
zhang.xin 已提交
3 4
# check environment variables
SW_ANALYSIS_HOME=${HOME}/skywalking-analysis
Z
zhang.xin 已提交
5 6 7 8 9 10 11

#check hbase home
HBASE_HOME=${HOME}/hbase-1.1.2

#check hadoop home
HADOOP_HOME=${HOME}/hadoop-2.6.0

Z
zhang.xin 已提交
12 13 14 15
#check skywalking runtime config directory is exisit, if not, will create it.
SW_RT_CONF_DIR="${SW_ANALYSIS_HOME}/runtime-conf"
if [ ! -d "$SW_RT_CONF_DIR" ]; then
    mkdir -p $SW_RT_CONF_DIR
Z
zhang.xin 已提交
16 17
fi

Z
zhang.xin 已提交
18 19
# get the previous process id
PID_FILES="${SW_RT_CONF_DIR}/analysis.pid"
Z
zhang.xin 已提交
20

Z
zhang.xin 已提交
21
if [ ! -f "$FILE_PREVIOUS_EXECUTE_TIME" ]; then
Z
zhang.xin 已提交
22 23 24
  touch "$PID_FILES"
fi

Z
zhang.xin 已提交
25 26 27
SW_ANALYSIS_PID=`cat ${PID_FILES}`
# check if the skywalking analysis process is running
if [ "$SW_ANALYSIS_PID" != "" ]; then
A
ascrutae 已提交
28 29 30 31
    #PS_OUT=`ps -ef | grep $SW_ANALYSIS_PID | grep -v 'grep' | grep -v $0`
    #PS_OUT=`ps -ax | awk '{ print $1 }' | grep -e "^${SW_ANALYSIS_PID}$"` | echo ${PS_OUT}
    PS_OUT=`ps -ax | awk '{print $1}' | grep -e "^${SW_ANALYSIS_PID}$"`
    if [ "$PS_OUT" != "" ]; then
Z
zhang.xin 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
        echo "The skywalking analysis process is running. Will delay the analysis."
        exit -1;
    fi
fi

#skywalking analysis mode:1)accumulate(default) 2)rewrite
SW_ANALYSIS_MODE=ACCUMULATE
#skywalking rewrite execute dates. Each number represents the day of the month.
REWRITE_EXECUTIVE_DAY_ARR=(5,10)

#Get the previous execute time of rewrite mode
PRE_TIME_OF_REWRITE_FILE="${SW_RT_CONF_DIR}/rewrite_pre_time.conf"
if [ ! -f "$PRE_TIME_OF_REWRITE_FILE" ]; then
    echo "skywalking rewrite time file is not exists, create it"
    touch $PRE_TIME_OF_REWRITE_FILE
Z
zhang.xin 已提交
47 48
fi

Z
zhang.xin 已提交
49 50 51 52 53 54 55 56
PRE_TIME_OF_REWRITE_TIME=`cat $PRE_TIME_OF_REWRITE_FILE`
#check if the day is in the date of rewrite mode
if [ "$PRE_TIME_OF_REWRITE_TIME" != "" ]; then
    TODAY=$(date "+%d")
    if [ "$PRE_TIME_OF_REWRITE_TIME" != $TODAY ]; then
        THE_DAY_OF_MONTH=$(date "+%d")
        for THE_DAY in ${REWRITE_EXECUTIVE_DAY_ARR[@]}
        do
A
ascrutae 已提交
57
            if [ ${THE_DAY} == ${THE_DAY_OF_MONTH} ]; then
Z
zhang.xin 已提交
58 59 60 61 62 63 64 65 66
                SW_ANALYSIS_MODE=REWRITE
                START_TIME=$(date --date='1 month ago' '+%Y-%m-01/00:00:00')
                echo "skywalking analysis will execute rewrite mode. Start time:${START_TIME}"
                break
            fi
        done
    else
        echo "${TODAY} has been execute rewrite analysis process.Will not execute rewrite mode!!"
    fi
Z
zhang.xin 已提交
67 68 69
    else
    echo "The previous time of rewrite execute is Null, will put today to the ${PRE_TIME_OF_REWRITE_FILE} file."
    echo $(date "+%d") > ${PRE_TIME_OF_REWRITE_FILE}
Z
zhang.xin 已提交
70 71 72 73 74 75 76 77 78 79 80 81
fi

if [ "${SW_ANALYSIS_MODE}" != "REWRITE" ]; then
    #check the file of previous executive accumulate mode time
    PRE_TIME_OF_ACCUMULATE_FILE="${SW_RT_CONF_DIR}/accumulate_pre_time.conf"
    if [ ! -f "${PRE_TIME_OF_ACCUMULATE_FILE}" ]; then
        echo "skywalking accumulate time file is not exists, create it."
        touch $PRE_TIME_OF_ACCUMULATE_FILE
    fi

    START_TIME=`cat ${PRE_TIME_OF_ACCUMULATE_FILE}`
    if [ "$START_TIME" = "" ]; then
A
ascrutae 已提交
82
        START_TIME=`date --date='1 month ago' "+%Y-%m-%d/%H:%M:%S"`
Z
zhang.xin 已提交
83 84 85 86 87 88 89
    fi
    SW_ANALYSIS_MODE=ACCUMULATE
    echo "skywalking analysis process will execute accumulate mode. start time: ${START_TIME}."
fi

#Get the current datetime
END_TIME=`date --date='10 minute ago' "+%Y-%m-%d/%H:%M:%S"`
Z
zhang.xin 已提交
90 91 92
#echo $END_TIME

## execute command
Z
zhang.xin 已提交
93
echo "Begin to analysis the buried point data between ${START_TIME} to ${END_TIME}."
A
ascrutae 已提交
94 95 96 97
export HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase classpath`
nohup ${HADOOP_HOME}/bin/hadoop jar skywalking-analysis-1.0-SNAPSHOT.jar -Dskywalking.analysis.mode=${SW_ANALYSIS_MODE} ${START_TIME} ${END_TIME} > ${SW_ANALYSIS_HOME}/log/map-reduce.log 2>&1 &

CURRENT_PID=`echo $!`
Z
zhang.xin 已提交
98

A
ascrutae 已提交
99 100
echo "current analysis process Id is ${CURRENT_PID}"
echo ${CURRENT_PID} > ${PID_FILES}
Z
zhang.xin 已提交
101 102 103 104 105 106

if [ "${SW_ANALYSIS_MODE}" = "REWRITE" ]; then
    echo $(date "+%d") > ${PRE_TIME_OF_REWRITE_FILE}
else
    echo $END_TIME > ${PRE_TIME_OF_ACCUMULATE_FILE}
fi