定期訪問WebLogic Server返回狀態的腳本


在運維過程中,經常要獲悉WebLogic Server的狀態以便於主動的維護,本文通過weblogic WLST腳本初步設計了一下

腳本大概為2個,一是WLST的py腳本,getStates.py

connect('weblogic','weblogic12','localhost:7001')
serverRuntime()
state('AdminServer')

另一個是linux的sh腳本

#!/bin/bash
. /home/weblogic/Oracle/Middleware/user_projects/domains/base_domain/bin/setDomainEnv.sh
cd /home/weblogic/WLST
while [ true ]; do
/bin/sleep 60
java weblogic.WLST /home/weblogic/WLST/getStates.py > /home/weblogic/WLST/result.log
result=$(grep "RUNNING" /home/weblogic/WLST/result.log | wc -l)

echo "*************** $result"
if [ "$result" = "1" ]; then
echo "Connecting successfully"
else
echo " ======= Connecting fail ========"
fi

done

腳本為沒隔1分鍾去訪問一下weblogic server的AdminServer,獲取狀態信息,並把結果輸入到result.log

在實際的生產環境中,基本可以設置為5分鍾或者10分鍾定期訪問一下

另外需要注意的是,在網絡不是太穩定狀態下,建議修改腳本,5分鍾訪問如果失敗,再等5分鍾再訪問一次,如果還是失敗,就再等5分鍾再訪問一次,如果三次訪問

失敗,觸發后續的操作.

后續操作可以是echo,或者發郵件,或者調用api發短信到手機的模式.

試驗了一下,運行不多久把weblogic server直接給停了,輸出如下:

[weblogic@dockervm WLST]$ sh getStates.sh
*************** 1
Connecting successfully
*************** 1
Connecting successfully
*************** 1
Connecting successfully
*************** 1
Connecting successfully
Problem invoking WLST - Traceback (innermost last):
File "/home/weblogic/WLST/getStates.py", line 1, in ?
File "<iostream>", line 19, in connect
File "<iostream>", line 552, in raiseWLSTException
WLSTException: Error occurred while performing connect : Error getting the initial context. There is no server running at t3://localhost:7001 : t3://localhost:7001: Destination 0:0:0:0:0:0:0:1, 7001 unreachable; nested exception is:
java.net.ConnectException: Connection refused; No available router to destination
Use dumpStack() to view the full stacktrace :

*************** 0
======= Connecting fail ========

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM