zoukankan      html  css  js  c++  java
  • JAMon监控SQL执行时间

    JAMon监控web工程方法的调用性能 http://www.cnblogs.com/zfc2201/p/3786365.html

    这往往篇文章主要告诉大家如何监控web方法调用时间,在这个基础这上,如果我们想要监控sql的执行时间,需要增加如下的配置:

    1.增加一个类,假设是com.allen.bookshop.common.MonitorDataSource

    import java.io.PrintWriter;
    import java.sql.Connection;
    import java.sql.SQLException;
    
    import javax.sql.DataSource;
    
    import com.jamonapi.proxy.MonProxyFactory;
    
    public class MonitorDataSource implements DataSource
    {
        private DataSource realDataSource;
    
        public void setRealDataSource( DataSource realDataSource )
        {
            this.realDataSource = realDataSource;
        }
    
        public DataSource getRealDataSource()
        {
            return realDataSource;
        }
    
        public Connection getConnection() throws SQLException
        {
            // 表示由jamon来代理realDataSource返回的Connection
            return MonProxyFactory.monitor( realDataSource.getConnection() );
        }
    
        public Connection getConnection( String username, String password )
                throws SQLException
        {
            // 表示由jamon来代理realDataSource返回的Connection
    
            return MonProxyFactory.monitor( realDataSource.getConnection( username,
                    password ) );
        }
    
        public PrintWriter getLogWriter() throws SQLException
        {
            return realDataSource.getLogWriter();
        }
    
        public int getLoginTimeout() throws SQLException
        {
            return realDataSource.getLoginTimeout();
        }
    
        public void setLogWriter( PrintWriter out ) throws SQLException
        {
            realDataSource.setLogWriter( out );
        }
    
        public void setLoginTimeout( int seconds ) throws SQLException
        {
            realDataSource.setLoginTimeout( seconds );
        }
    }

    2.对数据源进行配置:

        <bean id="dataSource" class="com.allen.bookshop.common.MonitorDataSource" destroy-method="close">  
            <property name="realDataSource" ref="basicDataSource"/>  
        </bean>
       <bean id="basicDataSource" class="org.apache.commons.dbcp.BasicDataSource"
            destroy-method="close">
            <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
            <property name="url" value="jdbc:oracle:thin:@192.168.0.11:1521:orcl" />
            <property name="username" value="orcl" />
            <property name="password" value="orcl" />
            <property name="initialSize" value="20" />
            <property name="maxActive" value="50" />
            <property name="defaultAutoCommit" value="true" />   
        </bean>

    至此,配置完成,现在可以访问:http://localhost:8080/bookshop/jamon/sql.jsp查看sql的执行时间了。

  • 相关阅读:
    2016 Multi-University Training Contest 1 solutions BY HIT
    Unicode 码表
    用 lambda 表达式 对 List 进行排序
    Linux的sed命令介绍
    Linux下的NTP服务搭建
    Linux网络配置(ip命令及配置文件)
    Linux的bash脚本编程(if语句和循环语句)
    Linux新手必须掌握的命令(2)
    Linux的文件查找
    bash中的变量
  • 原文地址:https://www.cnblogs.com/zfc2201/p/3786383.html
Copyright © 2011-2022 走看看