Author: markt
Date: Thu Mar 15 22:49:06 2012
New Revision: 1301256

URL: http://svn.apache.org/viewvc?rev=1301256&view=rev
Log:
Added support to the JMXProxyServlet for fetching a specific key from a 
CompositeData value.
Added documentation for the entire 'get' command for the JMXProxyServlet, 
including the new optional 'key' parameter.
Backport of patch by schultz

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java
    tomcat/tc7.0.x/trunk/webapps/docs/manager-howto.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Mar 15 22:49:06 2012
@@ -1 +1 @@
-/tomcat/trunk:1156115-1157160,1157162-1157859,1157862-1157942,1157945-1160347,1160349-1163716,1163718-1166689,1166691-1174340,1174342-1175596,1175598-1175611,1175613-1175932,1175934-1177783,1177785-1177980,1178006-1180720,1180722-1183094,1183096-1187753,1187755,1187775,1187801,1187806,1187809,1187826-1188312,1188314-1188401,1188646-1188840,1188842-1190176,1190178-1195223,1195225-1195953,1195955,1195957-1201238,1201240-1203345,1203347-1206623,1206625-1208046,1208073,1208096,1208114,1208145,1208772,1209194-1212125,1212127-1220291,1220293,1220295-1221321,1221323-1222328,1222332-1222401,1222405-1222795,1222850-1222950,1222969-1225326,1225328-1225463,1225465,1225627,1225629-1226534,1226536-1228908,1228911-1228923,1228927-1229532,1229534-1230766,1230768-1231625,1231627-1233414,1233419-1235207,1235209-1237425,1237427,1237429-1237977,1237981,1237985,1238070,1238073,1239024-1239048,1239050-1239062,1239135,1239256,1239258-1239485,1240101,1240106,1240109,1240112,1240114,1240116,1240118
 
,1240121,1240329,1240697,1240795,1240821,1240842,1240857,1241087,1241160,1241908-1241909,1241982,1242099,1242110,1242371,1242434,1242495,1242947,1243034,1243038,1244302,1244511,1244567,1244718-1244719,1244935-1244938,1245274,1245449,1245849,1290875,1292334,1292338,1292345-1292347,1293155,1293831-1293832,1295998,1296284,1297014-1297015,1297017,1297158,1297177,1297202,1297209,1297213,1297717,1297722,1297729,1297768,1297778,1297818,1297828,1297979,1297987,1298121,1298140,1298590,1298592,1298628-1298629,1298794,1298983-1298984,1299020,1299034,1299819,1300154-1300155,1300569,1300948
+/tomcat/trunk:1156115-1157160,1157162-1157859,1157862-1157942,1157945-1160347,1160349-1163716,1163718-1166689,1166691-1174340,1174342-1175596,1175598-1175611,1175613-1175932,1175934-1177783,1177785-1177980,1178006-1180720,1180722-1183094,1183096-1187753,1187755,1187775,1187801,1187806,1187809,1187826-1188312,1188314-1188401,1188646-1188840,1188842-1190176,1190178-1195223,1195225-1195953,1195955,1195957-1201238,1201240-1203345,1203347-1206623,1206625-1208046,1208073,1208096,1208114,1208145,1208772,1209194-1212125,1212127-1220291,1220293,1220295-1221321,1221323-1222328,1222332-1222401,1222405-1222795,1222850-1222950,1222969-1225326,1225328-1225463,1225465,1225627,1225629-1226534,1226536-1228908,1228911-1228923,1228927-1229532,1229534-1230766,1230768-1231625,1231627-1233414,1233419-1235207,1235209-1237425,1237427,1237429-1237977,1237981,1237985,1238070,1238073,1239024-1239048,1239050-1239062,1239135,1239256,1239258-1239485,1239785-1240046,1240101,1240106,1240109,1240112,1240114
 
