通过weblogic 9 mbean监控其应用状态
来源:互联网 发布:vue.js 开发工具 编辑:程序博客网 时间:2024/06/07 03:50
通过weblogic开放的jmx mbean可以对部署其上的应用\jms\datasource。。。很多内容进行查看和管理,下面这个demo只是借鉴了一下weblogic提供的例子作一个简单的测试。如果想通过这个实现监控,可以为这段代码加上定时设置(通过TimerTask或者quartz)。
下面这段代码主要查看应用的状态以及jms相关情况(需要依赖weblogic.jar)。
import java.io.IOException;import java.net.MalformedURLException;import java.util.Hashtable;import javax.management.MBeanServerConnection;import javax.management.MalformedObjectNameException;import javax.management.ObjectName;import javax.management.remote.JMXConnector;import javax.management.remote.JMXConnectorFactory;import javax.management.remote.JMXServiceURL;import javax.naming.Context;public class PrintServerState {private static MBeanServerConnection connection;private static JMXConnector connector;private static final ObjectName service;// Initializing the object name for DomainRuntimeServiceMBean// so it can be used throughout the class.static {try {service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");} catch (MalformedObjectNameException e) {throw new AssertionError(e.getMessage());}}/** Initialize connection to the Domain Runtime MBean Server*/public static void initConnection(String hostname, String portString, String username, String password)throws IOException, MalformedURLException {String protocol = "t3";Integer portInteger = Integer.valueOf(portString);int port = portInteger.intValue();String jndiroot = "/jndi/";String mserver = "weblogic.management.mbeanservers.domainruntime";JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver);Hashtable h = new Hashtable();h.put(Context.SECURITY_PRINCIPAL, username);h.put(Context.SECURITY_CREDENTIALS, password);h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");connector = JMXConnectorFactory.connect(serviceURL, h);connection = connector.getMBeanServerConnection();}/* * Print an array of ServerRuntimeMBeans.* This MBean is the root of the runtime MBean hierarchy, and* each server in the domain hosts its own instance.*/public static ObjectName[] getServerRuntimes() throws Exception {return (ObjectName[]) connection.getAttribute(service, "ServerRuntimes");}/* * Iterate through ServerRuntimeMBeans and get the name and state*/public void printNameAndState() throws Exception {ObjectName[] serverRT = getServerRuntimes();System.out.println("got domain runtimes");int length = (int) serverRT.length;for (int i = 0; i < length; i++) {String name = (String) connection.getAttribute(serverRT[i], "Name");String state = (String) connection.getAttribute(serverRT[i], "Type");System.out.println("Server name: " + name + ". Server state: " + state);}}public void printAppNameAndState() throws Exception {ObjectName[] serverRT = getServerRuntimes();for (int k = 0; k < serverRT.length; k++) {ObjectName[] appRT = (ObjectName[]) connection.getAttribute(serverRT[k], "ApplicationRuntimes");int length = appRT.length;for (int i = 0; i < length; i++) {String appName = (String) connection.getAttribute(appRT[i], "Name");ObjectName[] compRT = (ObjectName[]) connection.getAttribute(appRT[i], "ComponentRuntimes");for (int j = 0; j < compRT.length; j++) {int appState = ((Integer) connection.getAttribute(compRT[j], "DeploymentState")).intValue();String type = (String) connection.getAttribute(compRT[j], "Type");System.out.println(k + "|" + j + "|Server name: " + appName + ". Server type: " + type+ " Server state: " + appState);}}}}public void printJMS() throws Exception {ObjectName[] serverRT = getServerRuntimes();ObjectName JMSRT = (ObjectName) connection.getAttribute(serverRT[0], "JMSRuntime");ObjectName[] JMSServers = (ObjectName[]) connection.getAttribute(JMSRT, "JMSServers");int JMSServer_Length = (int) JMSServers.length;for (int x = 0; x < JMSServer_Length; x++) {String JMSServer_name = (String) connection.getAttribute(JMSServers[x], "Name");ObjectName[] JMSDests = (ObjectName[]) connection.getAttribute(JMSServers[x], "Destinations");int JMSdest_Length = (int) JMSDests.length;for (int y = 0; y < JMSdest_Length; y++) {String queue_name = (String) connection.getAttribute(JMSDests[y], "Name");long pendingmcount = (Long) connection.getAttribute(JMSDests[y], "MessagesPendingCount");long currentcount = (Long) connection.getAttribute(JMSDests[y], "MessagesCurrentCount");System.out.println(y + "|jms server name: " + JMSServer_name + " jms name: " + queue_name+ " pending: " + pendingmcount + " current: " + currentcount);} //for y} //for x}public static void main(String[] args) throws Exception {String hostname = "127.0.0.1";String portString = "8001";String username = "weblogic";String password = "weblogic";PrintServerState s = new PrintServerState();initConnection(hostname, portString, username, password);s.printNameAndState();s.printAppNameAndState();s.printJMS();connector.close();}}
更详细的内容,可以查看weblogic相关文档http://download.oracle.com/docs/cd/E13222_01/wls/docs90/wlsmbeanref/core/index.html
- 通过weblogic 9 mbean监控其应用状态
- 通过MBean server监控weblogic应用
- 通过MBean server监控weblogic应用
- 使用JMX访问WebLogic Server MBean(监控应用服务器系列文章)
- WebLogic配置连接池(通过mbean)
- spring通过annotation注解注册MBean到JMX实现监控java运行状态
- spring通过annotation注解注册MBean到JMX实现监控java运行状态
- spring通过annotation注解注册MBean到JMX实现监控java运行状态
- 关于JMX通过MBean监控JBoss
- weblogic状态监控脚本
- 监控mbean
- 通过JMX监控weblogic服务
- weblogic 理解MBean
- jconsole 远程监控MBean
- druid 采用mbean监控
- 监控应用状态
- 通过JMX监控管理weblogic的运行
- 通过JMX监控管理weblogic的运行
- MySQL常用SQL语句
- 在flex下,切换模块时出现RemoteClass注册失败
- C++builder enum类型
- vsftpd 安装及设置
- Hql substring length
- 通过weblogic 9 mbean监控其应用状态
- visual studio2005网站连接Access2003
- 如何整合在windows下apache和tomcat
- 常用的APT命令参数
- VC用法汇总
- Linux性能测试工具:Oprofile, KFT, Gprof
- 设计模式学习笔记——中介者模式
- 黑马程序员_asp.net页面事件执行顺序
- logistic 函数(logistic function)