2012-12-01 20 views
0

我必须编写一个独立的Java应用程序,监视CQ5,部署在Weblogic内部(尤其是内存使用情况)。要使用(以及如何)以编程方式确定应用程序(CQ5)内部Weblogic中部署的MBean

我能够使用下面的类(在文档中找到)在weblogic中连接到域运行时服务器。

现在,我想知道我需要监视内存低点的MBean,所以只要某个阈值被击中,我就可以触发一个事件。

你们能给我一些见解吗?这是一个纯粹的JMX/Java问题,与CQ无关。

我想以编程方式重新创建Jconsole已经做了什么。但我需要编程,因为我需要与外部API进行交流,以防某些阈值被击中。

public class PrintServerState { 
    private static MBeanServerConnection connection; 
    private static JMXConnector connector; 
    private static final ObjectName service; 

    private static final ObjectName bundleWrite; 
    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(); 
    System.out.println("***************** get mbean count ************************* " + connection.getMBeanCount()); 
    Set<ObjectName> mbeans = connection.queryNames(null, null); 

    for (ObjectName mbeanName : mbeans) { 
     System.out.println(mbeanName); 
    } 

    System.out.println("********************** ---- ***********************"); 
} 
/* 
* 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 server 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 static void main(String[] args) throws Exception { 
    String hostname = args[0]; 
    String portString = args[1]; 
    String username = args[2]; 
    String password = args[3]; 
    PrintServerState s = new PrintServerState(); 
    System.out.println("hostname " + hostname); 
    System.out.println("portString " + portString); 
    System.out.println("username " + username); 
    System.out.println("password " + password); 
    initConnection(hostname, portString, username, password); 
    System.out.println("**************************************************"); 
    s.printNameAndState(); 
    connector.close(); 
} 
} 

回答

0

这会帮助 -

domainRuntime() CD( '/ ServerRuntimes /' +的eval( 'managedServerName')+ '/ JVMRuntime /' +的eval( 'managedServerName')) heapFreeCurrentPerOld = STR(cmo.getHeapFreePercent()) heapFreeCurrentValOld = STR(cmo.getHeapFreeCurrent())

相关问题