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 404075c..8e01c56 100644 --- a/src/main/java/com/loafle/overflow/crawler/jmx/JmxCrawler.java +++ b/src/main/java/com/loafle/overflow/crawler/jmx/JmxCrawler.java @@ -53,7 +53,14 @@ public class JmxCrawler extends Crawler{ logCrawler(mbeanName, attr, "not readable"); continue; } - Object att = beanCon.getAttribute(mbeanName, attr.getName()); + Object att = null; + + try { + att = beanCon.getAttribute(mbeanName, attr.getName()); + }catch (Exception e) { + e.printStackTrace(); + } + if (att != null) returnMap.put(attr.getName(), att.toString()); } diff --git a/src/test/java/com/loafle/AppTest.java b/src/test/java/com/loafle/AppTest.java index df3c33c..f6d5d93 100644 --- a/src/test/java/com/loafle/AppTest.java +++ b/src/test/java/com/loafle/AppTest.java @@ -25,7 +25,7 @@ public class AppTest { ClassLoader classLoader = getClass().getClassLoader(); URL url = classLoader.getResource("config/"); - String path = classLoader.getResource("config/example.json").getFile(); + String path = classLoader.getResource("config/example1.json").getFile(); ObjectMapper mapper = new ObjectMapper(); Config c = mapper.readValue(new File(path),Config.class); @@ -34,7 +34,6 @@ public class AppTest { List result = (List) cr.getInternal(c); print("",result); - } private void print(String s, List mm) { diff --git a/src/test/resources/config/example1.json b/src/test/resources/config/example1.json new file mode 100644 index 0000000..8b479e9 --- /dev/null +++ b/src/test/resources/config/example1.json @@ -0,0 +1,68 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.103", + "port" : "9840", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"jmx", + "container":"java_proxy" + }, + "items" : [ + { + "keys" : [ + {"metric" : "net.connector[$0].maxThreads", "key" : "maxThreads"}, + {"metric" : "net.connector[$0].currentThreadCount", "key" : "currentThreadCount"}, + {"metric" : "net.connector[$0].currentThreadsBusy", "key" : "currentThreadsBusy"} + ], + "queryInfo" : { + "query": "*Catalina:type=ThreadPool,*", + "extend" : { + "aliases" : [ + { + "key": "Catalina:type", + "index":0 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "ThreadPool" ] + } + }, + { + "keys" : [ + {"metric" : "net.connector[$0].bytesSent", "key" : "bytesSent"}, + {"metric" : "net.connector[$0].bytesReceived", "key" : "bytesReceived"}, + {"metric" : "net.connector[$0].errorCount", "key" : "errorCount"}, + {"metric" : "net.connector[$0].requestCount", "key" : "requestCount"}, + {"metric" : "net.connector[$0].maxTime", "key" : "maxTime"}, + {"metric" : "net.connector[$0].processingTime", "key" : "processingTime"} + ], + "queryInfo" : { + "query": "*Catalina:type=GlobalRequestProcessor,*", + "extend" : { + "aliases" : [ + { + "key": "Catalina:type", + "index":0 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "GlobalRequestProcessor" ] + } + } + ] +} \ No newline at end of file diff --git a/src/test/resources/config/example2.json b/src/test/resources/config/example2.json new file mode 100644 index 0000000..c9a1f89 --- /dev/null +++ b/src/test/resources/config/example2.json @@ -0,0 +1,47 @@ +{ + "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "target" : { + "connection" : { + "ip" : "192.168.1.103", + "port" : "9840", + "ssl" : false, + "portType" : "tcp" + }, + "auth" : { + + } + }, + "schedule" : { + "interval" : "10" + }, + "crawler" : { + "name":"jmx", + "container":"java_proxy" + }, + "items" : [ + { + "keys" : [ + {"metric" : "net.connector[$1].bytesSent", "key" : "bytesSent"}, + {"metric" : "net.connector[$1].bytesReceived", "key" : "bytesReceived"}, + {"metric" : "net.connector[$1].errorCount", "key" : "errorCount"}, + {"metric" : "net.connector[$1].requestCount", "key" : "requestCount"}, + {"metric" : "net.connector[$1].maxTime", "key" : "maxTime"}, + {"metric" : "net.connector[$1].processingTime", "key" : "processingTime"} + ], + "queryInfo" : { + "query": "*Catalina:j2eeType=GlobalRequestProcessor,*", + "extend" : { + "aliases" : [ + { + "key": "Catalina:type", + "index":1 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "GlobalRequestProcessor" ] + } + } + ] +} \ No newline at end of file