geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccard...@apache.org
Subject svn commit: r509483 - in /geronimo/server/trunk/applications/console/geronimo-console-standard/src/main: java/org/apache/geronimo/console/jmxmanager/JMXManagerHelper.java webapp/WEB-INF/view/jmxmanager/viewJMXServer.jsp
Date Tue, 20 Feb 2007 09:55:06 GMT
Author: ccardona
Date: Tue Feb 20 01:55:05 2007
New Revision: 509483

URL: http://svn.apache.org/viewvc?view=rev&rev=509483
Log:
GERONIMO-2853 Add a way to view MBean stats info in the JMX Viewer portlet

Modified:
    geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/jmxmanager/JMXManagerHelper.java
    geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/webapp/WEB-INF/view/jmxmanager/viewJMXServer.jsp

Modified: geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/jmxmanager/JMXManagerHelper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/jmxmanager/JMXManagerHelper.java?view=diff&rev=509483&r1=509482&r2=509483
==============================================================================
--- geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/jmxmanager/JMXManagerHelper.java
(original)
+++ geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/java/org/apache/geronimo/console/jmxmanager/JMXManagerHelper.java
Tue Feb 20 01:55:05 2007
@@ -21,8 +21,10 @@
 import java.net.URL;
 import java.text.DateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -30,6 +32,13 @@
 import java.util.TreeMap;
 
 import javax.management.ObjectName;
