微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

mbean dump jsp

<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.management.*" %>
<%@ page import="javax.management.*" %>

<!--
  A little JMX Server inspection tool. This JSP allows you to list all attributes on all mbeans
  in all mbean servers in your JVM. We make a reasonable attempt to also print the value of each
  attribute,although we don't dig into the more complex structures. JConsole is a much better
  tool for that.

  And yes,the resulting list is *huge*. :-)

  Written by Kees Jan Koster <[email protected]>
-->

<%!
    private static void spillTheBeans(final Writer out) throws Exception {
        final PrintWriter os = new PrintWriter(out);
        os.println("<table border=1>");

        final List<MBeanServer> servers = new LinkedList<MBeanServer>();
        servers.add(ManagementFactory.getPlatformMBeanServer());
        servers.addAll(MBeanServerFactory.findMBeanServer(null));
        for (final MBeanServer server : servers) {
            os.println("  <tr><td colspan='4'>&nbsp;</td></tr>");
            os.println("  <tr><td>Server:</td><td colspan='3'>"
                    + server.getClass().getName() + "</td></tr>");

            final Set<ObjectName> mbeans = new HashSet<ObjectName>();
            mbeans.addAll(server.queryNames(null,null));
            for (final ObjectName mbean : mbeans) {
                os.println("  <tr><td colspan='4'>&nbsp;</td></tr>");
                os.println("  <tr><td>MBean:</td><td colspan='3'>" + mbean
                        + "</td></tr>");

                final MBeanAttributeInfo[] attributes = server.getMBeanInfo(
                        mbean).getAttributes();
                for (final MBeanAttributeInfo attribute : attributes) {
                    os.print("  <tr><td>&nbsp;</td><td>" + attribute.getName()
                            + "</td><td>" + attribute.getType() + "</td><td>");

                    try {
                        final Object value = server.getAttribute(mbean,attribute.getName());
                        if (value == null) {
                            os.print("<font color='#660000'>null</font>");
                        } else {
                            os.print(value.toString());
                        }
                    } catch (Exception e) {
                        os.print("<font color='#990000'>" + e.getMessage()
                                + "</font>");
                    }

                    os.println("</td></tr>");
                }
            }
        }

        os.println("</table>");
        os.flush();
    }
%>

<html>
  <head><title>Spill the Beans -- JMX Mbean Listing</title></head>
  <body>
    <% spillTheBeans(out); %>
  </body>
</body>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