- 论坛徽章:
- 0
|
贴出来
#!/bin/bash
export PATH="/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin:/usr/bin/X11:/usr/local/app/wsl_bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/usr/local/Ice/bin:"
. /usr/local/app/binary/monitor/functions
RUNNING_FILE="/usr/local/app/binary/monitor/.mt_log_cron_run"
PROC_NAME=`basename $0`
if [ -f ${RUNNING_FILE} ] ; then
echo "${PROC_NAME} is running ... EXIT 99" 1>&2
exit 99
fi
touch ${RUNNING_FILE}
HISTORY="1" #采集历史数据标志
SERV_CODE="" #监控系统服务代码
APPLICATION="" #应用名(同ICE编程命名规范)
SERVER="" #服务名(同ICE编程命名规范)
LOG_TYPE="" #日志类型(比如说是errro 或者up 或者down 等日志类文件)
FLOW_KEY="" #流量关键字
BASE_DIR="/data/log_server/log/day"
TIME_INTERVAL=5
SQL="select mt_log_serv_code from db_monitor.t_mt_log_config where is_valid = 'Y';"
SERV_CODE_LIST=`mysql -uroot -h172.18.16.74 -s -e "${SQL}"`
echo "$SERV_CODE_LIST" | while read SERV_CODE ; do
SQL="SELECT CONCAT_WS(':', mt_log_serv_code, application, server, log_type, flow_key) FROM db_monitor.t_mt_log_config WHERE mt_log_serv_code = '${SERV_CODE}';"
CONFIG_STR=`mysql -uroot -h172.18.16.74 -s -e "${SQL}"`
#echo ${CONFIG_STR}
#IFS=: CONFIG_ARRAY=($CONFIG_STR)
#IFS=
#echo ${CONFIG_ARRAY[0]}
#echo ${CONFIG_ARRAY[1]}
IFS=: read SERV_CODE APPLICATION SERVER LOG_TYPE FLOW_KEY <<<"$CONFIG_STR"
if [ ! -d "${BASE_DIR}/${APPLICATION}/${SERVER}" ] ; then
echo "${BASE_DIR}/${APPLICATION}/${SERVER} is not exist... EXIT 98" 1>&2
rm ${RUNNING_FILE}
exit 98
fi
cd ${BASE_DIR}/${APPLICATION}/${SERVER}
while [ 1 ] ; do
SQL="SELECT curr_date, curr_time FROM db_monitor.t_time_ctl WHERE serv_code = '${SERV_CODE}';"
DATE_STR=`mysql -uroot -h172.18.16.74 -s -e "${SQL}"`
read CURR_DATE CURR_TIME <<< "$DATE_STR"
DATE_FORMAT=`echo $CURR_DATE | tr -d "-"`
BEGIN_TIME=${CURR_TIME}
END_DATE_TIME=`date -d "$CURR_DATE $CURR_TIME $TIME_INTERVAL minutes" +"%Y-%m-%d %H:%M:%S"`
read END_DATE END_TIME <<< "${END_DATE_TIME}"
END_DATE_TIME_FORMAT=`echo $END_DATE_TIME | tr -d ":\ -"`
DATE_NOW=`date +"%Y%m%d%H%M%S"`
if [ -n "${LOG_TYPE}" ] ; then
LOG_FILE=${APPLICATION}"."${SERVER}"_"${LOG_TYPE}"_"${DATE_FORMAT}.log
else
LOG_FILE=${APPLICATION}"."${SERVER}"_"${DATE_FORMAT}.log
fi
GZ_LOG_FILE="${LOG_FILE}.gz"
if [ ! -f ${LOG_FILE} ] && [ ! -f ${GZ_LOG_FILE} ] ; then
echo "[${DATE_NOW}] ${SERV_CODE} ${LOG_FILE} && ${GZ_LOG_FILE} \"file is not exist!\"" 1>&2
break
fi
if [ "${END_DATE_TIME_FORMAT}" -ge "${DATE_NOW}" ] ; then
echo "[${DATE_NOW}] ${SERV_CODE} ${END_DATE_TIME_FORMAT} \"end-timestamp is big than now-time!\""
break
fi
if [ -f ${LOG_FILE} ] ; then
FLOW=`get_flow "$LOG_FILE" "" "$BEGIN_TIME" "$END_TIME"`
write_table "$SERV_CODE" "${CURR_DATE}" "${BEGIN_TIME}" "${END_TIME}" "$FLOW"
else
FLOW=`get_gz_flow "$GZ_LOG_FILE" "" "$BEGIN_TIME" "$END_TIME"`
write_table "$SERV_CODE" "${CURR_DATE}" "${BEGIN_TIME}" "${END_TIME}" "$FLOW"
fi
SQL="update db_monitor.t_time_ctl set last_date = '$CURR_DATE', last_time = '$CURR_TIME', curr_date= '$END_DATE', curr_time='$END_TIME', update_time=now() where serv_code = '$SERV_CODE'"
mysql -uroot -h172.18.16.74 -s -e "${SQL}"
#break 对所有历史数据都做循环,所以注释掉break
if [ "${HISTORY}" == "0" ] ; then
break
fi
done
done
rm ${RUNNING_FILE}
exit 0 |
|