[펌]Jeus JMS 통계 정보 얻기..

Jeus JMS 통계 정보 얻기..

– . JMX 구동 방식

-.  JeusJmxUtil.java, QueStatInfo.java  두개 파일 구현

 

[1. JeusJmxUtil.java 소스..  package 명은 알아서 바꿔주는 센스..~~]

[ main 메소드에 샘플 코드 작성했음.]

package com.krxapm.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.naming.Context;

import jeus.jms.server.mbean.JMSQueueDestinationResourceMBean;
import jeus.management.RemoteMBeanServerFactory;
import jeus.management.j2ee.J2EEServerMBean;
import jeus.management.j2ee.JEUSManagerMBean;

import com.krxapm.app.jmx.info.QueStatInfo;

public class JeusJmxUtil {
public MBeanServerConnection getMbean(HashMap hmap){
MBeanServerConnection rmiMbeanServer = null;
try {

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, “jeus.jndi.JEUSContextFactory”);
env.put(Context.SECURITY_PRINCIPAL, hmap.get(“jeus_id”).toString());
env.put(Context.SECURITY_CREDENTIALS, hmap.get(“jeus_pw”).toString());
env.put(Context.PROVIDER_URL, hmap.get(“host_ip”).toString());
//      InitialContext ctx = new InitialContext(env);
//      String targetName = hmap.get(“host_id”).toString();
//     
//      JMXConnector connector = (JMXConnector) ctx.lookup(JMXConstants.JNDI_BINDING_PREFIX + targetName);
//      connector.connect();
//     
//      /* JNDI 호출 방식.. ObjectName 리스트 전체가 안 찍힘.. */
//      rmiMbeanServer = connector.getMBeanServerConnection();

// JNDI 방식보다 Remote 방식이 ObjectName 리스트가 안정적으로 나옴..
rmiMbeanServer = RemoteMBeanServerFactory.getMBeanServer(env);
} catch (Throwable t) {
t.printStackTrace();
}

return rmiMbeanServer;
}

/**
   * Jeus JMS 컨테이너 정보 얻기..
   *
   * @param mbConn
   * @return
   * @throws Exception
   */

public ArrayList getConList(MBeanServerConnection mbConn) throws Exception {

int i = 0;
ObjectName filterName = null;
filterName = new ObjectName(“JEUS:jeusType=JeusManager,*”);

Set objectNames = mbConn.queryNames(filterName, null);
JEUSManagerMBean[] jeusMangerMBean = new JEUSManagerMBean[objectNames.size()];

ArrayList alist = new ArrayList();

Iterator objectNamesIter = objectNames.iterator();
while(objectNamesIter.hasNext()){

ObjectName obj = (ObjectName) objectNamesIter.next();

Class conManagerClass = Class.forName(“jeus.management.j2ee.JEUSManagerMBean”);
jeusMangerMBean[i] = (JEUSManagerMBean) MBeanServerInvocationHandler.newProxyInstance(mbConn, obj, conManagerClass,false);

ObjectName[] objs = jeusMangerMBean[i].getj2eeServerNames();
//String[] conList = new String[objs.length];
ArrayList conList = new ArrayList();
for(int j=0; j<objs.length; j++){
// 컨테이너 정보 전부를 담을 경우 String[] 배열로 선언한 후 아래 주석을 제거한다.
//conList[j] = objs[j].getKeyProperty(“name”);

// JMSEngine을 포함하는 컨테이너 정보만 얻어올 경우 아래 로직 사용
// conList는 ArrayList로 구현한다.. (벡터 사용)
Class j2eeManagerClass = Class.forName(“jeus.management.j2ee.J2EEServerMBean”);
J2EEServerMBean j2eeServerMBean = (J2EEServerMBean) MBeanServerInvocationHandler.newProxyInstance(mbConn, objs[j], j2eeManagerClass, false);
ObjectName[] engineList = j2eeServerMBean.getEngines();
for(int k=0; k<engineList.length; k++){
String engineType = engineList[k].getKeyProperty(“jeusType”);
if(engineType.equals(“JMSEngine”)){
conList.add(objs[j].getKeyProperty(“name”));
}
}
}

HashMap hmap = new HashMap();
hmap.put(“node”, obj.getKeyProperty(“name”));
hmap.put(“conList”, conList);
alist.add(hmap);

i++;
}

return alist;
}

