经常看到有人通过检查 PID 或者端口号是否存在来判断 WebLogic 实例是否正常。
其实那种方法是不好的。因为在实际的线上环境里面,WebLogic 实例会因为很多种原因出现异常,比如内存溢出、过载、死锁等,这个时候它的 PID 或端口都没有问题,但实际上它已经无法正常工作了,需要通过重启 WebLogic 实例才能恢复正常。
一个更加靠谱的监控方法是,在脚本里面调用 WebLogic 的命令 weblogic.Admin 来判断实例的状态。希望本文的脚本对大家有所帮助。
操作系统版本:
C:\>systeminfo | findstr /c:"OS Name"
OS Name: Microsoft(R) Windows(R) Server 2003 Enterprise x64 Edition
|
WebLogic 版本:
C:\>java weblogic.version | findstr "WebLogic"
WebLogic Server 10.3.6.0 Tue Nov 15 08:52:36 PST 2011 1441050
|
代码:
点击(此处)折叠或打开
-
@echo off
-
set "CLASSPATH=D:\WebLogic\Middleware\wlserver_10.3\server\lib\weblogic.jar;%CLASSPATH%"
-
set "PATH=D:\WebLogic\Middleware\jrockit_160_29_D1.2.0-10\bin;%PATH%"
-
-
set "URL=10.135.8.188:7001"
-
set "USER_NAME=weblogic"
-
set "PASS_WORD=welcome1"
-
set "DOMAIN_NAME=wl_server"
-
set "SERVER_NAME=examplesServer"
-
set "SERVER_INFO=%DOMAIN_NAME%:%SERVER_NAME%"
-
-
set CMD_WLS_ADMIN=java weblogic.Admin -url %URL% -username %USER_NAME% -password %PASS_WORD% get -pretty -mbean "%DOMAIN_NAME%:Location=%SERVER_NAME%,Name=%SERVER_NAME%,Type=ServerRuntime"
-
set "STATE_FILE=WLS_STATE.log"
-
%CMD_WLS_ADMIN% | more > "%STATE_FILE%" 2>&1
-
-
REM Check WebLogic instance running status
-
findstr /c:"State: RUNNING" "%STATE_FILE%" >nul 2>&1
-
if errorlevel 1 (
-
echo %URL% %DOMAIN_NAME% %SERVER_NAME% running status is not OK
-
) else (
-
echo %URL% %DOMAIN_NAME% %SERVER_NAME% running status is OK
-
)
-
-
REM Check WebLogic instance health status
-
findstr /c:"State:HEALTH_OK" "%STATE_FILE%" >nul 2>&1
-
if errorlevel 1 (
-
echo %URL% %DOMAIN_NAME% %SERVER_NAME% health status is not OK
-
) else (
-
echo %URL% %DOMAIN_NAME% %SERVER_NAME% health status is OK
-
)
-
-
REM Check WebLogic instance open sockets number
-
set "SOCKET_MAX=200"
-
for /f "tokens=2" %%i in ('findstr "OpenSocketsCurrentCount" "%STATE_FILE%"') do (
-
set "SOCKET_NOW=%%i"
-
)
-
if "x%SOCKET_NOW%" equ "x" (
-
echo %URL% %DOMAIN_NAME% %SERVER_NAME% open sockets number is not OK: fail to get
-
) else (
-
if %SOCKET_NOW% gtr %SOCKET_MAX% (
-
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%
-
)
-
)
-
-
pause
阅读(3467) | 评论(0) | 转发(0) |