config 적용 테스트
This commit is contained in:
parent
d824601b33
commit
cb1fd86aed
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||||
<output url="file://$MODULE_DIR$/../jmx_crawler/target/classes" />
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
<output-test url="file://$MODULE_DIR$/../jmx_crawler/target/test-classes" />
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
@ -13,6 +13,9 @@
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="Maven: com.loafle.overflow:crawler:1.0.0-SNAPSHOT" level="project" />
|
<orderEntry type="library" name="Maven: com.loafle.overflow:crawler:1.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.8" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.8" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package com.loafle.overflow.crawler.jmx;
|
package com.loafle.overflow.crawler.jmx;
|
||||||
|
|
||||||
import com.loafle.overflow.crawler.Crawler;
|
import com.loafle.overflow.crawler.Crawler;
|
||||||
import com.loafle.overflow.crawler.config.Config;
|
import com.loafle.overflow.crawler.config.*;
|
||||||
|
import com.loafle.overflow.crawler.config.Query;
|
||||||
|
|
||||||
import javax.management.*;
|
import javax.management.*;
|
||||||
import javax.management.openmbean.CompositeData;
|
import javax.management.openmbean.CompositeData;
|
||||||
|
@ -33,8 +34,10 @@ public class JmxCrawler extends Crawler{
|
||||||
private String password;
|
private String password;
|
||||||
private boolean ssl;
|
private boolean ssl;
|
||||||
private MBeanReceiver receiver;
|
private MBeanReceiver receiver;
|
||||||
|
private List<String> whiteObjectNameList = new ArrayList<>();
|
||||||
|
private List<List<String>> keys = new ArrayList<>();
|
||||||
|
|
||||||
private List<Object> result = new ArrayList<>();
|
private Map<String, String> re = new HashMap<String, String>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getInternal(Config config) throws Exception {
|
public Object getInternal(Config config) throws Exception {
|
||||||
|
@ -42,26 +45,43 @@ public class JmxCrawler extends Crawler{
|
||||||
MBeanReceiver m = new MBeanReceiver() {
|
MBeanReceiver m = new MBeanReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void recordBean(String domain, LinkedList<String> attrKeys, String attrName, String attrType, String attrDescription, Object value) {
|
public void recordBean(String domain, LinkedList<String> attrKeys, String attrName, String attrType, String attrDescription, Object value) {
|
||||||
Map<String, String> l = new HashMap<String, String>();
|
re.put(attrName, value.toString());
|
||||||
l.put(attrName, attrType+" "+value);
|
|
||||||
result.add(l);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// String jmxUrl = (String) map.get("jmxUrl");
|
// "service:jmx:rmi:///jndi/rmi://192.168.1.103:9840/jmxrmi";
|
||||||
// String username = (String)map.get("username");
|
String hostIp = config.getTarget().getConnection().getIp();
|
||||||
// String password = (String)map.get("password");
|
String port = config.getTarget().getConnection().getPort();
|
||||||
// Boolean isSSL = (Boolean)map.get("ssl");
|
|
||||||
//
|
this.jmxUrl = "service:jmx:rmi:///jndi/rmi://" + hostIp + ":" +port + "/jmxrmi";
|
||||||
// JmxCrawler jmxCrawler = new JmxCrawler(
|
this.username = null;
|
||||||
// jmxUrl,
|
this.password = null;
|
||||||
// username,
|
this.receiver = m;
|
||||||
// password,
|
|
||||||
// isSSL,
|
for (Item item : config.getItems()) {
|
||||||
// m
|
List<com.loafle.overflow.crawler.config.Query> querys = item.getQueries();
|
||||||
// );
|
for (Query q : querys) {
|
||||||
//
|
this.whiteObjectNameList.add(q.getQuery());
|
||||||
// jmxCrawler.doCrawler();
|
this.keys.add(q.getKeys());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.doCrawler();
|
||||||
|
|
||||||
|
Map<String, String> result = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
for (List<String> ks : this.keys) {
|
||||||
|
for (String k : ks) {
|
||||||
|
for (String key : re.keySet()) {
|
||||||
|
if (k.equals(key)) {
|
||||||
|
result.put(key, re.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,13 +92,13 @@ public class JmxCrawler extends Crawler{
|
||||||
public JmxCrawler() {
|
public JmxCrawler() {
|
||||||
|
|
||||||
}
|
}
|
||||||
public JmxCrawler(String jmxUrl, String username, String password, boolean ssl, MBeanReceiver receiver) {
|
// public JmxCrawler(String jmxUrl, String username, String password, boolean ssl, MBeanReceiver receiver) {
|
||||||
this.jmxUrl = jmxUrl;
|
// this.jmxUrl = jmxUrl;
|
||||||
this.username = username;
|
// this.username = username;
|
||||||
this.password = password;
|
// this.password = password;
|
||||||
this.ssl = ssl;
|
// this.ssl = ssl;
|
||||||
this.receiver = receiver;
|
// this.receiver = receiver;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 커넥터 생성
|
// 커넥터 생성
|
||||||
public void doCrawler() throws Exception {
|
public void doCrawler() throws Exception {
|
||||||
|
@ -112,11 +132,15 @@ public class JmxCrawler extends Crawler{
|
||||||
// crawlerBean(beanCon, name.getObjectName());
|
// crawlerBean(beanCon, name.getObjectName());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
ObjectName on = new ObjectName("Catalina:type=*,*");
|
// ObjectName on = new ObjectName("Catalina:type=*,*");
|
||||||
// ObjectName on = new ObjectName("org.apache.cassandra.db:type=*,*");
|
// ObjectName on = new ObjectName("org.apache.cassandra.db:type=*,*");
|
||||||
|
|
||||||
mBeanNames.addAll(beanCon.queryMBeans(on,null));
|
ObjectName on = null;
|
||||||
|
|
||||||
|
for (String q : this.whiteObjectNameList) {
|
||||||
|
on = new ObjectName(q);
|
||||||
|
mBeanNames.addAll(beanCon.queryMBeans(on,null));
|
||||||
|
}
|
||||||
for (ObjectInstance name : mBeanNames) {
|
for (ObjectInstance name : mBeanNames) {
|
||||||
crawlerBean(beanCon, name.getObjectName());
|
crawlerBean(beanCon, name.getObjectName());
|
||||||
}
|
}
|
||||||
|
@ -174,13 +198,12 @@ public class JmxCrawler extends Crawler{
|
||||||
|
|
||||||
private void processBeanValue(String domain, LinkedList<String> attrKeys, String attrName, String attrType, String attrDescription, Object value) {
|
private void processBeanValue(String domain, LinkedList<String> attrKeys, String attrName, String attrType, String attrDescription, Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
logCrawler("ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"+domain + attrName, "null");
|
logCrawler("Value Null : "+domain + attrName, "null");
|
||||||
} else if (value instanceof Number || value instanceof String || value instanceof Boolean) {
|
} else if (value instanceof Number || value instanceof String || value instanceof Boolean) {
|
||||||
logCrawler(domain + attrName, value.toString());
|
logCrawler(domain + attrName, value.toString());
|
||||||
this.receiver.recordBean(domain, attrKeys, attrName, attrType, attrDescription,value);
|
this.receiver.recordBean(domain, attrKeys, attrName, attrType, attrDescription,value);
|
||||||
// JSON 결과 생성
|
// JSON 결과 생성
|
||||||
} else if (value instanceof CompositeData) {
|
} else if (value instanceof CompositeData) {
|
||||||
logCrawler("ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"+domain + attrName, "compositedata");
|
|
||||||
CompositeData composite = (CompositeData)value;
|
CompositeData composite = (CompositeData)value;
|
||||||
CompositeType type = composite.getCompositeType();
|
CompositeType type = composite.getCompositeType();
|
||||||
attrKeys = new LinkedList<String>();
|
attrKeys = new LinkedList<String>();
|
||||||
|
@ -193,7 +216,6 @@ public class JmxCrawler extends Crawler{
|
||||||
processBeanValue(domain, attrKeys, key, typ, type.getDescription(), val);
|
processBeanValue(domain, attrKeys, key, typ, type.getDescription(), val);
|
||||||
}
|
}
|
||||||
} else if (value instanceof TabularData) {
|
} else if (value instanceof TabularData) {
|
||||||
logCrawler("ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"+domain + attrName, "tabulardata");
|
|
||||||
TabularData tds = (TabularData)value;
|
TabularData tds = (TabularData)value;
|
||||||
TabularType tt = tds.getTabularType();
|
TabularType tt = tds.getTabularType();
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,14 @@
|
||||||
package com.loafle;
|
package com.loafle;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import com.loafle.overflow.crawler.Crawler;
|
||||||
|
import com.loafle.overflow.crawler.config.*;
|
||||||
import com.loafle.overflow.crawler.jmx.JmxCrawler;
|
import com.loafle.overflow.crawler.jmx.JmxCrawler;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class AppTest {
|
public class AppTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSum() {
|
public void testSum() {
|
||||||
|
@ -12,7 +17,7 @@ public class AppTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestDoCrawler() {
|
public void TestDoCrawler() throws Exception {
|
||||||
// JmxCrawler jmxCrawler = new JmxCrawler(
|
// JmxCrawler jmxCrawler = new JmxCrawler(
|
||||||
//// "service:jmx:rmi:///jndi/rmi://192.168.1.207:7199/jmxrmi",
|
//// "service:jmx:rmi:///jndi/rmi://192.168.1.207:7199/jmxrmi",
|
||||||
// "service:jmx:rmi:///jndi/rmi://192.168.1.103:9840/jmxrmi",
|
// "service:jmx:rmi:///jndi/rmi://192.168.1.103:9840/jmxrmi",
|
||||||
|
@ -24,5 +29,60 @@ public class AppTest {
|
||||||
// );
|
// );
|
||||||
//
|
//
|
||||||
// jmxCrawler.doCrawler();
|
// jmxCrawler.doCrawler();
|
||||||
|
|
||||||
|
Config config = new Config();
|
||||||
|
|
||||||
|
config.setId("SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734");
|
||||||
|
Connection cn = new Connection();
|
||||||
|
cn.setIp("192.168.1.103");
|
||||||
|
cn.setPort("9840");
|
||||||
|
cn.setSsl(false);
|
||||||
|
cn.setPortType("tcp");
|
||||||
|
|
||||||
|
Target t = new Target();
|
||||||
|
t.setConnection(cn);
|
||||||
|
|
||||||
|
Schedule s = new Schedule();
|
||||||
|
s.setInterval("10");
|
||||||
|
|
||||||
|
com.loafle.overflow.crawler.config.Crawler cc = new com.loafle.overflow.crawler.config.Crawler();
|
||||||
|
cc.setName("jmx_crawler");
|
||||||
|
cc.setContainer("java_crawler");
|
||||||
|
|
||||||
|
List<Item> ls = new ArrayList<>();
|
||||||
|
List<String> metrics = new ArrayList<>();
|
||||||
|
List<Query> queries = new ArrayList<>();
|
||||||
|
List<String> keys = new ArrayList<>();
|
||||||
|
keys.add("ProcessCpuLoad");
|
||||||
|
keys.add("ProcessCpuTime");
|
||||||
|
keys.add("SystemCpuLoad");
|
||||||
|
|
||||||
|
Query query = new Query();
|
||||||
|
query.setKeys(keys);
|
||||||
|
query.setQuery("java.lang:type=OperatingSystem");
|
||||||
|
|
||||||
|
queries.add(query);
|
||||||
|
|
||||||
|
metrics.add("cpu.system");
|
||||||
|
metrics.add("cpu.user");
|
||||||
|
metrics.add("cpu.system_children");
|
||||||
|
metrics.add("cpu.user_children");
|
||||||
|
|
||||||
|
Item it = new Item();
|
||||||
|
it.setMetrics(metrics);
|
||||||
|
it.setQueries(queries);
|
||||||
|
|
||||||
|
ls.add(it);
|
||||||
|
|
||||||
|
config.setTarget(t);
|
||||||
|
config.setSchedule(s);
|
||||||
|
config.setCrawler(cc);
|
||||||
|
config.setItems(ls);
|
||||||
|
|
||||||
|
JmxCrawler cr = new JmxCrawler();
|
||||||
|
|
||||||
|
Object o = cr.getInternal(config);
|
||||||
|
|
||||||
|
System.out.println("o = " + o);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user