,1240116,1240118,1240121,1240329,1240697,1240795,1240821,1240842,1240857,1241087,1241160,1241908-1241909,1241982,1242099,1242110,1242371,1242434,1242495,1242947,1243034,1243038,1244302,1244511,1244567,1244718-1244719,1244935-1244938,1245274,1245449,1245849,1290875,1292334,1292338,1292345-1292347,1293155,1293831-1293832,1295998,1296284,1297014-1297015,1297017,1297158,1297177,1297202,1297209,1297213,1297717,1297722,1297729,1297768,1297778,1297818,1297828,1297979,1297987,1298121,1298140,1298590,1298592,1298628-1298629,1298794,1298983-1298984,1299020,1299034,1299819,1300154-1300155,1300569,1300948

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java?rev=1301256&r1=1301255&r2=1301256&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/manager/JMXProxyServlet.java 
Thu Mar 15 22:49:06 2012
@@ -25,6 +25,7 @@ import javax.management.MBeanOperationIn
 import javax.management.MBeanParameterInfo;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -97,7 +98,7 @@ public class JMXProxyServlet extends Htt
         qry=request.getParameter("get");
         if( qry!= null ) {
             String name=request.getParameter("att");
-            getAttribute( writer, qry, name );
+            getAttribute( writer, qry, name, request.getParameter("key") );
             return;
         }        
         qry = request.getParameter("invoke");
@@ -122,18 +123,35 @@ public class JMXProxyServlet extends Htt
 
     }
 
-    public void getAttribute(PrintWriter writer, String onameStr, String att) {
+    public void getAttribute(PrintWriter writer, String onameStr, String att, 
String key) {
         try {
             ObjectName oname = new ObjectName(onameStr);
             Object value = mBeanServer.getAttribute(oname, att);
+
+            if(null != key && value instanceof CompositeData)
+              value = ((CompositeData)value).get(key);
+
             String valueStr;
             if (value != null) {
                 valueStr = value.toString();
             } else {
                 valueStr = "<null>";
             }
-            writer.println("OK - Attribute get '" + onameStr + "' - " + att
-                    + "= " + MBeanDumper.escape(valueStr));
+
+            writer.print("OK - Attribute get '");
+            writer.print(onameStr);
+            writer.print("' - ");
+            writer.print(att);
+
+            if(null != key) {
+                writer.print(" - key '");
+                writer.print(key);
+                writer.print("'");
+            }
+
+            writer.print(" = ");
+
+            writer.println(MBeanDumper.escape(valueStr));
         } catch (Exception ex) {
             writer.println("Error - " + ex.toString());
             ex.printStackTrace(writer);

Modified: tomcat/tc7.0.x/trunk/webapps/docs/manager-howto.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/manager-howto.xml?rev=1301256&r1=1301255&r2=1301256&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/manager-howto.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/manager-howto.xml Thu Mar 15 22:49:06 2012
@@ -1265,6 +1265,37 @@ http://webserver/manager/jmxproxy/?qry=S
     you may run.
   </subsection>
 
+  <subsection name="JMX Get command">
+    The JXMProxyServlet also supports a "get" command that you can use to
+    fetch the value of a specific MBean's attribute. The general form of
+    the <code>get</code> command is:
+
+    <source>
+      
http://webserver/manager/jmxproxy/?get=BEANNAME&amp;att=MYATTRIBUTE&amp;key=MYKEY
+    </source>
+
+    You must provide the following parameters:
+    <ol>
+      <li><code>get</code>: The full bean name</li>
+      <li><code>att</code>: The attribute you wish to fetch</li>
+      <li><code>key</code>: (optional) The key into a CompositeData MBean 
attribute</li>
+    </ol>
+
+    If all goes well, then it will say OK, otherwise an error message will
+    be shown. For example, let's say we wish to fetch the current heap memory
+    data:
+
+    <source>
+      
http://webserver/manager/jmxproxy/?get=java.lang:type=Memory&amp;att=HeapMemoryUsage
+    </source>
+
+    Or, if you only want the "used" key:
+
+    <source>
+      
http://webserver/manager/jmxproxy/?get=java.lang:type=Memory&amp;att=HeapMemoryUsage&amp;key=used
+    </source>
+  </subsection>
+
   <subsection name="JMX Set command">
     Now that you can query an MBean, its time to muck with Tomcat's internals!
     The general form of the set command is :



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to