Springboot visits tomcat’s SlowQueryReport

  jdbc

Order

Tomcat jdbc provides an interceptor like SlowQueryReport, which can be used to record slow query sql that exceeds a threshold. In addition to the jmx access provided by SlowQueryReportJmx, how can ordinary web access relevant statistical information?

Get QueryStats

SlowQueryReport provides a static statistical map, so it can be called directly

@RequestMapping(value = "/slow-sql",method = RequestMethod.GET)
    public Object getSlowSql(){
        return SlowQueryReport.getPoolStats(connectionPool.getPool().getName());
    }

Return instance

{
  "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 represents the maximum time consumption, in milliseconds.
MaxInvocationDate represents the point in time when it occurred