상세 컨텐츠

본문 제목

How to JMS queue in Weblogic using Mbean. Mbean 이용한 Weblogic queue 모니터링

Oracle/Weblogic

by 야솔아빠 2013. 10. 20. 23:28

본문

반응형

How to JMS queue in Weblogic using JMX(Mbean).


아래 자료를 읽은 후에, 접근해야 Mbean 을 이해할 수 있다.

http://docs.oracle.com/cd/E14571_01/apirefs.1111/e13951/core/index.html


Mbean Root "ServerRuntimes" 이후부터, 찾고자 하는

Related MBeans

를 찾아서 한단계씩 내려가다가 마지막 destination 에서 attribute를 찾아서 출력하면 된다.


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;


import weblogic.management.runtime.JMSRuntimeMBean;

import weblogic.management.runtime.JMSServerRuntimeMBean;

import weblogic.management.runtime.ServerRuntimeMBean;

import weblogic.management.runtime.ServletRuntimeMBean;


public class QueueMonitor {


   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 printOnlineQueue() throws Exception {

      ObjectName[] serverRT = getServerRuntimes();

      System.out.println("got server runtimes");

      int length = (int) serverRT.length;

      ObjectName jmsRuntime = null;

      ObjectName[] jmsServer = null;

      ObjectName[] destinations = null;

      String name = null;

      

      for (int i = 0; i < length; i++) {

         name = (String) connection.getAttribute(serverRT[i],

            "Name");

         String state = (String) connection.getAttribute(serverRT[i],

            "State");

        

        if(name.startsWith("soapip")) {

//          System.out.println(serverRT[i].getCanonicalName());

//          System.out.println(serverRT[i].getKeyPropertyListString());

          

          jmsRuntime = (ObjectName)connection.getAttribute(serverRT[i], "JMSRuntime");

          

//          System.out.println("jmsRuntime : " + jmsRuntime);

          

          jmsServer = (ObjectName[])connection.getAttribute(jmsRuntime, "JMSServers");

          

          for(ObjectName obj : jmsServer) {

            name = null;

            name = (String) connection.getAttribute(obj, "Name");

            if(name != null && name.startsWith("PIPJMSServer")) {

              destinations = (ObjectName[])connection.getAttribute(obj, "Destinations");

              

              for(ObjectName dest : destinations) {

//                System.out.println("dest : " + dest);

                name = (String) connection.getAttribute(dest, "Name");

                if(name != null && name.indexOf("_QUEUE") > 0) {                  

                  System.out.println(name + "] MessagesCurrentCount : " + connection.getAttribute(dest, "MessagesCurrentCount") + ",   MessagesPendingCount : " + connection.getAttribute(dest, "MessagesPendingCount"));

                                     

                }

              }

            }

//            System.out.println(obj);

          }

          

          

//          JMSServerRuntimeMBean jmsBean =  (JMSServerRuntimeMBean) connection.getAttribute(serverRT[i], "JMSServerRuntimeMBean");

//          System.out.println(serverRuntimeBean);

        }

        

//         System.out.println("Server name: " + name + ".   Server state: "

//            + state);

//         System.out.println(serverRT[i]);

      }

   }

   


   


   public static void main(String[] args) throws Exception {

     String[] hostname = {"xxx", "xxx1", "xxx2"};

     String[] portString = {"6001", "6001", "7001"}; 

      String username = "weblogic";

      String password = "welcome1";


      QueueMonitor s = null;

      

      for(int i=0; i<3; i++)  {

        s = new QueueMonitor();

        System.out.println("========================================================");

        System.out.println("domain IP : " + hostname[i]);

        initConnection(hostname[i], portString[i], username, password);

        s.printOnlineQueue();

        connector.close();

      }


      

   }

}


* 이 포스팅을 사용하실 때는 꼭 출처를 밝혀주시기를 바랍니다..

반응형

관련글 더보기

댓글 영역