.
This commit is contained in:
parent
d305a43850
commit
27578fe288
|
@ -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<String> whiteObjectNameList = new ArrayList<>();
|
||||
private List<Keys> keys = new ArrayList<>();
|
||||
private List<Keys> metrics = new ArrayList<>();
|
||||
private Map<String, String> re = new HashMap<String, String>();
|
||||
|
||||
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<String, Object> environment = getAuthority();
|
||||
jmxconn = JMXConnectorFactory.connect(new JMXServiceURL(this.jmxUrl), environment);
|
||||
beanCon = jmxconn.getMBeanServerConnection();
|
||||
}
|
||||
|
||||
Map<String, Object> environment = getAuthority();
|
||||
jmxconn = JMXConnectorFactory.connect(new JMXServiceURL(this.jmxUrl), environment);
|
||||
beanCon = jmxconn.getMBeanServerConnection();
|
||||
|
||||
List<OFResultSet> resultSetList = new ArrayList<>();
|
||||
List<ObjectName> objectNames = new LinkedList<ObjectName>();
|
||||
|
@ -164,152 +145,6 @@ public class JmxCrawler extends Crawler{
|
|||
return returnData;
|
||||
}
|
||||
|
||||
// public static interface MBeanReceiver {
|
||||
// void recordBean(String domain, LinkedList<String> 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<String, Object> environment = getAuthority();
|
||||
// jmxconn = JMXConnectorFactory.connect(new JMXServiceURL(this.jmxUrl), environment);
|
||||
// beanCon = jmxconn.getMBeanServerConnection();
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// Set<ObjectInstance> mBeanNames = new HashSet();
|
||||
// List<ObjectName> objectNames = new LinkedList<ObjectName>();
|
||||
// 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<String>(),
|
||||
// attr.getName(),
|
||||
// attr.getType(),
|
||||
// attr.getDescription(),
|
||||
// value
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// private void processBeanValue(String domain, LinkedList<String> 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<String>();
|
||||
// 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<String> valueKeys = new TreeSet<String>(type.keySet());
|
||||
//
|
||||
// LinkedList<String> extendedAttrKeys = new LinkedList<String>(attrKeys);
|
||||
// extendedAttrKeys.add(attrName);
|
||||
//
|
||||
// for (Object valu : tds.values()) {
|
||||
// if (valu instanceof CompositeData) {
|
||||
// CompositeData composite = (CompositeData) valu;
|
||||
//
|
||||
// for(String valueIdx : valueKeys) {
|
||||
// LinkedList<String> 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<String, Object> getAuthority() {
|
||||
|
||||
Map<String, Object> environment = new HashMap<String, Object>();
|
||||
|
|
Loading…
Reference in New Issue
Block a user