mybatis sql 监控插件

来源:互联网 发布:谷歌浏览器mac 编辑:程序博客网 时间:2024/06/05 11:08

1、拦截器代码

@Intercepts({        @Signature(type = StatementHandler.class, method = "update", args = { Statement.class }),        @Signature(type = StatementHandler.class, method = "query", args = { Statement.class, ResultHandler.class})})public class SQLTimeInterceptor implements Interceptor {    private static final Logger logger = LoggerFactory.getLogger(SQLTimeInterceptor.class);    @Override    public Object intercept(Invocation invocation) throws Throwable {        long start = System.currentTimeMillis();        Object object = invocation.proceed();        long end = System.currentTimeMillis();        if (end - start > 200){            QMonitor.recordOne(QMonitorKey.SQLMonitor.SLOW_SQL_WITHOUT_GET_CONNECTION_TIME, end - start);            logger.info("slow sql with out get connection, time: {}", end - start);        }        return object;    }    @Override    public Object plugin(Object target) {        return Plugin.wrap(target, this);    }    @Override    public void setProperties(Properties properties) {    }}

2、mybatis-config.xml "com.qunar.hotel.qta.order_audit.core.filter.SQLExceptionInterceptor" />  "com.qunar.hotel.qta.order_audit.core.filter.SQLTimeInterceptor" /> 
0 0
原创粉丝点击