項(xiàng)目是基于java、weblogic及timer的處理模式,每次服務(wù)部署之后timer的整體狀態(tài)是一個(gè)盲區(qū),因?yàn)?00多個(gè)進(jìn)程,是否有啟動(dòng)遺漏或者啟動(dòng)重復(fù)的,想做到一目了然是件困難的事情。所以我考慮用shell腳本的文件查找與匹配方法來(lái)解決這個(gè)問(wèn)題,簡(jiǎn)單記錄下,僅供參考。
1)通過(guò)將系統(tǒng)定義的進(jìn)程(timer)配置到配置文件process_signal.config中
2)將服務(wù)器當(dāng)前所有的java進(jìn)程存儲(chǔ)到process_current.txt中
3)逐行讀取process_signal.config中的進(jìn)程,到process_current.txt中進(jìn)行匹配
4)沒(méi)有匹配到則為啟動(dòng)遺漏,存入到process_invalid.txt中,匹配到1次正常(不做處理),匹配到大于1次,則將timer名稱及啟動(dòng)次數(shù)記錄到process_invalid.txt中。
5)通過(guò)定時(shí)器30分鐘一次執(zhí)行腳本,使用SQLLOAD將process_invalid.txt加載到數(shù)據(jù)表中,對(duì)數(shù)據(jù)庫(kù)表進(jìn)行監(jiān)控。
1、整體文件結(jié)構(gòu):
webusr@iomtimer1:/weblogic/script/process_signal >ls
process_current.txt process_invalid.txt process_invalid_his.txt process_signal.config process_signal.sh
2、進(jìn)程配置示例:
webusr@iomtimer1:/weblogic/script/process_signal >cat process_signal.config
#停復(fù)發(fā)NAS
extapp.tftonas.PutTfToNas 10 2
extapp.tftonas.PutTfToNas 11 2
extapp.tftonas.PutTfToNas 12 3
3、執(zhí)行結(jié)果記錄:
webusr@iomtimer1:/weblogic/script/process_signal >cat process_invalid.txt
127.0.0.1 process [extapp.leaseroute.PutToLeaseRoute 180] is not exist 2018-04-11 08:29:00
127.0.0.1 process [ DealWorkTaskTimer 3001 ] is repeatRun 2 Times 2018-04-11 17:51:56
4、邏輯匹配入口:
webusr@iomtimer1:/weblogic/script/process_signal >cat process_signal.sh
#!/bin/sh
path=/weblogic/script/process_signal #腳本路徑
file_config=process_signal.config #配置文件名
file_result=process_invalid.txt #錯(cuò)誤進(jìn)程信息
file_tmp=process_current.txt #當(dāng)前進(jìn)程信息(全量,臨時(shí))
if_get_exist="N" #是否輸出日志(N不輸出,Y輸出)
hostip="127.0.0.1" #主機(jī)IP
currenttime=`date "+%Y-%m-%d %H:%M:%S"` #當(dāng)前系統(tǒng)時(shí)間
#定義方法get_process_signal()
get_process_signal(){
# 轉(zhuǎn)儲(chǔ)上次記錄到歷時(shí),追加
cat /weblogic/script/process_signal/process_invalid.txt >> process_invalid_his.txt
#清空錯(cuò)誤進(jìn)程信息,當(dāng)前進(jìn)程信息
>/weblogic/script/process_signal/process_invalid.txt
>/weblogic/script/process_signal/process_current.txt
#輸出當(dāng)前時(shí)間并獲取主機(jī)上所有java類進(jìn)程
echo "######################### get ps info time is: " $currenttime " #########################">>/weblogic/script/process_signal/process_current.txt
ps -ef|grep java >>/weblogic/script/process_signal/process_current.txt
echo "######################### get ps info time is: " $currenttime " #########################">>/weblogic/script/process_signal/process_current.txt
#逐條讀取配置文件process_signal.config
cat /weblogic/script/process_signal/process_signal.config | while read LINE
do
# 如果配置文件含有#號(hào),則跳過(guò)不處理
if [[ `echo $LINE|cut -c1-1` != "#" ]]; then
#如果配置文件記錄在主機(jī)進(jìn)程中存在
if [[ -n `find $path -name $file_tmp | xargs grep -w "$LINE"` ]]; then
#開(kāi)關(guān)為Y,輸出到屏幕
if [[ $if_get_exist = "Y" ]]; then
echo $hostip " process [" $LINE "] is exist " $currenttime >>/weblogic/script/process_signal/process_invalid.txt
fi
#配置文件記錄與主機(jī)進(jìn)程匹配
run=`find $path -name $file_tmp | xargs grep -w "$LINE"|wc -l`
if (($run>1)); then
#打印配置文件中記錄與主機(jī)進(jìn)程匹配數(shù)大于1的記錄
echo $hostip " process [" $LINE "] is repeatRun "$run " Times" $currenttime >>/weblogic/script/process_signal/process_invalid.txt
fi
#如果配置文件記錄在主機(jī)進(jìn)程中不存在
else
echo $hostip " process ["$LINE"] is not exist " $currenttime >>/weblogic/script/process_signal/process_invalid.txt
fi
fi
done
}
#調(diào)用方法
get_process_signal
#fhs.workflow.EventMonitorMain 4
#find /weblogic/script/process_signal -name process_current.txt | xargs grep -i "fhs.workflow.EventMonitorMain 4"
#ps -ef|grep java|grep "fhs.workflow.EventMonitorMain 4"
5、SqlLOAD入庫(kù)(含控制文件conl.ctl)
efile92@iomitfdb2:/interface/contabfile/monitor_time >cat conl.ctl
load data
infile '/interface/contabfile/monitor_time/process_invalid.txt'
truncate into table T_MONITOR_TIMER
fields terminated by '\n'
-- Create table
create table T_MONITOR_TIMER
(
info VARCHAR2(1000)
)
sqlldr userid=用戶名/密碼@sid control=/interface/contabfile/monitor_time/conl.ctl log=/interface/contabfile/monitor_time/conl.log
總結(jié)
以上所述是小編給大家介紹的shell腳本實(shí)現(xiàn)服務(wù)器進(jìn)程監(jiān)控的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
您可能感興趣的文章:- 用shell腳本監(jiān)控進(jìn)程是否存在 不存在則啟動(dòng)的實(shí)例
- SHELL腳本監(jiān)控JAVA進(jìn)程的代碼
- Shell腳本實(shí)現(xiàn)Linux系統(tǒng)和進(jìn)程資源監(jiān)控
- linux進(jìn)程監(jiān)控shell腳本代碼
- Shell腳本實(shí)現(xiàn)監(jiān)控swap空間使用情況和查看占用swap的進(jìn)程
- Shell腳本實(shí)現(xiàn)的memcached進(jìn)程監(jiān)控
- shell監(jiān)控linux系統(tǒng)進(jìn)程創(chuàng)建腳本分享