start-analysis.sh 3.9 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

12 13 14 15 16
SW_RT_LOG_DIR=${SW_ANALYSIS_HOME}/log
if [ ! -d "$SW_RT_LOG_DIR" ]; then
    mkdir -p $SW_RT_LOG_DIR
fi

Z
zhang.xin 已提交
17 18 19 20
#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 已提交
21 22
fi

Z
zhang.xin 已提交
23 24
# get the previous process id
PID_FILES="${SW_RT_CONF_DIR}/analysis.pid"
Z
zhang.xin 已提交
25

Z
zhang.xin 已提交
26
if [ ! -f "$FILE_PREVIOUS_EXECUTE_TIME" ]; then
Z
zhang.xin 已提交
27 28 29
  touch "$PID_FILES"
fi

Z
zhang.xin 已提交
30 31 32
SW_ANALYSIS_PID=`cat ${PID_FILES}`
# check if the skywalking analysis process is running
if [ "$SW_ANALYSIS_PID" != "" ]; then
A
ascrutae 已提交
33 34 35 36
    #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 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
        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 已提交
52 53
fi

Z
zhang.xin 已提交
54 55 56 57 58 59 60 61
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 已提交
62
            if [ ${THE_DAY} == ${THE_DAY_OF_MONTH} ]; then
Z
zhang.xin 已提交
63 64 65 66 67 68 69 70 71
                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 已提交
72 73 74
    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 已提交
75 76 77 78 79 80 81 82 83 84 85 86
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
87
        START_TIME=`date --date='3 month ago' "+%Y-%m-%d/%H:%M:%S"`
Z
zhang.xin 已提交
88 89 90 91 92 93 94
    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 已提交
95 96 97
#echo $END_TIME

## execute command
Z
zhang.xin 已提交
98
echo "Begin to analysis the buried point data between ${START_TIME} to ${END_TIME}."
A
ascrutae 已提交
99
export HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase classpath`
100
nohup ${HADOOP_HOME}/bin/hadoop jar skywalking-analysis-1.0b.jar -Dskywalking.analysis.mode=${SW_ANALYSIS_MODE} ${START_TIME} ${END_TIME} > ${SW_RT_LOG_DIR}/map-reduce.log 2>&1 &
A
ascrutae 已提交
101 102

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

A
ascrutae 已提交
104 105
echo "current analysis process Id is ${CURRENT_PID}"
echo ${CURRENT_PID} > ${PID_FILES}
Z
zhang.xin 已提交
106 107 108 109 110 111

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