定期访问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 ========

 

posted @ 2016-03-16 11:17  ericnie  阅读(2548)  评论(0编辑  收藏  举报