中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

自動(dòng)監(jiān)控url是否可用,如不可用則重啟應(yīng)用,并做相應(yīng)的報(bào)警策略

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線(xiàn)!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
#!/bin/bash 
#author: QingFeng
#qq: 530035210
#blog: http://my.oschina.net/pwd/blog 
#自動(dòng)監(jiān)控url是否可用,如不可用則重啟應(yīng)用,并做相應(yīng)的報(bào)警策略。
#缺省的配置如下
  
logdir=/data/log/check          #日志路徑
log=$logdir/log.log            #日志文件 
is_font=1                #終端是否打印日志: 1打印 0不打印 
is_log=0                 #是否記錄日志: 1記錄 0不記錄
key="data-camp"  #進(jìn)程關(guān)鍵字
exec_stop="/etc/init.d/data-camp  stop"  #停應(yīng)用命令
exec_start="/etc/init.d/data-camp  start" #啟動(dòng)應(yīng)用命令
  
datef(){
date "+%Y-%m-%d %H:%M:%S"
}
  
print_log(){
if [[ $is_log -eq 1  ]];then
[[ -d $logdir ]] || mkdir -p $logdir
echo "[ $(datef) ] $1" >> $log
fi
if [[ $is_font -eq 1  ]];then
echo -e "[ $(datef) ] $1"
fi
}
 
#定義重啟
derestart(){
 
if [[  $1 == "" ]];then
print_log "$FUNCNAME():應(yīng)用關(guān)鍵字不能為空"
exit
fi
 
if [[  $2 == "" ]];then
print_log "$FUNCNAME():啟動(dòng)文件不能為空"
exit
fi
 
 
if [[  $2 == "" ]];then
print_log "$FUNCNAME():啟動(dòng)參數(shù)口不能為空"
exit
fi
 
ppid=0
ppid=$(ps axu |grep "$1" |grep -v grep |grep -v "$0" |wc -l)
$2 $3 
ppid=$(ps axu |grep "$1" |grep -v grep |grep -v "$0" |wc -l)
echo $ppid > /tmp/restart.num
print_log "$FUNCNAME(): $1的進(jìn)程數(shù)為:$ppid"
 
}
 
#場(chǎng)景一: 當(dāng)網(wǎng)站返回碼不為200,則重啟應(yīng)用.
 
check_code(){
if [[  $1 == "" ]];then
print_log "$FUNCNAME():服務(wù)器地址不能為空"
exit
fi
 
if [[  $2 == "" ]];then
print_log "$FUNCNAME():服務(wù)器端口不能為空"
exit
fi
 
print_log "$FUNCNAME():開(kāi)始檢測(cè)-[$1:$2]服務(wù)器的網(wǎng)站狀態(tài)返回碼."
code=$(curl -m 8 -o /dev/null -s -w  %{http_code} http://$1:$2/verdict/session/LSGJA52U7CH055974/latest/result)
 
if [[  $code -ne 200    ]];then
print_log "$FUNCNAME():[$1:$2]服務(wù)器的網(wǎng)站狀態(tài)返回碼不正常,開(kāi)始重啟應(yīng)用--$code."
print_log "$FUNCNAME():執(zhí)行命令: $exec_stop"
derestart  "$key"  "$exec_stop"
num2=$(cat /tmp/restart.num)
if [[ $num2 -ne 0   ]];then
print_log "$FUNCNAME():停應(yīng)用失敗."
fi 
print_log "$FUNCNAME():執(zhí)行命令: $exec_start"
sleep 3
derestart  "$key"  "$exec_start"
num2=$(cat /tmp/restart.num)
if [[ $num2 -eq 0   ]];then
print_log "$FUNCNAME():啟動(dòng)應(yīng)用失敗."
fi
 
print_log "$FUNCNAME():重啟應(yīng)用成功."
else
print_log "$FUNCNAME():[$1:$2]服務(wù)器的網(wǎng)站狀態(tài)返回碼正常--$code."
fi 
}
 
#場(chǎng)景二: 檢測(cè)網(wǎng)站http返回的時(shí)間
 
check_timeout(){
if [[  $1 == "" ]];then
print_log "$FUNCNAME():服務(wù)器地址不能為空"
exit
fi
 
if [[  $2 == "" ]];then
print_log "$FUNCNAME():服務(wù)器端口不能為空"
exit
fi
 
print_log "$FUNCNAME():開(kāi)始檢測(cè)-[$1:$2]服務(wù)器的網(wǎng)站超時(shí)時(shí)間."
httptime=`curl  -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer:%{time_starttransfer}\ntime_total: %{time_total}\n" "http://$1:$2/verdict/session/LSGJA52U7CH055974/latest/result" |grep time_total|awk -F ":" '{print $2*1000}'`
 
taketime=$(expr $httptime / 1000)
 
if [[  $httptime -gt 60000    ]];then
print_log "$FUNCNAME():[$1:$2]服務(wù)器的網(wǎng)站響應(yīng)時(shí)間不正常,開(kāi)始重啟應(yīng)用--$httptime ms."
print_log "$FUNCNAME():執(zhí)行命令: $exec_stop"
derestart  "$key"  "$exec_stop"
num2=$(cat /tmp/restart.num)
if [[ $num2 -ne 0   ]];then
print_log "$FUNCNAME():停應(yīng)用失敗."
fi
print_log "$FUNCNAME():執(zhí)行命令: $exec_start"
sleep 3
derestart  "$key"  "$exec_start"
num2=$(cat /tmp/restart.num)
if [[ $num2 -eq 0   ]];then
print_log "$FUNCNAME():啟動(dòng)應(yīng)用失敗."
fi
 
print_log "$FUNCNAME():重啟應(yīng)用成功."
else
print_log "$FUNCNAME():[$1:$2]服務(wù)器的網(wǎng)站響應(yīng)時(shí)間正常--$httptime ms/$taketime s."
fi
}
 
check_code "localhost" "6500"
check_timeout "localhost" "6500"

標(biāo)簽: 服務(wù)器 服務(wù)器地址 服務(wù)器端

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:Android分頁(yè)查詢(xún)獲取系統(tǒng)聯(lián)系人信息

下一篇:servlet實(shí)現(xiàn)文件上傳數(shù)據(jù)增刪該查