经常看到有人通过检查 PID 或者端口号是否存在来判断 WebLogic 实例是否正常。
其实那种方法是不好的。因为在实际的线上环境里面,WebLogic 实例会因为很多种原因出现异常,比如内存溢出、过载、死锁等,这个时候它的 PID 或端口都没有问题,但实际上它已经无法正常工作了,需要通过重启 WebLogic 实例才能恢复正常。
一个更加靠谱的监控方法是,在脚本里面调用 WebLogic 的命令 weblogic.Admin 来判断实例的状态。希望本文的脚本对大家有所帮助。
操作系统版本:
[root@WLS1 /]# head -1 /etc/redhat-release
Red Hat Enterprise Linux Server release 5.3 (Tikanga)
|
WebLogic 版本:
[root@WLS1 /]# java weblogic.version | grep -m 1 "."
WebLogic Server 10.3.6.0 Tue Nov 15 08:52:36 PST 2011 1441050
|
代码:
-
#!/bin/bash
-
CLASSPATH="/opt/Oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar:$CLASSPATH"
-
PATH="/usr/java/jdk1.6.0_45/bin:$PATH"
-
-
URL="192.168.222.11:7020"
-
USER_NAME="weblogic"
-
PASS_WORD="weblogic1"
-
DOMAIN_NAME="MedRecDomain"
-
SERVER_NAME="MedRecAdmSvr"
-
-
STATE_ALL=$(java weblogic.Admin -url $URL -username $USER_NAME -password $PASS_WORD get -pretty -mbean "$DOMAIN_NAME:Location=$SERVER_NAME,Name=$SERVER_NAME,Type=ServerRuntime")
-
-
# Check WebLogic instance running status
-
echo "$STATE_ALL" | grep -q "State: RUNNING"
-
if [ $? == 0 ]; then
-
echo "$URL $DOMAIN_NAME $SERVER_NAME running status is OK"
-
else
-
echo "$URL $DOMAIN_NAME $SERVER_NAME running status is not OK"
-
fi
-
-
# Check WebLogic instance health status
-
echo "$STATE_ALL" | grep -q "State:HEALTH_OK"
-
if [ $? == 0 ]; then
-
echo "$URL $DOMAIN_NAME $SERVER_NAME health status is OK"
-
else
-
echo "$URL $DOMAIN_NAME $SERVER_NAME health status is not OK"
-
fi
-
-
# Check WebLogic instance open sockets number
-
SOCKET_MAX=200
-
SOCKET_NOW=$(echo "$STATE_ALL" | awk '/OpenSocketsCurrentCount/{print $2}')
-
if [ x$SOCKET_NOW == x ]; then
-
echo "$URL $DOMAIN_NAME $SERVER_NAME open sockets number is not OK: fail to get"
-
else
-
if [ $SOCKET_NOW -gt $SOCKET_MAX ]; then
-
echo "$URL $DOMAIN_NAME $SERVER_NAME health status is not OK: $SOCKET_NOW greater than $SOCKET_MAX"
-
else
-
echo "$URL $DOMAIN_NAME $SERVER_NAME health status is OK: $SOCKET_NOW not greater than $SOCKET_MAX"
-
fi
-
fi
阅读(11590) | 评论(0) | 转发(3) |