/**
* JMS 통계 정보 얻기
*
* @param mbConn
* @param conName
* @return
* @throws Exception
*/
public ArrayList getJmsStat(MBeanServerConnection mbConn, String conName) throws Exception{
ObjectName jeusScope = new ObjectName(RemoteMBeanServerFactory.SYSTEM_DOMAIN +“:j2eeType=JeusService,jeusType=JMSDestinationResource,JMXManager=”+conName+“,*”);
Set jeusSet = mbConn.queryNames(jeusScope, null);

JMSQueueDestinationResourceMBean dstQueMbean=null;
ArrayList alist = new ArrayList();

for (Iterator i = jeusSet.iterator(); i.hasNext();) {
ObjectName jmsDstObj = new ObjectName(i.next().toString());
dstQueMbean = (JMSQueueDestinationResourceMBean)MBeanServerInvocationHandler.newProxyInstance(mbConn, jmsDstObj, JMSQueueDestinationResourceMBean.class, false );
//System.out.println(“[JEUS Monitoring Service] ” + i.next());

QueStatInfo qsi = new QueStatInfo();
qsi.setName(dstQueMbean.getName());
qsi.setExportName(dstQueMbean.getExportName());

try{
qsi.setExpiredCount(new Long(dstQueMbean.getExpiredMessageCount()).toString());
qsi.setDestCount(new Long(dstQueMbean.getMessageCount()).toString());
qsi.setRemainCount(new Long(dstQueMbean.getRemainingMessages()).toString());
if(dstQueMbean.isTopic())
qsi.setPendingCount(new Long(dstQueMbean.getRemainingPendingMessages()).toString());
else
qsi.setPendingCount(“0”);

qsi.setWaitMaxTime(new Long(dstQueMbean.getMessageWaitMaxTime()).toString());
qsi.setWaitMinTime(new Long(dstQueMbean.getMessageWaitMinTime()).toString());
qsi.setWaitTotalTime(new Long(dstQueMbean.getMessageWaitTotalTime()).toString());
}catch(Exception e){
qsi.setExpiredCount(“0”);
qsi.setDestCount(“0”);
qsi.setRemainCount(“0”);
qsi.setPendingCount(“0”);

qsi.setWaitMaxTime(“0”);
qsi.setWaitMinTime(“0”);
qsi.setWaitTotalTime(“0”);
}
List list = dstQueMbean.getJMSConsumerResourceNames();
String clientNames = “”;
for(int j =0; j<list.size(); j++){
if(j > list.size())
clientNames += list.get(j).toString()+“,”;
else
clientNames += list.get(j).toString();
}
qsi.setClientNames(clientNames);

if(dstQueMbean.isQueue()){
qsi.setQueueType(“Queue”);
}else if(dstQueMbean.isTopic()){
qsi.setQueueType(“Topic”);
}
alist.add(qsi);
}

return alist;
}

public static void main(String[] args) {
HashMap hmap = new HashMap();
hmap.put(“host_id”, “tmax-ae3898e485”);
hmap.put(“host_ip”, “localhost”);
hmap.put(“jndi_port”, “9736”);
hmap.put(“jeus_id”, “administrator”);
hmap.put(“jeus_pw”, “jeusadmin”);

JeusJmxUtil ju = new JeusJmxUtil();
MBeanServerConnection mbconn = ju.getMbean(hmap);
try{
ArrayList conList = ju.getConList(mbconn);
ArrayList queStatList = ju.getJmsStat(mbconn, “tmax-ae3898e485_container1”);
}catch(Exception e){
e.printStackTrace();
}
}
}

 

[2. QueStatInfo.java 소스..  package 명은 알아서 바꿔주는 센스..~~]

package com.krxapm.app.jmx.info;

public class QueStatInfo {
private String name;
private String exportName;
private String expiredCount;
private String destCount;
private String remainCount;
private String pendingCount;
private String waitMaxTime;
private String waitMinTime;
private String waitTotalTime;
private String queueType;
private String clientNames;
public String getClientNames() {
return clientNames;
}
public void setClientNames(String clientNames) {
this.clientNames = clientNames;
}
public String getQueueType() {
return queueType;
}
public void setQueueType(String queueType) {
this.queueType = queueType;
}
public String getDestCount() {
return destCount;
}
public void setDestCount(String destCount) {
this.destCount = destCount;
}
public String getExpiredCount() {
return expiredCount;
}
public void setExpiredCount(String expiredCount) {
this.expiredCount = expiredCount;
}
public String getExportName() {
return exportName;
}
public void setExportName(String exportName) {
this.exportName = exportName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPendingCount() {
return pendingCount;
}
public void setPendingCount(String pendingCount) {
this.pendingCount = pendingCount;
}
public String getRemainCount() {
return remainCount;
}
public void setRemainCount(String remainCount) {
this.remainCount = remainCount;
}
public String getWaitMaxTime() {
return waitMaxTime;
}
public void setWaitMaxTime(String waitMaxTime) {
this.waitMaxTime = waitMaxTime;
}
public String getWaitMinTime() {
return waitMinTime;
}
public void setWaitMinTime(String waitMinTime) {
this.waitMinTime = waitMinTime;
}
public String getWaitTotalTime() {
return waitTotalTime;
}
public void setWaitTotalTime(String waitTotalTime) {
this.waitTotalTime = waitTotalTime;
}
}