Search in sources :

Example 16 with JdbcDataSourceStat

use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.

the class StatFilter method connection_rollback.

@Override
public void connection_rollback(FilterChain chain, ConnectionProxy connection) throws SQLException {
    chain.connection_rollback(connection);
    JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
    dataSourceStat.getConnectionStat().incrementConnectionRollbackCount();
    dataSourceStat.getConnectionStat().incrementConnectionRollbackCount();
}
Also used : JdbcDataSourceStat(com.alibaba.druid.stat.JdbcDataSourceStat)

Example 17 with JdbcDataSourceStat

use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.

the class StatFilter method resultSet_close.

@Override
public void resultSet_close(FilterChain chain, ResultSetProxy resultSet) throws SQLException {
    long nanos = System.nanoTime() - resultSet.getConstructNano();
    int fetchRowCount = resultSet.getFetchRowCount();
    JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
    dataSourceStat.getResultSetStat().afterClose(nanos);
    dataSourceStat.getResultSetStat().addFetchRowCount(fetchRowCount);
    dataSourceStat.getResultSetStat().incrementCloseCounter();
    StatFilterContext.getInstance().addFetchRowCount(fetchRowCount);
    String sql = resultSet.getSql();
    if (sql != null) {
        JdbcSqlStat sqlStat = resultSet.getSqlStat();
        if (sqlStat != null && resultSet.getCloseCount() == 0) {
            sqlStat.addFetchRowCount(fetchRowCount);
            long stmtExecuteNano = resultSet.getStatementProxy().getLastExecuteTimeNano();
            sqlStat.addResultSetHoldTimeNano(stmtExecuteNano, nanos);
            if (resultSet.getReadStringLength() > 0) {
                sqlStat.addStringReadLength(resultSet.getReadStringLength());
            }
            if (resultSet.getReadBytesLength() > 0) {
                sqlStat.addReadBytesLength(resultSet.getReadBytesLength());
            }
            if (resultSet.getOpenInputStreamCount() > 0) {
                sqlStat.addInputStreamOpenCount(resultSet.getOpenInputStreamCount());
            }
            if (resultSet.getOpenReaderCount() > 0) {
                sqlStat.addReaderOpenCount(resultSet.getOpenReaderCount());
            }
        }
    }
    chain.resultSet_close(resultSet);
    StatFilterContext.getInstance().resultSet_close(nanos);
}
Also used : JdbcSqlStat(com.alibaba.druid.stat.JdbcSqlStat) JdbcDataSourceStat(com.alibaba.druid.stat.JdbcDataSourceStat) Savepoint(java.sql.Savepoint)

Example 18 with JdbcDataSourceStat

use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.

the class StatFilter method connection_commit.

@Override
public void connection_commit(FilterChain chain, ConnectionProxy connection) throws SQLException {
    chain.connection_commit(connection);
    JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
    dataSourceStat.getConnectionStat().incrementConnectionCommitCount();
}
Also used : JdbcDataSourceStat(com.alibaba.druid.stat.JdbcDataSourceStat)

Example 19 with JdbcDataSourceStat

use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.

the class StatFilter method internalBeforeStatementExecute.

private final void internalBeforeStatementExecute(StatementProxy statement, String sql) {
    JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
    dataSourceStat.getStatementStat().beforeExecute();
    final ConnectionProxy connection = statement.getConnectionProxy();
    final JdbcConnectionStat.Entry connectionCounter = getConnectionInfo(connection);
    statement.setLastExecuteStartNano();
    connectionCounter.setLastSql(sql);
    if (connectionStackTraceEnable) {
        connectionCounter.setLastStatementStatckTrace(new Exception());
    }
    // //////////SQL
    JdbcSqlStat sqlStat = statement.getSqlStat();
    if (sqlStat == null || sqlStat.isRemoved()) {
        sqlStat = createSqlStat(statement, sql);
        statement.setSqlStat(sqlStat);
    }
    JdbcStatContext statContext = JdbcStatManager.getInstance().getStatContext();
    if (statContext != null) {
        sqlStat.setName(statContext.getName());
        sqlStat.setFile(statContext.getFile());
    }
    boolean inTransaction = false;
    try {
        inTransaction = !statement.getConnectionProxy().getAutoCommit();
    } catch (SQLException e) {
        LOG.error("getAutoCommit error", e);
    }
    if (sqlStat != null) {
        sqlStat.setExecuteLastStartTime(System.currentTimeMillis());
        sqlStat.incrementRunningCount();
        if (inTransaction) {
            sqlStat.incrementInTransactionCount();
        }
    }
    StatFilterContext.getInstance().executeBefore(sql, inTransaction);
    Profiler.enter(sql, Profiler.PROFILE_TYPE_SQL);
}
Also used : JdbcSqlStat(com.alibaba.druid.stat.JdbcSqlStat) SQLException(java.sql.SQLException) JdbcDataSourceStat(com.alibaba.druid.stat.JdbcDataSourceStat) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy) JdbcConnectionStat(com.alibaba.druid.stat.JdbcConnectionStat) SQLException(java.sql.SQLException) JdbcStatContext(com.alibaba.druid.stat.JdbcStatContext)

Example 20 with JdbcDataSourceStat

use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.

the class JdbcDataSourceStatTest method test_max_10.

public void test_max_10() throws Exception {
    Properties connectProperties = new Properties();
    connectProperties.put(Constants.DRUID_STAT_SQL_MAX_SIZE, 10);
    JdbcDataSourceStat stat = new JdbcDataSourceStat("", "", "mysql", connectProperties);
    for (int i = 0; i < 1000 * 1; ++i) {
        stat.createSqlStat("select " + i);
    }
    Assert.assertEquals(10, stat.getSqlStatMap().size());
}
Also used : JdbcDataSourceStat(com.alibaba.druid.stat.JdbcDataSourceStat) Properties(java.util.Properties)

Aggregations

JdbcDataSourceStat (com.alibaba.druid.stat.JdbcDataSourceStat)25 JdbcSqlStat (com.alibaba.druid.stat.JdbcSqlStat)6 SQLException (java.sql.SQLException)4 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 JdbcConnectionStat (com.alibaba.druid.stat.JdbcConnectionStat)3 JdbcStatContext (com.alibaba.druid.stat.JdbcStatContext)3 Connection (java.sql.Connection)3 Properties (java.util.Properties)3 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)2 Savepoint (java.sql.Savepoint)2 HashMap (java.util.HashMap)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 Filter (com.alibaba.druid.filter.Filter)1 FilterChain (com.alibaba.druid.filter.FilterChain)1 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)1 StatFilter (com.alibaba.druid.filter.stat.StatFilter)1 MockDriver (com.alibaba.druid.mock.MockDriver)1 DataSourceProxy (com.alibaba.druid.proxy.jdbc.DataSourceProxy)1 DataSourceProxyConfig (com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig)1 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)1