Linux Shell 指令碼監控 WAS (WebSphere Application Server) 的運行狀態

來源:互聯網
上載者:User

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

 
  1. #!/bin/ksh
  2. WAS_IP="192.168.222.3"
  3. WAS_USERNAME="wasadmin"
  4. WAS_PASSWORD="wasadmin"
  5. WAS_INSTANCE_NAME="SampleServer1"
  6. WSADMIN="/opt/IBM/WebSphere/AppServer/bin/wsadmin.sh"
  7. FILE_STAT_LOG=was_stat_`date +"%Y%m%d_%H%M%S"`.log
  8. $WSADMIN -lang jython -host $WAS_IP -user $WAS_USERNAME -password $WAS_PASSWORD -f check_was_state.py > $FILE_STAT_LOG 2>&1

  9. grep "${WAS_INSTANCE_NAME}: STARTED" $FILE_STAT_LOG > /dev/null 2>&1
  10. if [ $? == 0 ]; then
  11. echo "$WAS_IP $WAS_INSTANCE_NAME status is OK"
  12. else
  13. echo "$WAS_IP $WAS_INSTANCE_NAME status is not OK"
  14. fi

check_was_state.py

 
  1. import AdminUtilities

  2. # List servers with specified server type
  3. servers = AdminTask.listServers('-serverType APPLICATION_SERVER')

  4. # Convert Jython string to list
  5. servers = AdminUtilities.convertToList(servers)

  6. # Loop through each server in server list
  7. for aServer in servers:
  8. # Obtain server and node names
  9. sname = aServer[0:aServer.find("(")]
  10. nname = aServer[aServer.find("nodes/")+6:aServer.find("servers/")-1]
  11. runningServer = AdminControl.queryNames("type=Server,node=" + nname + ",name=" + sname + ",*")
  12. if (len(runningServer) > 0):
  13. serverState = AdminControl.getAttribute(runningServer, "state")
  14. else:
  15. serverState = "STOPPED"
  16. # endIf
  17. # Two different states: STARTED, STOPPED
  18. print "%s: %s" % (sname,serverState)
  19. #endFor


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.