序
tomcat jdbc提供了SlowQueryReport这种的interceptor,可以用来记录超过阈值的慢查询sql,除了SlowQueryReportJmx提供jmx访问外,普通web如何访问相关统计信息呢?
获取QueryStats
SlowQueryReport提供了一个静态统计map出来,因此可以直接调用
@RequestMapping(value = "/slow-sql",method = RequestMethod.GET)
public Object getSlowSql(){
return SlowQueryReport.getPoolStats(connectionPool.getPool().getName());
}
返回实例
{
"select relname from pg_class where relkind='S'": {
"query": "select relname from pg_class where relkind='S'",
"nrOfInvocations": 1,
"maxInvocationTime": 1,
"maxInvocationDate": 1499354543914,
"minInvocationTime": 1,
"minInvocationDate": 1499354543914,
"totalInvocationTime": 1
},
"select authuser0_.id as id1_0_, authuser0_.created_by as created_2_0_, authuser0_.created_date as created_3_0_, authuser0_.last_modified_by as last_mod4_0_, authuser0_.last_modified_date as last_mod5_0_, authuser0_.access_token as access_t6_0_, authuser0_.attachment_type as attachme7_0_, authuser0_.auth_type as auth_typ8_0_, authuser0_.broker_id as broker_i9_0_, authuser0_.deleted as deleted10_0_, authuser0_.dept_name as dept_na11_0_, authuser0_.employee_id as employe12_0_, authuser0_.org_id as org_id13_0_, authuser0_.org_name as org_nam14_0_, authuser0_.position as positio15_0_, authuser0_.principal as princip16_0_, authuser0_.user_name as user_na17_0_, authuser0_.version as version18_0_ from auth_user authuser0_ where ( authuser0_.deleted = 0)": {
"query": "select authuser0_.id as id1_0_, authuser0_.created_by as created_2_0_, authuser0_.created_date as created_3_0_, authuser0_.last_modified_by as last_mod4_0_, authuser0_.last_modified_date as last_mod5_0_, authuser0_.access_token as access_t6_0_, authuser0_.attachment_type as attachme7_0_, authuser0_.auth_type as auth_typ8_0_, authuser0_.broker_id as broker_i9_0_, authuser0_.deleted as deleted10_0_, authuser0_.dept_name as dept_na11_0_, authuser0_.employee_id as employe12_0_, authuser0_.org_id as org_id13_0_, authuser0_.org_name as org_nam14_0_, authuser0_.position as positio15_0_, authuser0_.principal as princip16_0_, authuser0_.user_name as user_na17_0_, authuser0_.version as version18_0_ from auth_user authuser0_ where ( authuser0_.deleted = 0)",
"nrOfInvocations": 1,
"maxInvocationTime": 2,
"maxInvocationDate": 1499354555423,
"minInvocationTime": 2,
"minInvocationDate": 1499354555423,
"totalInvocationTime": 2
}
}
maxInvocationTime表示最大的耗时,毫秒单位;
maxInvocationDate表示发生的时间点
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。