티스토리 뷰

④ 미들웨어/ⓙ JEUS

[JEUS6] JMX Guide

GodNR 2018. 7. 23. 11:25
728x90
반응형

 포스팅은 JMX 작성 가이드입니다.



1. 용어

a. JMX(Java Management eXtensions)
엔터프라이즈 모니터링 시스템 개발에 대한 표준적인 방법
응용프로그램을 관리 감시하기 위해 API spec 제공
각종 리소스들은 Mbean(Managed Bean)이라는 객체로 표현된다.

b. Mbean(Managed Bean)

Mbean는 JVM에서 돌아가는 resource(application,JDBC..등등)을 표현한 것이다.

c. ObjectName 

Mbean객체의 기본 JMX객체 이름.
기본적으로 이름 형식 JMX 표준 형식임
밴더마라 JMX구현 및 계층 구조가 다르기 때문에 다른 값을 가질 수 있음.
Mbean의 객체를 질의할때 OjectName을 이용한다.

 

*문법

<domain_name>: j2eeType=<j2eeType_value>, name=<name_value>,
[<parent-j2eeType_value>], [jeusType = <jeusType_value>],
[isTargetable = <isTargetable_value>],
[jeusManager = <jeusManager_value>],
JMXManager = <JMXManager_value> [,*]

예시

JEUS: JMXManager=nrson-PC,

JeusManager=nrson-PC,

isTargetable=true,

j2eeType=J2EEServer,

name=nrson-PC_default

 

2. JMX기본 구조(그림)
Manager Side :
Management level enables remote applications to access the MBeanServer through connectors and adaptors

A connector provides full remote access to the MBeanServer API using various communication frameworks (RMI, IIOP, JMS, WS-* …)
An adaptor adapts the API to another protocol (SNMP, …) or to Web-based GUI (HTML/HTTP, WML/HTTP, …)

AgentSide(MbeanServer) :
The core of JMX
Mbean과 applications(클라이언트)간에 매개자(intermediary) 역할을 한다.


 


 

3. JEUS에서 MeanServer에 접속 방법
위와 그림에서도 나와있듯이 MbeanServer에 접속하기 위해서는 Connector 또는 adaptor을 이용해야 한다.
제우스에서는 connector로는 jmxap connector, rmi connector가 있고 adaptor로는 html, snmp 가 있다.

RMI커넥터
JMXMP 커넥터
- Socket기반
- JEUS에서 기본 커넥터

HTML Adaptor
- html 프로토콜 어댑터
SNMP Adaptor
- snmp 프로토콜 어댑터

 

4. JEUS에서 connector, adaptor설정 방법

<?xml version="1.0" encoding="utf-8"?>
<jeus-system xmlns="http://www.tmaxsoft.com/xml/ns/jeus">
  <node>
    <!-- ... -->
    <engine-container>
      <!-- ... -->
    </engine-container>
    <!-- JMX Manager configuration for JEUS management/monitoring -->
    <jmx-manager>
      <!-- JMXMP Connector -->
      <jmx-connector>
        <jmxmp-connector>
          <jmxmp-connector-port>5001</jmxmp-connector-port>
        </jmxmp-connector>
      </jmx-connector>
      <!-- HTML Adaptor -->
      <html-adaptor-port>9980</html-adaptor-port>
      <!-- SNMP Adaptor (SNMP Agent) -->
      <snmp-adaptor>
        <snmp-adaptor-port>9999</snmp-adaptor-port>
        <snmp-version>3</snmp-version>
        <snmp-max-packet-size>4096</snmp-max-packet-size>
        <snmp-security>true</snmp-security>
        <pooling>
          <min>5</min>
          <max>20</max>
          <period>5</period>
        </pooling>
      </snmp-adaptor>
    </jmx-manager>
  </node>
</jeus-system> 

 

5. JMX클라이언트 application개발시 일반적인 구조
Meanbean연결 -> 질의 -> 질의결과 처리 및 가공

 

6. Meanbean연결: MeanServer connect 방법

a. JEUS 유틸리티 
String hostname = args[0];
String username = args[1];
String password = args[2];
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "jeus.jndi.JNSContextFactory");
env.put(Context.PROVIDER_URL, hostname);
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);

 

// Step 2. Getting MBeanServer
MBeanServerConnection mbeanServer = jeus.management.RemoteMBeanServerFactory.getMBeanServer(env);

b. JNDI사용

// Step 1. Setting Environments
String hostname = args[0];
String username = args[1];
String password = args[2];
// targetName could be node or container name,
// for example, "johan", "johan_container1"
String targetName = args[3];
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"jeus.jndi.JNSContextFactory");
env.put(Context.PROVIDER_URL, hostname);
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);

// Step 2. Getting MBeanServerConnection
InitialContext ctx = new InitialContext(env);
JMXConnector connector = null;
try{
connector = (JMXConnector)ctx.lookup("mgmt/rmbs/" + targetName);
MBeanServerConnection mbeanServer
= connector.getMBeanServerConnection();

c. JMX Remote API사용(RMI 커넥터 이용)

String hostname = args[0];
String username = args[1];
String password = args[2];
// the JMX RMIConnector export name specified in the JEUSMain.xml
String exportName = args[3];
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "jeus.jndi.JNSContextFactory");
env.put(Context.PROVIDER_URL, hostname);
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);

