public static long getLastGcDuration(ObjectName gcCollector) { long lastGcDuration = 0; Object lastGcInfo = getValueFromMBean(gcCollector, "LastGcInfo"); if (lastGcInfo != null && lastGcInfo instanceof CompositeData) { CompositeData cds = (CompositeData)lastGcInfo; lastGcDuration = (long) cds.get("duration"); } return lastGcDuration; }
@Test public void testSearchJson() throws JsonProcessingException, IOException { String jsonString = "{\"test\":[{\"data1\":100,\"data2\":\"hello\",\"data3\": [1 , 2 , 3]}, " + "{\"data4\":0}]}"; JsonNode node = JSONMetricUtil.mappStringToJsonNode(jsonString); JsonNode r1 = JSONMetricUtil.searchJson(node, "data1"); JsonNode r2 = JSONMetricUtil.searchJson(node, "data2"); JsonNode r3 = JSONMetricUtil.searchJson(node, "data3"); JsonNode r4 = JSONMetricUtil.searchJson(node, "data4"); assertEquals(100, r1.intValue()); assertEquals("hello", r2.textValue()); assertEquals(1, r3.get(0).intValue()); assertEquals(0, r4.intValue()); }
@Test public void testBuildObjectName() throws MalformedObjectNameException { String[] keys = {"type", "name"}; String[] values = {"MemoryPool", "Par Eden Space"}; Hashtable<String, String> properties = JSONMetricUtil.buldKeyValueTable(keys, values); ObjectName testObject = JSONMetricUtil.buildObjectName(JSONMetricUtil.JAVA_LANG_DOMAIN, properties); assertEquals(JSONMetricUtil.JAVA_LANG_DOMAIN, testObject.getDomain()); assertEquals(testObject.getKeyPropertyList(), properties); }
List<GarbageCollectorMXBean> gcBeans = JSONMetricUtil.getGcCollectorBeans(); GarbageCollectorMXBean collector1 = null; GarbageCollectorMXBean collector2 = null; collector2 = gcBeans.get(1); } catch(IndexOutOfBoundsException e) {} List<MemoryPoolMXBean> mPools = JSONMetricUtil.getMemoryPools(); pageContext.setAttribute("pageTitle", "Process info for PID: " + JSONMetricUtil.getProcessPID()); out.print( JSONMetricUtil.getCommmand().split(" ")[0] ); out.write("</h1>\n </div>\n </div>\n <table class=\"table table-striped\" width=\"90%\" >\n <tr>\n <th>Started</th>\n <th>Uptime</th>\n <th>PID</th>\n <th>JvmPauseMonitor Count </th>\n <th>Owner</th>\n </tr>\n <tr>\n <tr>\n <td>"); out.print( new Date(runtimeBean.getStartTime()) ); out.print( StringUtils.humanTimeDiff(runtimeBean.getUptime()) ); out.write("</td>\n <td>"); out.print( JSONMetricUtil.getProcessPID() ); out.write("</td>\n <td>"); out.print( (long)JSONMetricUtil.getValueFromMBean(rsMetrics, "pauseWarnThresholdExceeded") + (long)JSONMetricUtil.getValueFromMBean(rsMetrics, "pauseInfoThresholdExceeded") ); out.write("</td>\n <td>"); out.print( runtimeBean.getSystemProperties().get("user.name") ); out.write("</td>\n </tr>\n </table>\n</div>\n<div class=\"container-fluid content\">\n <div class=\"row\">\n <div class=\"page-header\">\n <h2>Threads</h2>\n </div>\n </div>\n <table class=\"table table-striped\" width=\"90%\" >\n <tr>\n <th>ThreadsNew</th>\n <th>ThreadsRunable</th>\n <th>ThreadsBlocked</th>\n <th>ThreadsWaiting</th>\n <th>ThreadsTimeWaiting</th>\n <th>ThreadsTerminated</th>\n </tr>\n <tr>\n <tr>\n <td>"); out.print( JSONMetricUtil.getValueFromMBean(jvmMetrics, "ThreadsNew") ); out.write("</td>\n <td>"); out.print( JSONMetricUtil.getValueFromMBean(jvmMetrics, "ThreadsRunnable")); out.write("</td>\n <td>"); out.print( JSONMetricUtil.getValueFromMBean(jvmMetrics, "ThreadsBlocked")); out.write("</td>\n <td>"); out.print( JSONMetricUtil.getValueFromMBean(jvmMetrics, "ThreadsWaiting"));
public static JsonNode searchJson(JsonNode tree, String searchKey) throws JsonProcessingException, IOException { if (tree == null) { return null; } if(tree.has(searchKey)) { return tree.get(searchKey); } if(tree.isContainerNode()) { for(JsonNode branch: tree) { JsonNode branchResult = searchJson(branch, searchKey); if (branchResult != null && !branchResult.isMissingNode()) { return branchResult; } } } return null; }
@Test public void testBuildHashtable() { String[] keys = {"type", "name"}; String[] emptyKey = {}; String[] values = {"MemoryPool", "Par Eden Space"}; String[] values2 = {"MemoryPool", "Par Eden Space", "Test"}; String[] emptyValue = {}; Map<String, String> properties = JSONMetricUtil.buldKeyValueTable(keys, values); assertEquals(values[0], properties.get("type")); assertEquals(values[1], properties.get("name")); assertNull(JSONMetricUtil.buldKeyValueTable(keys, values2)); assertNull(JSONMetricUtil.buldKeyValueTable(keys, emptyValue)); assertNull(JSONMetricUtil.buldKeyValueTable(emptyKey, values2)); assertNull(JSONMetricUtil.buldKeyValueTable(emptyKey, emptyValue)); }
List<GarbageCollectorMXBean> gcBeans = JSONMetricUtil.getGcCollectorBeans(); GarbageCollectorMXBean collector1 = null; GarbageCollectorMXBean collector2 = null; collector2 = gcBeans.get(1); } catch(IndexOutOfBoundsException e) {} List<MemoryPoolMXBean> mPools = JSONMetricUtil.getMemoryPools(); pageContext.setAttribute("pageTitle", "Process info for PID: " + JSONMetricUtil.getProcessPID()); out.print( JSONMetricUtil.getCommmand().split(" ")[0] ); out.write("</h1>\n </div>\n </div>\n <table class=\"table table-striped\" width=\"90%\" >\n <tr>\n <th>Started</th>\n <th>Uptime</th>\n <th>PID</th>\n <th>Owner</th>\n </tr>\n <tr>\n <tr>\n <td>"); out.print( new Date(runtimeBean.getStartTime()) ); out.print( StringUtils.humanTimeDiff(runtimeBean.getUptime()) ); out.write("</td>\n <td>"); out.print( JSONMetricUtil.getProcessPID() ); out.write("</td>\n <td>"); out.print( runtimeBean.getSystemProperties().get("user.name") ); out.write("</td>\n </tr>\n </table>\n</div>\n<div class=\"container-fluid content\">\n <div class=\"row\">\n <div class=\"page-header\">\n <h2>Threads</h2>\n </div>\n </div>\n <table class=\"table table-striped\" width=\"90%\" >\n <tr>\n <th>ThreadsNew</th>\n <th>ThreadsRunable</th>\n <th>ThreadsBlocked</th>\n <th>ThreadsWaiting</th>\n <th>ThreadsTimeWaiting</th>\n <th>ThreadsTerminated</th>\n </tr>\n <tr>\n <td>"); out.print( JSONMetricUtil.getValueFromMBean(jvmMetrics, "ThreadsNew") ); out.write("</td>\n <td>"); out.print( JSONMetricUtil.getValueFromMBean(jvmMetrics, "ThreadsRunnable")); out.write("</td>\n <td>"); out.print( JSONMetricUtil.getValueFromMBean(jvmMetrics, "ThreadsBlocked")); out.write("</td>\n <td>"); out.print( JSONMetricUtil.getValueFromMBean(jvmMetrics, "ThreadsWaiting")); out.write("</td>\n <td>"); out.print( JSONMetricUtil.getValueFromMBean(jvmMetrics, "ThreadsTimedWaiting")); out.write("</td>\n <td>");
public static JsonNode searchJson(JsonNode tree, String searchKey) throws JsonProcessingException, IOException { if (tree == null) { return null; } if(tree.has(searchKey)) { return tree.get(searchKey); } if(tree.isContainerNode()) { for(JsonNode branch: tree) { JsonNode branchResult = searchJson(branch, searchKey); if (branchResult != null && !branchResult.isMissingNode()) { return branchResult; } } } return null; }
@Test public void testBuildHashtable() { String[] keys = {"type", "name"}; String[] emptyKey = {}; String[] values = {"MemoryPool", "Par Eden Space"}; String[] values2 = {"MemoryPool", "Par Eden Space", "Test"}; String[] emptyValue = {}; Map<String, String> properties = JSONMetricUtil.buldKeyValueTable(keys, values); assertEquals(values[0], properties.get("type")); assertEquals(values[1], properties.get("name")); assertNull(JSONMetricUtil.buldKeyValueTable(keys, values2)); assertNull(JSONMetricUtil.buldKeyValueTable(keys, emptyValue)); assertNull(JSONMetricUtil.buldKeyValueTable(emptyKey, values2)); assertNull(JSONMetricUtil.buldKeyValueTable(emptyKey, emptyValue)); }
@Test public void testGetLastGCInfo() { List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); for(GarbageCollectorMXBean bean:gcBeans) { ObjectName on = bean.getObjectName(); Object value = JSONMetricUtil.getValueFromMBean(on, "LastGcInfo"); LOG.info("Collector Info: "+ value); if (value != null && value instanceof CompositeData) { CompositeData cds = (CompositeData)value; assertNotNull(cds.get("duration")); } } } }
@Test public void testSearchJson() throws JsonProcessingException, IOException { String jsonString = "{\"test\":[{\"data1\":100,\"data2\":\"hello\",\"data3\": [1 , 2 , 3]}, " + "{\"data4\":0}]}"; JsonNode node = JSONMetricUtil.mappStringToJsonNode(jsonString); JsonNode r1 = JSONMetricUtil.searchJson(node, "data1"); JsonNode r2 = JSONMetricUtil.searchJson(node, "data2"); JsonNode r3 = JSONMetricUtil.searchJson(node, "data3"); JsonNode r4 = JSONMetricUtil.searchJson(node, "data4"); assertEquals(100, r1.intValue()); assertEquals("hello", r2.textValue()); assertEquals(1, r3.get(0).intValue()); assertEquals(0, r4.intValue()); }
public static JsonNode searchJson(JsonNode tree, String searchKey) throws JsonProcessingException, IOException { if (tree == null) { return null; } if(tree.has(searchKey)) { return tree.get(searchKey); } if(tree.isContainerNode()) { for(JsonNode branch: tree) { JsonNode branchResult = searchJson(branch, searchKey); if (branchResult != null && !branchResult.isMissingNode()) { return branchResult; } } } return null; }
@Test public void testBuildObjectName() throws MalformedObjectNameException { String[] keys = {"type", "name"}; String[] values = {"MemoryPool", "Par Eden Space"}; Hashtable<String, String> properties = JSONMetricUtil.buldKeyValueTable(keys, values); ObjectName testObject = JSONMetricUtil.buildObjectName(JSONMetricUtil.JAVA_LANG_DOMAIN, properties); assertEquals(JSONMetricUtil.JAVA_LANG_DOMAIN, testObject.getDomain()); assertEquals(testObject.getKeyPropertyList(), properties); }
public static long getLastGcDuration(ObjectName gcCollector) { long lastGcDuration = 0; Object lastGcInfo = getValueFromMBean(gcCollector, "LastGcInfo"); if (lastGcInfo != null && lastGcInfo instanceof CompositeData) { CompositeData cds = (CompositeData)lastGcInfo; lastGcDuration = (long) cds.get("duration"); } return lastGcDuration; }
public static long getLastGcDuration(ObjectName gcCollector) { long lastGcDuration = 0; Object lastGcInfo = getValueFromMBean(gcCollector, "LastGcInfo"); if (lastGcInfo != null && lastGcInfo instanceof CompositeData) { CompositeData cds = (CompositeData)lastGcInfo; lastGcDuration = (long) cds.get("duration"); } return lastGcDuration; }
@Test public void testGetLastGCInfo() { List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); for(GarbageCollectorMXBean bean:gcBeans) { ObjectName on = bean.getObjectName(); Object value = JSONMetricUtil.getValueFromMBean(on, "LastGcInfo"); LOG.info("Collector Info: "+ value); if (value != null && value instanceof CompositeData) { CompositeData cds = (CompositeData)value; assertNotNull(cds.get("duration")); } } } }