From 27578fe288de6c8308e98eb953d51ebf1a7473f5 Mon Sep 17 00:00:00 2001 From: "jackdaw@loafle.com" Date: Wed, 26 Apr 2017 18:07:55 +0900 Subject: [PATCH] . --- .../overflow/crawler/jmx/JmxCrawler.java | 173 +----------------- 1 file changed, 4 insertions(+), 169 deletions(-) diff --git a/src/main/java/com/loafle/overflow/crawler/jmx/JmxCrawler.java b/src/main/java/com/loafle/overflow/crawler/jmx/JmxCrawler.java index cb123eb..6c59c7f 100644 --- a/src/main/java/com/loafle/overflow/crawler/jmx/JmxCrawler.java +++ b/src/main/java/com/loafle/overflow/crawler/jmx/JmxCrawler.java @@ -2,14 +2,9 @@ package com.loafle.overflow.crawler.jmx; import com.loafle.overflow.crawler.Crawler; import com.loafle.overflow.crawler.config.*; -import com.loafle.overflow.crawler.config.Query; import com.loafle.overflow.crawler.result.OFResultSet; import javax.management.*; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.CompositeType; -import javax.management.openmbean.TabularData; -import javax.management.openmbean.TabularType; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; @@ -18,7 +13,6 @@ import javax.management.remote.rmi.RMIConnectorServer; import javax.naming.Context; import javax.rmi.ssl.SslRMIClientSocketFactory; import java.io.IOException; -import java.lang.management.ManagementFactory; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -34,11 +28,6 @@ public class JmxCrawler extends Crawler{ private String username; private String password; private boolean ssl; -// private MBeanReceiver receiver; - private List whiteObjectNameList = new ArrayList<>(); - private List keys = new ArrayList<>(); - private List metrics = new ArrayList<>(); - private Map re = new HashMap(); public JmxCrawler() {} @@ -74,11 +63,6 @@ public class JmxCrawler extends Crawler{ @Override public Object getInternal(Config config) throws Exception { -// MBeanReceiver m = (domain, attrKeys, attrName, attrType, attrDescription, value) -// -> re.put(attrName, value.toString()); -// this.receiver = m; - - String hostIp = config.getTarget().getConnection().getIp(); String port = config.getTarget().getConnection().getPort(); @@ -91,13 +75,10 @@ public class JmxCrawler extends Crawler{ JMXConnector jmxconn = null; try { - if (this.jmxUrl.isEmpty()) { - beanCon = ManagementFactory.getPlatformMBeanServer(); - } else { - Map environment = getAuthority(); - jmxconn = JMXConnectorFactory.connect(new JMXServiceURL(this.jmxUrl), environment); - beanCon = jmxconn.getMBeanServerConnection(); - } + + Map environment = getAuthority(); + jmxconn = JMXConnectorFactory.connect(new JMXServiceURL(this.jmxUrl), environment); + beanCon = jmxconn.getMBeanServerConnection(); List resultSetList = new ArrayList<>(); List objectNames = new LinkedList(); @@ -164,152 +145,6 @@ public class JmxCrawler extends Crawler{ return returnData; } -// public static interface MBeanReceiver { -// void recordBean(String domain, LinkedList attrKeys, String attrName, String attrType, String attrDescription, Object value); -// } -// -// -// -// // 커넥터 생성 -// public void doCrawler() throws Exception { -// MBeanServerConnection beanCon; -// JMXConnector jmxconn = null; -// -// if (this.jmxUrl.isEmpty()) { -// beanCon = ManagementFactory.getPlatformMBeanServer(); -// } else { -// Map environment = getAuthority(); -// jmxconn = JMXConnectorFactory.connect(new JMXServiceURL(this.jmxUrl), environment); -// beanCon = jmxconn.getMBeanServerConnection(); -// } -// -// try { -// Set mBeanNames = new HashSet(); -// List objectNames = new LinkedList(); -// objectNames.add(null); -// -// ObjectName on = null; -// -// for (String q : this.whiteObjectNameList) { -// on = new ObjectName(q); -// mBeanNames.addAll(beanCon.queryMBeans(on, null)); -// } -// for (ObjectInstance name : mBeanNames) { -// crawlerBean(beanCon, name.getObjectName()); -// } -// }finally { -// if (jmxconn != null) { -// jmxconn.close(); -// } -// } -// } - - // 수집 -// private void crawlerBean(MBeanServerConnection beanCon, ObjectName mbeanName) { -// MBeanInfo info; -// -// try { -// info = beanCon.getMBeanInfo(mbeanName); -// } catch (IOException e) { -// logCrawler(mbeanName.toString(), "getMbeanInfo Fail: " + e); -// return; -// } catch (JMException e) { -// logCrawler(mbeanName.toString(), "getMbeanInfo Fail: " + e); -// return; -// } -// -// MBeanAttributeInfo[] attrInfos = info.getAttributes(); -// -// for (int idx = 0; idx < attrInfos.length; ++idx) { -// MBeanAttributeInfo attr = attrInfos[idx]; -// -// if (!attr.isReadable()) { -// logCrawler(mbeanName, attr, "not readable"); -// continue; -// } -// -// Object value; -// -// try { -// value = beanCon.getAttribute(mbeanName, attr.getName()); -// } catch (Exception e) { -// logCrawler(mbeanName, attr, "Fail: " + e); -// continue; -// } -// -// logCrawler(mbeanName, attr, "process"); -// processBeanValue( -// mbeanName.getDomain(), -// new LinkedList(), -// attr.getName(), -// attr.getType(), -// attr.getDescription(), -// value -// ); -// } -// } - -// private void processBeanValue(String domain, LinkedList attrKeys, String attrName, String attrType, String attrDescription, Object value) { -// if (value == null) { -// logCrawler("Value Null : "+domain + attrName, "null"); -// } else if (value instanceof Number || value instanceof String || value instanceof Boolean) { -// logCrawler(domain + attrName, value.toString()); -// this.receiver.recordBean(domain, attrKeys, attrName, attrType, attrDescription,value); -// // JSON 결과 생성 -// } else if (value instanceof CompositeData) { -// CompositeData composite = (CompositeData)value; -// CompositeType type = composite.getCompositeType(); -// attrKeys = new LinkedList(); -// attrKeys.add(attrName); -// -// for (String key : type.keySet()) { -// String typ = type.getType(key).getTypeName(); -// Object val = composite.get(key); -// -// processBeanValue(domain, attrKeys, key, typ, type.getDescription(), val); -// } -// } else if (value instanceof TabularData) { -// TabularData tds = (TabularData)value; -// TabularType tt = tds.getTabularType(); -// -// CompositeType type = tt.getRowType(); -// Set valueKeys = new TreeSet(type.keySet()); -// -// LinkedList extendedAttrKeys = new LinkedList(attrKeys); -// extendedAttrKeys.add(attrName); -// -// for (Object valu : tds.values()) { -// if (valu instanceof CompositeData) { -// CompositeData composite = (CompositeData) valu; -// -// for(String valueIdx : valueKeys) { -// LinkedList attrNames = extendedAttrKeys; -// String typ = type.getType(valueIdx).getTypeName(); -// String name = valueIdx; -// if (valueIdx.toLowerCase().equals("value")) { -// // Skip appending 'value' to the name -// attrNames = attrKeys; -// name = attrName; -// } -// processBeanValue( -// domain, -// attrNames, -// name, -// typ, -// type.getDescription(), -// composite.get(valueIdx)); -// } -// } else { -// logCrawler(domain, "not a correct tabulardata format"); -// } -// } -// } else if (value.getClass().isArray()) { -// logCrawler(domain, "arrays are unsupported"); -// } else { -// logCrawler(domain, attrType + "is not exported"); -// } -// } - private Map getAuthority() { Map environment = new HashMap();