From bf7ee36cefc9edff5636deafee1956fb04b05926 Mon Sep 17 00:00:00 2001 From: geek Date: Wed, 6 Sep 2017 18:25:16 +0900 Subject: [PATCH] jmx test --- .../overflow/crawler/jmx/JmxCrawler.java | 9 ++- src/test/java/com/loafle/AppTest.java | 3 +- src/test/resources/config/example1.json | 68 +++++++++++++++++++ src/test/resources/config/example2.json | 47 +++++++++++++ 4 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/config/example1.json create mode 100644 src/test/resources/config/example2.json 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