监控sql执行时间
来源:互联网 发布:centos切换到图形界面 编辑:程序博客网 时间:2024/06/06 14:17
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.lang.time.StopWatch;
import com.njhh.fmcp.log.PortalRunLog;
import com.njhh.fmcp.util.BeanMaker;
import com.njhh.fmcp.util.SystemConfigUtil;
/**
* 监控系统dao执行时间
* @author
*
*/
public class SqlTimeAdvice implements MethodInterceptor{
private PortalRunLog log = (PortalRunLog)BeanMaker.getBean("monitorLog");
private PortalRunLog runLog = (PortalRunLog)BeanMaker.getBean("portalRunLog");
private long time = SystemConfigUtil.getTimeThresholdKey();
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
StopWatch clock = new StopWatch();
// 计时开始
clock.start();
Object result = null;
// 监控的类名
String className = invocation.getMethod().getDeclaringClass().getSimpleName();
//监控的方法名
String methodName = className + "." + invocation.getMethod().getName();
try {
//这个是我们监控的bean的执行并返回结果
result = invocation.proceed();
} catch (Throwable e) {
//监控的参数
runLog.error("数据库执行异常 , 方法名[" + methodName + "]" + " 参数:" + getString(invocation.getArguments()));
throw e;
}
clock.stop(); //计时结束
// 执行超过1秒的sql需要记录到监控日志
if (clock.getTime() >= time){
log.info("执行时间:" + clock.getTime() + " ms [" + methodName + "]" + " 参数:" + getString(invocation.getArguments()));
}
return result;
}
public String getString(Object[] objs) {
StringBuffer stringBuffer = new StringBuffer();
for (Object object : objs) {
stringBuffer.append("[").append(object.toString()).append("],");
}
if (stringBuffer.length() > 0){
stringBuffer.deleteCharAt(stringBuffer.length() - 1);
}
return stringBuffer.toString();
}
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.lang.time.StopWatch;
import com.njhh.fmcp.log.PortalRunLog;
import com.njhh.fmcp.util.BeanMaker;
import com.njhh.fmcp.util.SystemConfigUtil;
/**
* 监控系统dao执行时间
* @author
*
*/
public class SqlTimeAdvice implements MethodInterceptor{
private PortalRunLog log = (PortalRunLog)BeanMaker.getBean("monitorLog");
private PortalRunLog runLog = (PortalRunLog)BeanMaker.getBean("portalRunLog");
private long time = SystemConfigUtil.getTimeThresholdKey();
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
StopWatch clock = new StopWatch();
// 计时开始
clock.start();
Object result = null;
// 监控的类名
String className = invocation.getMethod().getDeclaringClass().getSimpleName();
//监控的方法名
String methodName = className + "." + invocation.getMethod().getName();
try {
//这个是我们监控的bean的执行并返回结果
result = invocation.proceed();
} catch (Throwable e) {
//监控的参数
runLog.error("数据库执行异常 , 方法名[" + methodName + "]" + " 参数:" + getString(invocation.getArguments()));
throw e;
}
clock.stop(); //计时结束
// 执行超过1秒的sql需要记录到监控日志
if (clock.getTime() >= time){
log.info("执行时间:" + clock.getTime() + " ms [" + methodName + "]" + " 参数:" + getString(invocation.getArguments()));
}
return result;
}
public String getString(Object[] objs) {
StringBuffer stringBuffer = new StringBuffer();
for (Object object : objs) {
stringBuffer.append("[").append(object.toString()).append("],");
}
if (stringBuffer.length() > 0){
stringBuffer.deleteCharAt(stringBuffer.length() - 1);
}
return stringBuffer.toString();
}
}
<bean id="SqlProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"
p:beanNames="*Dao,*DaoImpl" p:interceptorNames="sqlTimeAdvice" />
<bean id="sqlTimeAdvice" class="com.njhh.fmcp.interceptor.SqlTimeAdvice" />
0 0
- 监控sql语句执行时间
- 监控sql执行时间
- sql 执行时间
- sql执行时间
- SQL执行时间
- java监控函数执行时间
- net 监控方法执行时间
- StopWatch任务执行时间监控
- 监控GP服务内部执行时间
- spring StopWatch 监控请求执行时间
- 得到SQL语句执行时间
- 统计sql语句执行时间
- 测试SQL语句执行时间
- MS SQL执行时间测试
- 获得sql 语句执行时间
- SQL查询执行时间(毫秒)
- 查看sql语句执行时间
- SqlServer 查询sql执行时间
- spring Requestmapping标签介绍
- 内存泄漏
- ffmpeg直播h.264源卡顿
- Android中SimpleCursorAdapter的使用
- 堆数据结构小结
- 监控sql执行时间
- 真正的中国天气api接口xml,json
- PHP_substr()函数_截取字符串_定义chinesesubstr()函数处理_英文截取_中文截取
- Block阶梯学习_2
- IOS 关键字self,super,copy, retain, assign , readonly , readwrite, nonatomic、@synthesize、@property、@dyna
- Head First PHP&MySQL 学习笔记(二) —— Connect MySQL
- 线程池
- IOS facebook 开源动画引擎 pop
- javascript学习——函数