您好,登錄后才能下訂單哦!
使用shell腳本怎么實(shí)現(xiàn)服務(wù)器進(jìn)程監(jiān)控?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
程序說(shuō)明:
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)控。
腳本說(shuō)明:
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
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。