mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
增强监控
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@930 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -181,6 +181,8 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
protected final AtomicLong startTransactionCount = new AtomicLong();
|
||||
protected final AtomicLong rollbackCount = new AtomicLong();
|
||||
protected final AtomicLong reusePreparedStatement = new AtomicLong();
|
||||
protected final AtomicLong preparedStatementCount = new AtomicLong();
|
||||
protected final AtomicLong closedPreparedStatementCount = new AtomicLong();
|
||||
|
||||
protected final Histogram transactionHistogram = new Histogram(
|
||||
10,
|
||||
@@ -192,8 +194,20 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
public Histogram getTransactionHistogram() {
|
||||
return transactionHistogram;
|
||||
}
|
||||
|
||||
public void incrementClosedPreparedStatementCount() {
|
||||
closedPreparedStatementCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public void incrementPreparedStatementCount() {
|
||||
preparedStatementCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public long getPreparedStatementCount() {
|
||||
return preparedStatementCount.get();
|
||||
}
|
||||
|
||||
public void incrementReusePreparedStatementCount() {
|
||||
reusePreparedStatement.incrementAndGet();
|
||||
}
|
||||
|
||||
@@ -1309,4 +1323,13 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
public void closePreapredStatement(PreparedStatementHolder stmtHolder) {
|
||||
if (stmtHolder == null) {
|
||||
return;
|
||||
}
|
||||
closedPreparedStatementCount.incrementAndGet();
|
||||
|
||||
JdbcUtils.close(stmtHolder.getStatement());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,4 +121,6 @@ public interface DruidAbstractDataSourceMBean {
|
||||
long getTransactionThresholdMillis();
|
||||
|
||||
long getReusePreparedStatementCount();
|
||||
|
||||
long getPreparedStatementCount();
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
ConnectionHolder connection = connections[i];
|
||||
|
||||
for (PreparedStatementHolder holder : connection.getStatementPool().getMap().values()) {
|
||||
JdbcUtils.close(holder.getStatement());
|
||||
closePreapredStatement(holder);
|
||||
}
|
||||
|
||||
connection.getStatementPool().getMap().clear();
|
||||
|
||||
@@ -44,7 +44,6 @@ import com.alibaba.druid.logging.Log;
|
||||
import com.alibaba.druid.logging.LogFactory;
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
import com.alibaba.druid.util.TransactionInfo;
|
||||
|
||||
/**
|
||||
@@ -95,6 +94,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
stmt.setClosed(true); // soft set close
|
||||
} else {
|
||||
stmt.closeInternal();
|
||||
holder.getDataSource().incrementClosedPreparedStatementCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,15 +106,6 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
public Connection getConnection() {
|
||||
return conn;
|
||||
}
|
||||
|
||||
void closePoolableStatement() {
|
||||
PreparedStatementPool statmentPool = holder.getStatementPool();
|
||||
if (statmentPool != null) {
|
||||
for (PreparedStatementHolder holder : statmentPool.getMap().values()) {
|
||||
JdbcUtils.close(holder.getStatement());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void disable() {
|
||||
this.holder = null;
|
||||
@@ -164,11 +155,12 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
if (stmtHolder == null) {
|
||||
try {
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareStatement(sql));
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
} catch (SQLException ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
} else {
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
@@ -195,12 +187,14 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
if (stmtHolder == null) {
|
||||
try {
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareStatement(sql, resultSetType, resultSetConcurrency));
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareStatement(sql, resultSetType,
|
||||
resultSetConcurrency));
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
} catch (SQLException ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
} else {
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
@@ -227,12 +221,15 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
if (stmtHolder == null) {
|
||||
try {
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareStatement(sql, resultSetType,
|
||||
resultSetConcurrency,
|
||||
resultSetHoldability));
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
} catch (SQLException ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
} else {
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
@@ -258,11 +255,12 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
if (stmtHolder == null) {
|
||||
try {
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareStatement(sql, columnIndexes));
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
} catch (SQLException ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
} else {
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
@@ -288,11 +286,12 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
if (stmtHolder == null) {
|
||||
try {
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareStatement(sql, columnNames));
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
} catch (SQLException ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
} else {
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
@@ -318,11 +317,12 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
if (stmtHolder == null) {
|
||||
try {
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareStatement(sql, autoGeneratedKeys));
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
} catch (SQLException ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
} else {
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
@@ -351,11 +351,12 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
if (stmtHolder == null) {
|
||||
try {
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareCall(sql));
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
} catch (SQLException ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
} else {
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
@@ -381,12 +382,15 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
if (stmtHolder == null) {
|
||||
try {
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareCall(sql, resultSetType,
|
||||
resultSetConcurrency,
|
||||
resultSetHoldability));
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
} catch (SQLException ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
} else {
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
@@ -411,12 +415,14 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
|
||||
if (stmtHolder == null) {
|
||||
try {
|
||||
stmtHolder = new PreparedStatementHolder(key, conn.prepareCall(sql, resultSetType, resultSetConcurrency));
|
||||
stmtHolder = new PreparedStatementHolder(key,
|
||||
conn.prepareCall(sql, resultSetType, resultSetConcurrency));
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
} catch (SQLException ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
} else {
|
||||
holder.getDataSource().incrementPreparedStatementCount();
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
@@ -582,7 +588,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
if (holder == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
DruidAbstractDataSource dataSource = holder.getDataSource();
|
||||
dataSource.incrementRollbackCount();
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
@@ -57,7 +56,7 @@ public class PreparedStatementPool {
|
||||
PreparedStatementKey key = holder.getKey();
|
||||
PreparedStatementHolder oldHolder = map.put(key, holder);
|
||||
if (oldHolder != null) {
|
||||
JdbcUtils.close(oldHolder.getStatement());
|
||||
dataSource.closePreapredStatement(oldHolder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user