1

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表示发生的时间点


codecraft
11.9k 声望2k 粉丝

当一个代码的工匠回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞愧,这样,当他老的时候,可以很自豪告诉世人,我曾经将代码注入生命去打造互联网的浪潮之巅,那是个很疯狂的时代,我在一波波的浪潮上留下...


引用和评论

0 条评论