Class SlowQueryReport
java.lang.Object
org.apache.tomcat.jdbc.pool.JdbcInterceptor
org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor
org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport
org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport
- All Implemented Interfaces:
InvocationHandler
- Direct Known Subclasses:
SlowQueryReportJmx
Slow query report interceptor. Tracks timing of query executions.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHolds timing and invocation statistics for a single SQL query.static classCompares QueryStats by their lastInvocation value.Nested classes/interfaces inherited from class AbstractQueryReport
AbstractQueryReport.StatementProxy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanFlag to enable disable logging of failed queriesprotected booleanFlag to enable disable logging of slow queriesprotected intMaximum number of queries we will be storingprotected static final ConcurrentHashMap<String, ConcurrentHashMap<String, SlowQueryReport.QueryStats>> we will be keeping track of query stats on a per pool basisprotected ConcurrentHashMap<String, SlowQueryReport.QueryStats> the queries that are used for this interceptor.protected final Comparator<SlowQueryReport.QueryStats> Sort QueryStats by last invocation timeFields inherited from class AbstractQueryReport
thresholdFields inherited from class AbstractCreateStatementInterceptor
constructors, CREATE_STATEMENT, CREATE_STATEMENT_IDX, EXECUTE, EXECUTE_BATCH, EXECUTE_QUERY, EXECUTE_TYPES, EXECUTE_UPDATE, GET_GENERATED_KEYS, GET_RESULTSET, GET_STATEMENT, PREPARE_CALL, PREPARE_CALL_IDX, PREPARE_STATEMENT, PREPARE_STATEMENT_IDX, RESULTSET_IDX, STATEMENT_TYPE_COUNT, STATEMENT_TYPESFields inherited from class JdbcInterceptor
CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VAL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidinvoked when the connection receives the close request Not used for now.getPoolStats(String poolname) Returns the query stats for a given poolprotected SlowQueryReport.QueryStatsgetQueryStats(String sql) Retrieves or creates a QueryStats entry for the given SQL string.booleanReturns whether failed query logging is enabled.booleanReturns whether slow query logging is enabled.voidpoolClosed(ConnectionPool pool) Removes the query statistics map for the given connection pool.voidpoolStarted(ConnectionPool pool) Initializes the query statistics map for the given connection pool.voidprepareCall(String sql, long time) Tracks the preparation time for a callable statement.voidprepareStatement(String sql, long time) Tracks the preparation time for a prepared statement.protected voidSort QueryStats by last invocation timeprotected StringreportFailedQuery(String query, Object[] args, String name, long start, Throwable t) Invoked when a query execution, a call to execute/executeQuery or executeBatch failed.protected StringreportQuery(String query, Object[] args, String name, long start, long delta) Invoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was within the timing thresholdprotected StringreportSlowQuery(String query, Object[] args, String name, long start, long delta) Invoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was exceeded the timing thresholdvoidreset(ConnectionPool parent, PooledConnection con) Resets the query statistics reference when a connection is reset.voidsetLogFailed(boolean logFailed) Enables or disables failed query logging.voidsetLogSlow(boolean logSlow) Enables or disables slow query logging.voidsetMaxQueries(int maxQueries) Sets the maximum number of queries to track statistics for.voidsetProperties(Map<String, PoolProperties.InterceptorProperty> properties) Configures this interceptor from the given properties map, supporting threshold, maxQueries, logSlow, and logFailed settings.Methods inherited from class AbstractQueryReport
createStatement, getThreshold, setThresholdMethods inherited from class AbstractCreateStatementInterceptor
getConstructor, invoke, isExecute, isStatement, processMethods inherited from class JdbcInterceptor
compare, compare, disconnected, getNext, getProperties, isUseEquals, setNext, setUseEquals
-
Field Details
-
perPoolStats
protected static final ConcurrentHashMap<String, ConcurrentHashMap<String, SlowQueryReport.QueryStats>> perPoolStatswe will be keeping track of query stats on a per pool basis -
queries
the queries that are used for this interceptor. -
maxQueries
protected int maxQueriesMaximum number of queries we will be storing -
logSlow
protected boolean logSlowFlag to enable disable logging of slow queries -
logFailed
protected boolean logFailedFlag to enable disable logging of failed queries -
queryStatsComparator
Sort QueryStats by last invocation time
-
-
Constructor Details
-
SlowQueryReport
public SlowQueryReport()Creates a slow query report interceptor
-
-
Method Details
-
getPoolStats
Returns the query stats for a given pool- Parameters:
poolname- - the name of the pool we want to retrieve stats for- Returns:
- a hash map containing statistics for 0 to maxQueries
-
setMaxQueries
public void setMaxQueries(int maxQueries) Sets the maximum number of queries to track statistics for.- Parameters:
maxQueries- the maximum number of queries
-
reportFailedQuery
protected String reportFailedQuery(String query, Object[] args, String name, long start, Throwable t) Description copied from class:AbstractQueryReportInvoked when a query execution, a call to execute/executeQuery or executeBatch failed.- Overrides:
reportFailedQueryin classAbstractQueryReport- Parameters:
query- the query that was executed and failedargs- the arguments to the executionname- the name of the method used to executeAbstractCreateStatementInterceptor.isExecute(Method, boolean)start- the time the query execution startedt- the exception that happened- Returns:
- - the SQL that was executed or the string "batch" if it was a batch execution
-
reportQuery
Description copied from class:AbstractQueryReportInvoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was within the timing threshold- Overrides:
reportQueryin classAbstractQueryReport- Parameters:
query- the query that was executed and failedargs- the arguments to the executionname- the name of the method used to executeAbstractCreateStatementInterceptor.isExecute(Method, boolean)start- the time the query execution starteddelta- the time the execution took- Returns:
- - the SQL that was executed or the string "batch" if it was a batch execution
-
reportSlowQuery
Description copied from class:AbstractQueryReportInvoked when a query execution, a call to execute/executeQuery or executeBatch succeeded and was exceeded the timing threshold- Overrides:
reportSlowQueryin classAbstractQueryReport- Parameters:
query- the query that was executed and failedargs- the arguments to the executionname- the name of the method used to executeAbstractCreateStatementInterceptor.isExecute(Method, boolean)start- the time the query execution starteddelta- the time the execution took- Returns:
- - the SQL that was executed or the string "batch" if it was a batch execution
-
closeInvoked
public void closeInvoked()invoked when the connection receives the close request Not used for now.- Specified by:
closeInvokedin classAbstractCreateStatementInterceptor
-
prepareStatement
Tracks the preparation time for a prepared statement.- Specified by:
prepareStatementin classAbstractQueryReport- Parameters:
sql- the SQL statementtime- the time taken to prepare the statement
-
prepareCall
Tracks the preparation time for a callable statement.- Specified by:
prepareCallin classAbstractQueryReport- Parameters:
sql- the SQL calltime- the time taken to prepare the call
-
poolStarted
Initializes the query statistics map for the given connection pool.- Overrides:
poolStartedin classJdbcInterceptor- Parameters:
pool- the connection pool that has started
-
poolClosed
Removes the query statistics map for the given connection pool.- Overrides:
poolClosedin classJdbcInterceptor- Parameters:
pool- the connection pool that has been closed
-
getQueryStats
Retrieves or creates a QueryStats entry for the given SQL string.- Parameters:
sql- the SQL query string- Returns:
- the query statistics, or
nullif the pool has been closed
-
removeOldest
Sort QueryStats by last invocation time- Parameters:
queries- The queries map
-
reset
Resets the query statistics reference when a connection is reset.- Overrides:
resetin classAbstractCreateStatementInterceptor- Parameters:
parent- the connection poolcon- the pooled connection being reset
-
isLogSlow
public boolean isLogSlow()Returns whether slow query logging is enabled.- Returns:
trueif slow query logging is enabled
-
setLogSlow
public void setLogSlow(boolean logSlow) Enables or disables slow query logging.- Parameters:
logSlow-trueto enable slow query logging
-
isLogFailed
public boolean isLogFailed()Returns whether failed query logging is enabled.- Returns:
trueif failed query logging is enabled
-
setLogFailed
public void setLogFailed(boolean logFailed) Enables or disables failed query logging.- Parameters:
logFailed-trueto enable failed query logging
-
setProperties
Configures this interceptor from the given properties map, supporting threshold, maxQueries, logSlow, and logFailed settings.- Overrides:
setPropertiesin classJdbcInterceptor- Parameters:
properties- the interceptor properties
-