+import javax.management.j2ee.statistics.BoundaryStatistic;
+import javax.management.j2ee.statistics.BoundedRangeStatistic;
+import javax.management.j2ee.statistics.CountStatistic;
+import javax.management.j2ee.statistics.RangeStatistic;
+import javax.management.j2ee.statistics.Statistic;
+import javax.management.j2ee.statistics.Stats;
+import javax.management.j2ee.statistics.TimeStatistic;
 
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
@@ -47,8 +56,11 @@
 public class JMXManagerHelper {
     /** Used to return all MBeans */
     private static final String ALL_MBEANS = "AllMBeans";
-    private static final String GBEANINFO_NAME = "GBeanInfo";
     private static final String SERVICEMODULE_KEY = "ServiceModule";
+    private static final String GBEANINFO_ATTRIB = "GBeanInfo";
+    private static final String STATSPROVIDER_ATTRIB = "statisticsProvider";
+    private static final String STATS_ATTRIB = "stats";
+    
 
     private final Kernel kernel;
 
@@ -220,7 +232,7 @@
                 GAttributeInfo attribInfo = (GAttributeInfo) i.next();
                 // Don't include 'GBeanInfo' attributes
                 String attribName = attribInfo.getName();
-                if (!GBEANINFO_NAME.equals(attribName)) {
+                if (!GBEANINFO_ATTRIB.equals(attribName)) {
                     Map attribInfoMap = getAttribInfoAsMap(aname, attribInfo);
                     attributes.put(attribName, attribInfoMap);
                 }
@@ -252,7 +264,12 @@
             try {
                 Object value = kernel.getAttribute(abstractName, attribName);
                 if (value != null) {
-                    attribValue = value.toString();
+                    if (value instanceof String[]) {
+                        attribValue = Arrays.asList((String[]) value)
+                                .toString();
+                    } else {
+                        attribValue = value.toString();
+                    }
                 }
             } catch (Exception e) {
                 // GBean or attribute not found, just ignore
@@ -320,6 +337,129 @@
         }
 
         return info;
+    }
+
+    /**
+     * Return all MBeans that provide stats
+     */
+    public Collection getStatsProvidersMBeans() {
+        Collection result = new ArrayList();
+
+        Object[] allMBeans = listByPattern("*:*").toArray();
+        for (int i = 0; i < allMBeans.length; i++) {
+            try {
+                String[] mbean = (String[]) allMBeans[i];
+                AbstractName abstractName = new AbstractName(URI
+                        .create(mbean[0]));
+                Boolean statisticsProvider = (Boolean) kernel.getAttribute(
+                        abstractName, "statisticsProvider");
+                if (Boolean.TRUE.equals(statisticsProvider)) {
+                    result.add(mbean);
+                }
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * Return MBean stats
+     */
+    public Collection getMBeanStats(String abstractName) {
+        Map mbeanStats = new TreeMap();
+        try {
+            AbstractName aname = new AbstractName(URI.create(abstractName));
+            Boolean statisticsProvider = (Boolean) kernel.getAttribute(aname,
+                    STATSPROVIDER_ATTRIB);
+            Stats stats = (Stats) kernel.getAttribute(aname, STATS_ATTRIB);
+            if (statisticsProvider.booleanValue() == true && (stats != null)) {
+                String[] statisticNames = stats.getStatisticNames();
+                for (int i = 0; i < statisticNames.length; i++) {
+                    Statistic statistic = stats.getStatistic(statisticNames[i]);
+
+                    Collection mbeanStat = new ArrayList();
+                    String name = statistic.getName();
+                    mbeanStat.add(new String[] { "Name", name });
+                    String className = statistic.getClass().getName();
+                    // mbeanStat.add(new String[] { "Type", className });
+                    mbeanStat.add(new String[] { "Description",
+                            statistic.getDescription() });
+                    mbeanStat.add(new String[] { "Unit", statistic.getUnit() });
+                    Date startTime = new Date(statistic.getStartTime());
+                    mbeanStat.add(new String[] { "Start Time",
+                            startTime.toString() });
+                    Date lastSampleTime = new Date(statistic
+                            .getLastSampleTime());
+                    mbeanStat.add(new String[] { "Last Sample Time",
+                            lastSampleTime.toString() });
+
+                    if (statistic instanceof CountStatistic) {
+                        CountStatistic cStat = (CountStatistic) statistic;
+                        long count = cStat.getCount();
+                        mbeanStat.add(new String[] { "Count",
+                                Long.toString(count) });
+                    } else if (statistic instanceof BoundaryStatistic) {
+                        BoundaryStatistic bStat = (BoundaryStatistic) statistic;
+                        long upperBound = bStat.getUpperBound();
+                        mbeanStat.add(new String[] { "Upper Bound",
+                                Long.toString(upperBound) });
+                        long lowerBound = bStat.getLowerBound();
+                        mbeanStat.add(new String[] { "Lower Bound",
+                                Long.toString(lowerBound) });
+                    } else if (statistic instanceof RangeStatistic) {
+                        RangeStatistic rStat = (RangeStatistic) statistic;
+                        long highWaterMark = rStat.getHighWaterMark();
+                        mbeanStat.add(new String[] { "High Water Mark",
+                                Long.toString(highWaterMark) });
+                        long lowWaterMark = rStat.getLowWaterMark();
+                        mbeanStat.add(new String[] { "Low Water Mark",
+                                Long.toString(lowWaterMark) });
+                        long current = rStat.getCurrent();
+                        mbeanStat.add(new String[] { "Current",
+                                Long.toString(current) });
+                    } else if (statistic instanceof TimeStatistic) {
+                        TimeStatistic tStat = (TimeStatistic) statistic;
+                        long count = tStat.getCount();
+                        mbeanStat.add(new String[] { "Count",
+                                Long.toString(count) });
+                        long maxTime = tStat.getMaxTime();
+                        mbeanStat.add(new String[] { "Max Time",
+                                Long.toString(maxTime) });
+                        long minTime = tStat.getMinTime();
+                        mbeanStat.add(new String[] { "Min Time",
+                                Long.toString(minTime) });
+                        long totalTime = tStat.getTotalTime();
+                        mbeanStat.add(new String[] { "Total Time",
+                                Long.toString(totalTime) });
+                    } else if (statistic instanceof BoundedRangeStatistic) {
+                        BoundedRangeStatistic brStat = (BoundedRangeStatistic) statistic;
+                        long upperBound = brStat.getUpperBound();
+                        mbeanStat.add(new String[] { "Upper Bound",
+                                Long.toString(upperBound) });
+                        long lowerBound = brStat.getLowerBound();
+                        mbeanStat.add(new String[] { "Lower Bound",
+                                Long.toString(lowerBound) });
+                        long highWaterMark = brStat.getHighWaterMark();
+                        mbeanStat.add(new String[] { "High Water Mark",
+                                Long.toString(highWaterMark) });
+                        long lowWaterMark = brStat.getLowWaterMark();
+                        mbeanStat.add(new String[] { "Low Water Mark",
+                                Long.toString(lowWaterMark) });
+                        long current = brStat.getCurrent();
+                        mbeanStat.add(new String[] { "Current",
+                                Long.toString(current) });
+                    }
+
+                    mbeanStats.put(name, mbeanStat);
+                }
+            }
+        } catch (Exception e) {
+            // GBean not found, just ignore
+        }
+
+        return mbeanStats.values();
     }
 
     /**

Modified: geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/webapp/WEB-INF/view/jmxmanager/viewJMXServer.jsp
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/webapp/WEB-INF/view/jmxmanager/viewJMXServer.jsp?view=diff&rev=509483&r1=509482&r2=509483
==============================================================================
--- geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/webapp/WEB-INF/view/jmxmanager/viewJMXServer.jsp
(original)
+++ geronimo/server/trunk/applications/console/geronimo-console-standard/src/main/webapp/WEB-INF/view/jmxmanager/viewJMXServer.jsp
Tue Feb 20 01:55:05 2007
@@ -179,6 +179,9 @@
                                 // Remove service module marker
                 			    var svcModule = id.substring(id.indexOf('<SVCMODULE>') + '<SVCMODULE>'.length);
 
                 			    JMXHelper.listBySubstring(<portlet:namespace/>updateJMXTree,
svcModule);
+                            } else if (selectedNode.widgetId == 'statisticsProviderMBeans')
{
+                                // Get statistics provider MBeans
+                			    JMXHelper.getStatsProvidersMBeans(<portlet:namespace/>updateJMXTree);
                             } else {
                                 // Marker not recognized
                             }
@@ -208,6 +211,7 @@
     			    JMXHelper.getMBeanInfo(<portlet:namespace/>updateBasicInfoTable, abstractName);
     			    JMXHelper.getAttributes(<portlet:namespace/>updateAttributesTable, abstractName);
     			    JMXHelper.getOperations(<portlet:namespace/>updateOperationsTable, abstractName);
+    			    JMXHelper.getMBeanStats(<portlet:namespace/>updateStatsTable, abstractName);
     			}
 			}
 		);
@@ -308,6 +312,23 @@
 			    mainTabContainer.selectTab(infoTab);
             }
 		);
+
+        /**
+         * Tree context menu event handler: 'View Stats' 
+         */
+		dojo.event.topic.subscribe(
+		    'treeContextMenuViewStats/engage',
+			function (menuItem) {
+			    var selectedNode = getSelectedNode();
+                if (selectedNode == null) {
+                    alert('Please select a tree node.');
+                    return;
+                }
+			    var mainTabContainer = dojo.widget.byId('mainTabContainer');
+			    var statsTab = dojo.widget.byId('statsTab');
+			    mainTabContainer.selectTab(statsTab);
+            }
+		);
     }
 );
 
@@ -527,6 +548,37 @@
 }
 
 /**
+ * Update MBean stats table
+ */
+function <portlet:namespace/>updateStatsTable(stats) {
+    DWRUtil.removeAllRows('statsTableBody');
+    DWRUtil.addRows(
+        'statsTableBody', 
+        stats,
+        [
+            function(stat) { /* StatisticName Column */
+                var name = "<div align='right'>" + stat[0][1] + ":&nbsp;</div>";
+                return name;
+            },
+            function(stat) { /* StatisticValue Column */
+                var value = '';
+                for (var i = 1; i < stat.length; i++) {
+                    value += '<b>' + stat[i][0] + ':</b> ' + stat[i][1] + '<br>';
+                }
+                return value;
+            }
+        ],
+        tableOption
+    );
+    
+    // Render sortable table
+	var tbl = dojo.widget.byId("statsTable");
+	if (tbl) {
+	    tbl.render(false);
+	}
+}
+
+/**
  * Update 'Search MBeans' tree node 
  */
 function <portlet:namespace/>updateSearchMBeansTreeNode(searchResult) {
@@ -687,6 +739,7 @@
 	<div dojoType="TreeMenuItem" treeActions="view" widgetId="treeContextMenuViewAttribs"
caption="View Attributes"></div>
 	<div dojoType="TreeMenuItem" treeActions="view" widgetId="treeContextMenuViewOps" caption="View
Operations"></div>
 	<div dojoType="TreeMenuItem" treeActions="view" widgetId="treeContextMenuViewInfo" caption="View
Info"></div>
+	<div dojoType="TreeMenuItem" treeActions="view" widgetId="treeContextMenuViewStats" caption="View
Stats"></div>
 </div>
 
 <div dojoType="TreeSelector" widgetId="treeSelector"></div>
@@ -821,6 +874,10 @@
          	    </c:forEach>
             </div>
 
+         	<!-- Statistics Provider MBeans -->
+         	<div dojoType="TreeNode" title="Statistics Provider MBeans" widgetId="statisticsProviderMBeans"
isFolder="true" childIconSrc="<%= jmxIconURI %>" actionsDisabled="view">
+            </div>
+
             <!-- Search MBeans -->
          	<div dojoType="TreeNode" title="Search MBeans" widgetId="searchMBeans" isFolder="true"
childIconSrc="<%= jmxIconURI %>" actionsDisabled="view">
          	</div>
@@ -899,6 +956,30 @@
                     </tbody>
                 </table>
             </div> <!-- Info tab -->
+
+            <!-- Stats tab -->
+    		<div id="statsTab" dojoType="ContentPane" title="MBean Stats" label="Stats" style="overflow:
auto">
+    		    <br>
+            	<table dojoType="SortableTable" 
+            	    widgetId="statsTable" 
+            	    tbodyClass="scrollContent" 
+            	    enableMultipleSelect="true" 
+            	    enableAlternateRows="true" 
+            	    rowAlternateClass="alternateRow" 
+            	    cellpadding="0" 
+            	    cellspacing="2" 
+            	    border="0"
+            	    width="100%">
+                    <thead>
+                        <tr>
+                            <th field="Name" dataType="String" width="30%">&nbsp;Name&nbsp;</th>
+                            <th dataType="html" width="70%">&nbsp;Value&nbsp;</th>
+                        </tr>
+                    </thead>
+                    <tbody id="statsTableBody">
+                    </tbody>
+                </table>
+            </div> <!-- Stats tab -->
 
             <!-- Search tab -->
             <div id="searchTab" dojoType="ContentPane" title="Search" label="Search" style="overflow:
auto">



Mime
View raw message