服务监控程序开发实例.doc_第1页
服务监控程序开发实例.doc_第2页
服务监控程序开发实例.doc_第3页
服务监控程序开发实例.doc_第4页
服务监控程序开发实例.doc_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Weblogic 集群服务监控程序开发详解由于网络上的关于weblogic监控配置和开发的文档不多,而且大多都不详细。所以没有办法使用了另类的办法解决服务无法响应的问题。思路:在已知端口的weblogic服务实例上发布一个简单的web应用,然后通过http连接验证连接是否超时或者连接失败,由此来判断服务节点是否能够响应服务。类开发/WeblogicListenerCluster类开发,该类负责监控服务并执行处理脚本。package com.bjxj.listener;import java.io.IOException;import java.io.InputStream;import .HttpURLConnection;import .URL;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Properties;import java.util.Timer;public class WeblogicListenerCluster extends java.util.TimerTaskprivate Timer timer = null;private static int failcount = 0;private int clusterNodeActiveCount = 0;public static void main(String args) try writeLog(侦听服务正常启动,正在侦听服务 + getValue(description) + ,当前时间: + getCurTime();new WeblogicListenerCluster().response(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();public void response() throws IOException timer = new Timer();int time = Integer.parseInt(getValue(listentime); timer.schedule(this, 50L, time*1000);private static Properties getProperties()Properties p = null;tryInputStream in = WeblogicListenerCluster.class.getResourceAsStream(perties);p = new Properties();p.load(in);catch(IOException e)writeLog(无法读取配置文件,当前时间: + getCurTime();return p;public void run() String ServerMod = getValue(ServerMod);if(failcount = Integer.parseInt(getValue(failcount)if(ServerMod.equalsIgnoreCase(GENERAL)listenerAdminServer();else if(ServerMod.equalsIgnoreCase(CLUSTER)listenerCluster(); private void listenerAdminServer() if(listenerServer(AdminServer)excuteCmd(AdminServer);private void listenerCluster() if(listenerServer(AdminServer)excuteCmd(AdminServer);else if(listenerServer(ProxyServer)excuteCmd(ProxyServer);elseString ClusterServer = getValue(ClusterServer);String node = ClusterServer.split(,);if(getValue(CmdMod).equals(GENERAL)for(int i = 0; i node.length; i+)if(listenerServer(nodei)excuteCmd(nodei);elseboolean flag = false;for(int i = 0; i node.length; i+)if(listenerServer(nodei)clusterNodeActiveCount+;if(clusterNodeActiveCount=node.length)clusterNodeActiveCount = 0;flag = true;if(flag)excuteCmd(ClusterServer);private boolean listenerServer(String servername) try getResponseCod(getValue(servername); return false; catch (IOException e) writeLog(无法连接服务器 + servername + ,服务已经停止响应,当前时间: + getCurTime();return true;private void excuteCmd(String servername)tryint excutetime = Integer.parseInt(getValue(excutetime);WaitExecCmd wec = new WaitExecCmd();wec.startCmd(getValue(servername+Cmd),excutetime);writeLog(正在加载批处理脚本重新启动 + servername + 服务,当前时间: + getCurTime(); catch(InterruptedException e)failcount+;writeLog(未能正常加载运行批处理脚本,当前时间: + getCurTime(); catch (IOException e) failcount+;writeLog(未能正常加载运行批处理脚本,当前时间: + getCurTime();public int getResponseCod(String server) throws IOExceptionURL url = new URL(server);HttpURLConnection httpCon = (HttpURLConnection)url.openConnection();httpCon.setRequestMethod(GET);int code = httpCon.getResponseCode();/httpCon.disconnect();return code;public static String getValue(String property)return getProperties().getProperty(property);public static String getCurTime()SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd hh:mm:ss);return sdf.format(Calendar.getInstance().getTime();public static void writeLog(String msg)String logFilePath;try logFilePath = getValue(logfile);System.out.println(msg);WriteLog.createLogFile(logFilePath);WriteLog.writeTxtLog(msg);WriteLog.closeLogFile(); catch (Exception e) System.out.println(日志文件无法打开);/执行脚本的程序package com.bjxj.listener;import java.io.IOException;public class WaitExecCmdpublic void startCmd(String batfile,int excutetime) throws IOException, InterruptedException Runtime rt = Runtime.getRuntime();rt.exec(cmd /k start + batfile);Thread.sleep(excutetime*1000); /书写日志的程序package com.bjxj.listener;import java.io.FileOutputStream;import java.io.PrintStream;public class WriteLog private static PrintStream logWriter;public static void createLogFile(String logFilePath) throws Exception if (logFilePath.equalsIgnoreCase(stdout)logWriter = System.out;else if (logFilePath.equalsIgnoreCase(stderr) logWriter = System.err; else logWriter = new PrintStream(new FileOutputStream(logFilePath, true);public static void closeLogFile() throws Exception if (logWriter = null)return;logWriter.flush();logWriter.close();public static void writeTxtLog(String msg) throws Exception if (logWriter = null) return; else logWriter.println(msg);logWriter.flush();return;配置文件pertiesdescription=AdminServer(8080),ProxyServer(7001),ClusterServer(7004,7005,7006)listentime=60excutetime=90failcount=10ServerMod=CLUSTER#ServerMod=GENERAL#CmdMod=CLUSTERCmdMod=GENERALAdminServer=2:8080/listenerweb/listener.htm#AdminServer=http:/localhost:7001/listener/listener.htmProxyServer=2:7001/listenerweb/listener.htmClusterServer=ClusterNode1,ClusterNode2,ClusterNode3ClusterNode1=2:7004/listenerweb/listener.htmClusterNode2=2:7005/listenerweb/listener.htmClusterNode3=2:7006/listenerweb/listener.htmAdminServerCmd=D:MaximolistenercombjxjlistenerstartWLSCust.batProxyServerCmd=D:MaximolistenercombjxjlistenerstartWLSProxy.batClusterNode1Cmd=D:MaximolistenercombjxjlistenerstartWLSCustNode1.batClusterNode2Cmd=D:MaximolistenercombjxjlistenerstartWLSCustNode2.batClusterNode3Cmd=D:MaximolistenercombjxjlistenerstartWLSCustNode3.bat#ClusterServerCmd=D:MaximolistenercombjxjlistenerstartWLSCust.bat#AdminServerCmd=D:MaximolistenercombjxjlistenerstartWLS.bat#ProxyServerCmd=D:MaximolistenercombjxjlistenerstartWLS.bat#ClusterServerCmd=D:MaximolistenercombjxjlistenerstartWLS.batlogfile=D:Maximolistenerls.log执行的脚本1、启动监控程序脚本cd D:Maximolistenerjava com.bjxj.listener.WeblogicListenerCluster2、重新启动集群服务脚本sc stop beasvc maximoclusterdomain_AdminServersc stop beasvc maximoclusterdomain_ManagedServer_1sc stop beasvc maximoclusterdomain_ManagedServer_2sc stop beasvc maximoclusterdomain_ManagedServer_3sc start beasvc maximoclusterdomain_AdminServerD:cd D:beauser_projectsdomainsmaximoclusterdomaincmd /c stopWebLogic weblogic we

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论