Package com.alibaba.druid.stat

Examples of com.alibaba.druid.stat.JdbcDataSourceStat


    private final void internalAfterStatementExecute(StatementProxy statement, boolean firstResult,
                                                     int... updateCountArray) {
        final long nowNano = System.nanoTime();
        final long nanos = nowNano - statement.getLastExecuteStartNano();

        JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
        dataSourceStat.getStatementStat().afterExecute(nanos);

        final JdbcSqlStat sqlStat = statement.getSqlStat();

        if (sqlStat != null) {
            sqlStat.incrementExecuteSuccessCount();
View Full Code Here


        ConnectionProxy connection = statement.getConnectionProxy();
        JdbcConnectionStat.Entry connectionCounter = getConnectionInfo(connection);

        long nanos = System.nanoTime() - statement.getLastExecuteStartNano();

        JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
        dataSourceStat.getStatementStat().error(error);
        dataSourceStat.getStatementStat().afterExecute(nanos);

        connectionCounter.error(error);

        // SQL
        JdbcSqlStat sqlStat = statement.getSqlStat();
View Full Code Here

        return out.toString();
    }

    @Override
    protected void resultSetOpenAfter(ResultSetProxy resultSet) {
        JdbcDataSourceStat dataSourceStat = resultSet.getStatementProxy().getConnectionProxy().getDirectDataSource().getDataSourceStat();
        dataSourceStat.getResultSetStat().beforeOpen();

        resultSet.setConstructNano();

        StatFilterContext.getInstance().resultSet_open();
    }
View Full Code Here

        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) {
View Full Code Here

        return counter;
    }

    public JdbcSqlStat createSqlStat(StatementProxy statement, String sql) {
        DataSourceProxy dataSource = statement.getConnectionProxy().getDirectDataSource();
        JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();

        JdbcStatContext context = JdbcStatManager.getInstance().getStatContext();
        String contextSql = context != null ? context.getSql() : null;
        if (contextSql != null && contextSql.length() > 0) {
            return dataSourceStat.createSqlStat(contextSql);
        } else {
            String dbType = this.dbType;

            if (dbType == null) {
                dbType = dataSource.getDbType();
            }

            sql = mergeSql(sql, dbType);
            return dataSourceStat.createSqlStat(sql);
        }
    }
View Full Code Here

        long nanos = System.nanoTime() - conn.getConnectedTimeNano();

        long millis = nanos / (1000L * 1000L);

        JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
        dataSourceStat.getConnectionHoldHistogram().record(millis);

        StatFilterContext.getInstance().pool_connection_close(nanos);
    }
View Full Code Here

import com.alibaba.druid.stat.JdbcDataSourceStat;

public class JdbcDataSourceStatTest extends TestCase {

    public void test_max() throws Exception {
        JdbcDataSourceStat stat = new JdbcDataSourceStat("", "");

        for (int i = 0; i < 1000 * 10; ++i) {
            stat.createSqlStat("select " + i);
        }

        Assert.assertEquals(1000, stat.getSqlStatMap().size());
    }
View Full Code Here

    }

    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());
    }
View Full Code Here

    }
   
    public void test_max_10_str() 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());
    }
View Full Code Here

        dataSource.setFilters("stat");

        JdbcStatManager.getInstance().reset();

        dataSource.init();
        JdbcDataSourceStat stat = dataSource.getDataSourceStat();

        Assert.assertEquals(0, stat.getConnectionStat().getConnectCount());
        Assert.assertEquals(1, dataSource.getProxyFilters().size());

        for (int i = 0; i < 2; ++i) {
            Connection conn = dataSource.getConnection();

            Assert.assertEquals(1, stat.getConnectionStat().getConnectCount());
            Assert.assertEquals(0, stat.getConnectionStat().getCloseCount());

            conn.close();

            Assert.assertEquals(1, stat.getConnectionStat().getConnectCount());
            Assert.assertEquals(0, stat.getConnectionStat().getCloseCount()); // logic
                                                                              // close不会导致计数器+1
        }

        dataSource.close();

        // Assert.assertEquals(0, JdbcStatManager.getInstance().getDataSources().size());

        Assert.assertEquals(1, stat.getConnectionStat().getConnectCount());
        Assert.assertEquals(1, stat.getConnectionStat().getCloseCount());

        JdbcStatManager.getInstance().reset();

        Assert.assertEquals(1, stat.getConnectionStat().getConnectCount());
        Assert.assertEquals(1, stat.getConnectionStat().getCloseCount());
    }
View Full Code Here

TOP

Related Classes of com.alibaba.druid.stat.JdbcDataSourceStat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.