use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.
the class StatFilter method connection_connect.
public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
ConnectionProxy connection = null;
long startNano = System.nanoTime();
long startTime = System.currentTimeMillis();
long nanoSpan;
long nowTime = System.currentTimeMillis();
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
dataSourceStat.getConnectionStat().beforeConnect();
try {
connection = chain.connection_connect(info);
nanoSpan = System.nanoTime() - startNano;
} catch (SQLException ex) {
dataSourceStat.getConnectionStat().connectError(ex);
throw ex;
}
dataSourceStat.getConnectionStat().afterConnected(nanoSpan);
if (connection != null) {
JdbcConnectionStat.Entry statEntry = getConnectionInfo(connection);
dataSourceStat.getConnections().put(connection.getId(), statEntry);
statEntry.setConnectTime(new Date(startTime));
statEntry.setConnectTimespanNano(nanoSpan);
statEntry.setEstablishNano(System.nanoTime());
statEntry.setEstablishTime(nowTime);
statEntry.setConnectStackTrace(new Exception());
dataSourceStat.getConnectionStat().setActiveCount(dataSourceStat.getConnections().size());
}
return connection;
}
use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.
the class StatFilter method resultSetOpenAfter.
@Override
protected void resultSetOpenAfter(ResultSetProxy resultSet) {
JdbcDataSourceStat dataSourceStat = resultSet.getStatementProxy().getConnectionProxy().getDirectDataSource().getDataSourceStat();
dataSourceStat.getResultSetStat().beforeOpen();
resultSet.setConstructNano();
StatFilterContext.getInstance().resultSet_open();
}
use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.
the class StatFilter method statementCreateAfter.
@Override
public void statementCreateAfter(StatementProxy statement) {
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
dataSourceStat.getStatementStat().incrementCreateCounter();
super.statementCreateAfter(statement);
}
use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.
the class StatFilter method dataSource_releaseConnection.
@Override
public void dataSource_releaseConnection(FilterChain chain, DruidPooledConnection conn) throws SQLException {
chain.dataSource_recycle(conn);
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);
}
use of com.alibaba.druid.stat.JdbcDataSourceStat in project druid by alibaba.
the class StatFilter method connection_close.
@Override
public void connection_close(FilterChain chain, ConnectionProxy connection) throws SQLException {
if (connection.getCloseCount() == 0) {
long nowNano = System.nanoTime();
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
dataSourceStat.getConnectionStat().incrementConnectionCloseCount();
JdbcConnectionStat.Entry connectionInfo = getConnectionInfo(connection);
long aliveNanoSpan = nowNano - connectionInfo.getEstablishNano();
JdbcConnectionStat.Entry existsConnection = dataSourceStat.getConnections().remove(connection.getId());
if (existsConnection != null) {
dataSourceStat.getConnectionStat().afterClose(aliveNanoSpan);
}
}
chain.connection_close(connection);
// duplicate close, C3P0等连接池,在某些情况下会关闭连接多次。
}
Aggregations