camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1351102 - /camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextInfo.java
Date Sun, 17 Jun 2012 12:48:34 GMT
Author: davsclaus
Date: Sun Jun 17 12:48:34 2012
New Revision: 1351102

URL: http://svn.apache.org/viewvc?rev=1351102&view=rev
Log:
CAMEL-5373: Added more stats to Karaf Camel context-info command.

Modified:
    camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextInfo.java

Modified: camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextInfo.java?rev=1351102&r1=1351101&r2=1351102&view=diff
==============================================================================
--- camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextInfo.java
(original)
+++ camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ContextInfo.java
Sun Jun 17 12:48:34 2012
@@ -16,9 +16,10 @@
  */
 package org.apache.camel.karaf.commands;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.Set;
-
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
@@ -59,18 +60,61 @@ public class ContextInfo extends OsgiCom
         System.out.println(StringEscapeUtils.unescapeJava("\tVersion: " + camelContext.getVersion()));
         System.out.println(StringEscapeUtils.unescapeJava("\tStatus: " + camelContext.getStatus()));
         System.out.println(StringEscapeUtils.unescapeJava("\tUptime: " + camelContext.getUptime()));
-        
+
+        // the statistics are in the mbenas
+        ObjectName contextMBean = null;
         MBeanServer mBeanServer = camelContext.getManagementStrategy().getManagementAgent().getMBeanServer();
         Set<ObjectName> set = mBeanServer.queryNames(new ObjectName(DefaultManagementAgent.DEFAULT_DOMAIN
+ ":type=context,name=\"" + name + "\",*"), null);
         Iterator<ObjectName> iterator = set.iterator();
         if (iterator.hasNext()) {
-            ObjectName contextMBean = iterator.next();
+            contextMBean = iterator.next();
+        }
+
+        if (mBeanServer.isRegistered(contextMBean)) {
+            Long exchangesTotal = (Long) mBeanServer.getAttribute(contextMBean, "ExchangesTotal");
+            System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Total: " + exchangesTotal));
+            Long exchangesCompleted = (Long) mBeanServer.getAttribute(contextMBean, "ExchangesCompleted");
+            System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Completed: " +
exchangesCompleted));
+            Long exchangesFailed = (Long) mBeanServer.getAttribute(contextMBean, "ExchangesFailed");
+            System.out.println(StringEscapeUtils.unescapeJava("\tExchanges Failed: " + exchangesFailed));
+            Long minProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "MinProcessingTime");
+            System.out.println(StringEscapeUtils.unescapeJava("\tMin Processing Time: " +
minProcessingTime + "ms"));
+            Long maxProcessingTime = (Long) mBeanServer.getAttribute(contextMBean,  "MaxProcessingTime");
+            System.out.println(StringEscapeUtils.unescapeJava("\tMax Processing Time: " +
maxProcessingTime + "ms"));
+            Long meanProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "MeanProcessingTime");
+            System.out.println(StringEscapeUtils.unescapeJava("\tMean Processing Time: "
+ meanProcessingTime + "ms"));
+            Long totalProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "TotalProcessingTime");
+            System.out.println(StringEscapeUtils.unescapeJava("\tTotal Processing Time: "
+ totalProcessingTime + "ms"));
+            Long lastProcessingTime = (Long) mBeanServer.getAttribute(contextMBean, "LastProcessingTime");
+            System.out.println(StringEscapeUtils.unescapeJava("\tLast Processing Time: "
+ lastProcessingTime + "ms"));
+
             String load01 = (String) mBeanServer.getAttribute(contextMBean, "Load01");
             String load05 = (String) mBeanServer.getAttribute(contextMBean, "Load05");
             String load15 = (String) mBeanServer.getAttribute(contextMBean, "Load15");
             System.out.println(StringEscapeUtils.unescapeJava("\tLoad Avg: " + load01 + ",
" + load05 + ", " + load15));
+
+            // Test for null to see if a any exchanges have been processed first to avoid
NPE
+            Object firstExchangeTimestampObj = mBeanServer.getAttribute(contextMBean, "FirstExchangeCompletedTimestamp");
+            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            if (firstExchangeTimestampObj == null) {
+                // Print an empty value for scripting
+                System.out.println(StringEscapeUtils.unescapeJava("\tFirst Exchange Date:"));
+            } else {
+                Date firstExchangeTimestamp = (Date) firstExchangeTimestampObj;
+                System.out.println(StringEscapeUtils.unescapeJava("\tFirst Exchange Date:
" + format.format(firstExchangeTimestamp)));
+            }
+
+            // Again, check for null to avoid NPE
+            Object lastExchangeCompletedTimestampObj = mBeanServer.getAttribute(contextMBean,
"LastExchangeCompletedTimestamp");
+            if (lastExchangeCompletedTimestampObj == null) {
+                // Print an empty value for scripting
+                System.out.println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed
Date:"));
+            } else {
+                Date lastExchangeCompletedTimestamp = (Date) lastExchangeCompletedTimestampObj;
+                System.out.println(StringEscapeUtils.unescapeJava("\tLast Exchange Completed
Date: " + format.format(lastExchangeCompletedTimestamp)));
+            }
         }
-        
+
         System.out.println("");
         System.out.println(StringEscapeUtils.unescapeJava("\u001B[1mAdvanced\u001B[0m"));
         System.out.println(StringEscapeUtils.unescapeJava("\tAuto Startup: " + camelContext.isAutoStartup()));



Mime
View raw message