Linux Shell 指令碼監控 WAS (WebSphere Application Server) 的運行狀態
原理:通過調用 WAS 內建的指令碼 wsadmin.sh 來擷取執行個體的狀態
作業系統版本:
[root]# head -1 /etc/redhat-release Red Hat Enterprise Linux Server release 5.3 (Tikanga)
|
WAS 版本:
[root]# /opt/IBM/WebSphere/AppServer/bin/versionInfo.sh | grep -A 3 "Installed Product" Installed Product -------------------------------------------------------------------------------- Name IBM WebSphere Application Server - ND Version 7.0.0.25
|
代碼:
check_was_state.sh
- #!/bin/ksh
- WAS_IP="192.168.222.3"
- WAS_USERNAME="wasadmin"
- WAS_PASSWORD="wasadmin"
- WAS_INSTANCE_NAME="SampleServer1"
- WSADMIN="/opt/IBM/WebSphere/AppServer/bin/wsadmin.sh"
- FILE_STAT_LOG=was_stat_`date +"%Y%m%d_%H%M%S"`.log
- $WSADMIN -lang jython -host $WAS_IP -user $WAS_USERNAME -password $WAS_PASSWORD -f check_was_state.py > $FILE_STAT_LOG 2>&1
- grep "${WAS_INSTANCE_NAME}: STARTED" $FILE_STAT_LOG > /dev/null 2>&1
- if [ $? == 0 ]; then
- echo "$WAS_IP $WAS_INSTANCE_NAME status is OK"
- else
- echo "$WAS_IP $WAS_INSTANCE_NAME status is not OK"
- fi
check_was_state.py
- import AdminUtilities
- # List servers with specified server type
- servers = AdminTask.listServers('-serverType APPLICATION_SERVER')
- # Convert Jython string to list
- servers = AdminUtilities.convertToList(servers)
- # Loop through each server in server list
- for aServer in servers:
- # Obtain server and node names
- sname = aServer[0:aServer.find("(")]
- nname = aServer[aServer.find("nodes/")+6:aServer.find("servers/")-1]
- runningServer = AdminControl.queryNames("type=Server,node=" + nname + ",name=" + sname + ",*")
- if (len(runningServer) > 0):
- serverState = AdminControl.getAttribute(runningServer, "state")
- else:
- serverState = "STOPPED"
- # endIf
- # Two different states: STARTED, STOPPED
- print "%s: %s" % (sname,serverState)
- #endFor