tomcat jdbc提供了SlowQueryReport這種的interceptor,能夠用來記錄超過閾值的慢查詢sql,除了SlowQueryReportJmx提供jmx訪問外,普通web如何訪問相關統計信息呢?web
SlowQueryReport提供了一個靜態統計map出來,所以能夠直接調用sql
@RequestMapping(value = "/slow-sql",method = RequestMethod.GET) public Object getSlowSql(){ return SlowQueryReport.getPoolStats(connectionPool.getPool().getName()); }
返回實例tomcat
{ "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表示發生的時間點app