// Step 2. Getting MBeanServer
JMXServiceURL url
= new JMXServiceURL("service:jmx:rmi:///jndi/" + exportName);
JMXConnector connector = null;
try {
connector = JMXConnectorFactory.newJMXConnector(url,env);
// connect to JMXConnectorServer
connector.connect();
MBeanServerConnection mbeanServer
= connector.getMBeanServerConnection();

==================================================================================

<jmx-manager>
<jmx-connector>
<rmi-connector>
<export-name>RMIConnector</export-name>
</rmi-connector>
</jmx-connector>
</jmx-manager>

=> exportName은 rmi-connecotr의 export-name을 쓴다.

d. MEJBUtility이용

Hashtable env = new Hashtable();
         env.put(Context.INITIAL_CONTEXT_FACTORY, "jeus.jndi.JNSContextFactory");
         env.put(Context.PROVIDER_URL, hostname);
         env.put(Context.SECURITY_PRINCIPAL, username);
         env.put(Context.SECURITY_CREDENTIALS, password);  
 try {
                 InitialContext ic = new InitialContext(env);
         } catch (NamingException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
         }
  mbeanServer=null;
         try {
                 mbeanServer = MEJBUtility.getMEJBUtility(env);
         } catch (JMXManagerException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
         }
 return mbean


7. 질의 : ObjectName

8. Mbean정보 확인

a. jeusadmin 
nrson-PC>beanlistThe command misses the following required argument : module_name

nrson-PC>mbeanlistJEUS:j2eeType=J2EEDomain,JMXManager=nrson-PC,name=JeusSystemJEUS:j2eeType=J2EEServer,JMXManager=nrson-PC,isTargetable=true,JeusManager=nrson-PC,name=nrson-PC_defaultJEUS:j2eeType=JDBCResource,JMXManager=nrson-PC,JeusManager=nrson-PC,J2EEServer=nrson-PC_default,name=nrson-PC_defaultJEUS:j2eeType=JTAResource,JMXManager=nrson-PC,JeusManager=nrson-PC,J2EEServer=nrson-PC_default,name=nrson-PC_defaultJEUS:j2eeType=JVM,JMXManager=nrson-PC,JeusManager=nrson-PC,J2EEServer=nrson-PC_default,name=nrson-PC_defaultJEUS:j2eeType=JVM,JMXManager=nrson-PC,JeusManager=nrson-PC,J2EEServer=null,name=nrson-PCJEUS:j2eeType=JeusService,jeusType=ClassFTPService,JMXManager=nrson-PC,JeusManager=nrson-PC,name=nrson-PCJEUS:j2eeType=JeusService,jeusType=ClusterService,JMXManager=nrson-PC,JeusManager=nrson-PC,name=nrson-PCJEUS:j2eeType=JeusService,jeusType=ContainerManagerService,JMXManager=nrson-PC,JeusManager=nrson-PC,name=nrson-PCJEUS:j2eeType=JeusService,jeusType=ContainerMonitorService,JMXManager=nrson-PC,JeusManager=nrson-PC,name=nrson-PCJEUS:j2eeType=JeusService,jeusType=ContextGroup,JMXManager=nrson-PC,JeusManager=nrson-PC,J2EEServer=nrson-PC_default,
WebEngine=nrson-PC_servlet_engine1,name=MyGroupJEUS:j2eeType=JeusService,jeusType=EJBEngine,JMXManager=nrson-PC,JeusManager=nrson-PC,J2EEServer=nrson-PC_default,name=
nrson-PC_ejb_engine1JEUS:j2eeType=JeusService,jeusType=ExternalResourceService,JMXManager=nrson-PC,JeusManager=nrson-PC,name=nrson-PCJEUS:j2eeType=JeusService,jeusType=JAXRResourceService,JMXManager=nrson-PC,JeusManager=nrson-PC,name=nrson-PCJEUS:j2eeType=JeusService,jeusType=JDBCResourceService,JMXManager=nrson-PC,JeusManager=nrson-PC,name=nrson-PCJEUS:j2eeType=JeusService,jeusType=JEUSMPConnector,JMXManager=nrson-PC,name=nrson-PCJEUS:j2eeType=JeusService,jeusType=JMXExportService,JMXManager=nrson-PC,JeusManager=nrson-PC,J2EEServer=null,name=nrson-PC

b. webadmin에서 Mbean정보 확인



현재 기동되어 있는 JEUS에서의 Mbean정보를 확인할 수 있다.
위의 예는 ContainerManagerService Mbean정보를 본 것이다.
좌측에는 자세한 정보를 볼 수 있는데, 그 중 속성과 작업이 탭이 있다.

속성 : Mbean속성을 Mbean에 대한 속성을 확인 하는 것이다.
작업 : Mbean에 맵핑되어 있는 Resource에 대한 특정한 액션을 취하는 것이다.

이름은 실제 Mbean의 Method와 맵핑된다.(거의)
ex) 이름 : StartOnBootContainerList
메서드: jeus.server.service.ContainerManagerService implements ContainerManagerServiceMBean

    LoginUtil.checkPermissionWithRuntimeException(containerManagerPermission);

 

    List containerList = new Vector();
    try {
      JeusMainDescriptor desc = JeusServer.readJeusMainDescriptor(this.nodeName);
      for (i$ = desc.engineContainers.values().iterator(); i$.hasNext(); ) { Object o = i$.next();
        EngineContainerDescriptor ecdesc = (EngineContainerDescriptor)o;
        if (ecdesc.isStartOnBoot())
          containerList.add(ecdesc.getName());
      }
    }
    catch (JeusServerException e)
    {
      Iterator i$;
      logger.log(JeusMessage_Manager._147_LEVEL, JeusMessage_Manager._147, e);
    }

    return containerList;

}

고맙습니다.

728x90
반응형