• JMX监控tomcat jdbc pool


    以下二种方式都需要先配置:
    @Bean
    @ConditionalOnExpression("${spring.datasource.jmxEnabled:true}")
    public ConnectionPool jdbcPool(org.apache.tomcat.jdbc.pool.DataSource dataSource) throws SQLException {
    return dataSource.createPool().getJmxPool();
    }

    一、系统中监控

    import javax.management.MBeanAttributeInfo;
    import javax.management.MBeanInfo;
    import javax.management.MBeanServer;
    import javax.management.ObjectName;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.lang.management.ManagementFactory;
    import java.util.Set;
    
    public class MonitorServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
            PrintWriter writer = resp.getWriter();
            writer.println("<!DOCTYPE html>");
            writer.println("<html>");
            writer.println("<body>");
            writer.println("<p><h1>Tomcat Pool</h1></p><p>");
            try {
                MBeanServer server = ManagementFactory.getPlatformMBeanServer();
                Set<ObjectName> objectNames = server.queryNames(null, null);
                for (ObjectName name : objectNames) {
                    MBeanInfo info = server.getMBeanInfo(name);
                    if (info.getClassName().equals(
                            "org.apache.tomcat.jdbc.pool.jmx.ConnectionPool")) {
                        for (MBeanAttributeInfo mf : info.getAttributes()) {
                            Object attributeValue = server.getAttribute(name,
                                    mf.getName());
                            if (attributeValue != null) {
                                writer.println("" + mf.getName() + " : "
                                        + attributeValue.toString() + "<br/>");
    
                            }
                        }
                        break;
                    }
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            writer.println("</p></body>");
            writer.println("</html>");
        }
    }
    
    

    二、jconsole监控

    远程监控需要配置-Dcom.sun.management.jmxremote  -Dcom.sun.management.jmxremote.port=8011  -Dcom.sun.management.jmxremote.ssl=false  -Dcom.sun.management.jmxremote.authenticate=false

    1、cmd 然后输入jconsole,选择应用

    2、

  • 相关阅读:
    Bootstrap下拉菜单的使用(附源码文件)--Bootstrap
    滚动条实现RGB颜色的调制(窗体程序)--JAVA基础
    登录对话框(窗体程序)--JAVA基础
    Bootstrap表格样式(附源码文件)--Bootstrap
    Block 循环引用(中)
    Block 循环引用(上)
    依赖注入
    类型转化
    Block 实践
    动态创建 Plist 文件
  • 原文地址:https://www.cnblogs.com/whmbky/p/14899071.html
Copyright © 2020-2023  润新知