From 87bd9653764a9146027d36dd38027cde12f59761 Mon Sep 17 00:00:00 2001 From: geek Date: Tue, 12 Sep 2017 18:02:58 +0900 Subject: [PATCH] jmx test --- .../overflow/crawler/jmx/JmxCrawler.java | 13 +++- src/test/java/com/loafle/AppTest.java | 2 +- src/test/resources/config/example.json | 4 +- src/test/resources/config/example1.json | 64 ++++++++++++++++++- 4 files changed, 77 insertions(+), 6 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 8e01c56..ac1e9c8 100644 --- a/src/main/java/com/loafle/overflow/crawler/jmx/JmxCrawler.java +++ b/src/main/java/com/loafle/overflow/crawler/jmx/JmxCrawler.java @@ -53,12 +53,19 @@ public class JmxCrawler extends Crawler{ logCrawler(mbeanName, attr, "not readable"); continue; } + +// System.out.println("========================================================================"); +// System.out.println("PropertyListString"+mbeanName.getCanonicalKeyPropertyListString()); +// System.out.println("canonicaName="+mbeanName.getCanonicalName()); +// System.out.println(mbeanName.getDomain()); +// System.out.println(mbeanName.getKeyPropertyListString().compareTo("http")); +// System.out.println("========================================================================"); Object att = null; try { att = beanCon.getAttribute(mbeanName, attr.getName()); }catch (Exception e) { - e.printStackTrace(); + continue; } if (att != null) @@ -74,8 +81,8 @@ public class JmxCrawler extends Crawler{ String port = config.getTarget().getConnection().getPort(); this.jmxUrl = "service:jmx:rmi:///jndi/rmi://" + hostIp + ":" +port + "/jmxrmi"; - this.username = null; - this.password = null; + this.username = (String) config.getTarget().getAuth().get("username"); + this.password = (String) config.getTarget().getAuth().get("password"); // connection MBeanServerConnection beanCon; diff --git a/src/test/java/com/loafle/AppTest.java b/src/test/java/com/loafle/AppTest.java index f6d5d93..f19b6f1 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/example1.json").getFile(); + String path = classLoader.getResource("config/example.json").getFile(); ObjectMapper mapper = new ObjectMapper(); Config c = mapper.readValue(new File(path),Config.class); diff --git a/src/test/resources/config/example.json b/src/test/resources/config/example.json index 86b258f..521179f 100644 --- a/src/test/resources/config/example.json +++ b/src/test/resources/config/example.json @@ -23,7 +23,9 @@ "keys" : [ {"metric" : "net.connector[$0].requestCount", "key" : "requestCount"}, {"metric" : "net.connector[$0].loadOnStartup", "key" : "loadOnStartup"}, - {"metric" : "net.connector[$0].errorCount", "key" : "errorCount"} + {"metric" : "net.connector[$0].errorCount", "key" : "errorCount"}, + {"metric" : "net.connector[$0].objectName", "key" : "objectName"} + ], "queryInfo" : { "query": "*Catalina:j2eeType=Servlet,*", diff --git a/src/test/resources/config/example1.json b/src/test/resources/config/example1.json index 8b479e9..70ac2f6 100644 --- a/src/test/resources/config/example1.json +++ b/src/test/resources/config/example1.json @@ -8,7 +8,8 @@ "portType" : "tcp" }, "auth" : { - + "username": "jmxuser", + "password": "tomcat" } }, "schedule" : { @@ -63,6 +64,67 @@ "mappingInfo" : { "arrayColumns" : [ "GlobalRequestProcessor" ] } + }, + { + "keys" : [ + {"metric" : "net.connector[$0].processingTime", "key" : "processingTime"}, + {"metric" : "net.connector[$0].errorCount", "key" : "errorCount"}, + {"metric" : "net.connector[$0].requestCount", "key" : "requestCount"} + ], + "queryInfo" : { + "query": "*Catalina:j2eeType=Servlet,*", + "extend" : { + "aliases" : [ + { + "key": "Catalina:j2eeType", + "index":0 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "Servlet" ] + } + }, + { + "keys" : [ + {"metric" : "net.connector[$0].accessCount", "key" : "accessCount"}, + {"metric" : "net.connector[$0].hitCount", "key" : "hitCount"} + ], + "queryInfo" : { + "query": "*Catalina:type=StringCache,*", + "extend" : { + "aliases" : [ + { + "key": "Catalina:type", + "index":0 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "StringCache" ] + } + }, + { + "keys" : [ + {"metric" : "net.connector[$0].jspCount", "key" : "jspCount"}, + {"metric" : "net.connector[$0].jspReloadCount", "key" : "jspReloadCount"} + ], + "queryInfo" : { + "query": "*Catalina:type=JspMonitor,*", + "extend" : { + "aliases" : [ + { + "key": "Catalina:type", + "index":0 + } + ] + } + }, + "mappingInfo" : { + "arrayColumns" : [ "JspMonitor" ] + } } ] } \ No newline at end of file