改进Connection和Statement的直方图计算

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@909 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-27 06:27:49 +00:00
parent 87d6258ba9
commit 127b002144
8 changed files with 82 additions and 759 deletions
@@ -1214,47 +1214,9 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
map.put("ConnectionAliveMillisMax", stat.getConnectionConnectAliveMillisMax());
map.put("ConnectionAliveMillisMin", stat.getConnectionConnectAliveMillisMin());
map.put("ConnectionCount_Alive_0_1_Seconds", stat.getConnectionCount_Alive_0_1_Seconds());
map.put("ConnectionCount_Alive_1_5_Seconds", stat.getConnectionCount_Alive_1_5_Seconds());
map.put("ConnectionCount_Alive_5_10_Seconds", stat.getConnectionCount_Alive_5_10_Seconds());
map.put("ConnectionCount_Alive_10_30_Seconds", stat.getConnectionCount_Alive_10_30_Seconds());
map.put("ConnectionCount_Alive_30_60_Seconds", stat.getConnectionCount_Alive_30_60_Seconds());
map.put("ConnectionHistogram", stat.getConnectionHistogramValues());
map.put("StatementHistogram", stat.getStatementStat().getHistogramValues());
map.put("ConnectionCount_Alive_1_5_Minutes", stat.getConnectionCount_Alive_1_5_Minutes());
map.put("ConnectionCount_Alive_5_10_Minutes", stat.getConnectionCount_Alive_5_10_Minutes());
map.put("ConnectionCount_Alive_10_30_Minutes", stat.getConnectionCount_Alive_10_30_Minutes());
map.put("ConnectionCount_Alive_30_60_Minutes", stat.getConnectionCount_Alive_30_60_Minutes());
map.put("ConnectionCount_Alive_1_6_Hours", stat.getConnectionCount_Alive_1_6_Hours());
map.put("ConnectionCount_Alive_6_24_Hours", stat.getConnectionCount_Alive_6_24_Hours());
map.put("ConnectionCount_Alive_1_7_Day", stat.getConnectionCount_Alive_1_7_day());
map.put("ConnectionCount_Alive_7_30_Day", stat.getConnectionCount_Alive_7_30_Day());
map.put("ConnectionCount_Alive_30_90_Day", stat.getConnectionCount_Alive_30_90_Day());
map.put("ConnectionCount_Alive_90_more_Day", stat.getConnectionCount_Alive_90_more_Day());
map.put("StatementExecuteCount_0_1_Millis", stat.getStatementStat().getCount_0_1_Millis());
map.put("StatementExecuteCount_1_2_Millis", stat.getStatementStat().getCount_1_2_Millis());
map.put("StatementExecuteCount_2_5_Millis", stat.getStatementStat().getCount_2_5_Millis());
map.put("StatementExecuteCount_5_10_Millis", stat.getStatementStat().getCount_5_10_Millis());
map.put("StatementExecuteCount_10_20_Millis", stat.getStatementStat().getCount_10_20_Millis());
map.put("StatementExecuteCount_20_50_Millis", stat.getStatementStat().getCount_20_50_Millis());
map.put("StatementExecuteCount_50_100_Millis", stat.getStatementStat().getCount_50_100_Millis());
map.put("StatementExecuteCount_100_200_Millis", stat.getStatementStat().getCount_100_200_Millis());
map.put("StatementExecuteCount_200_500_Millis", stat.getStatementStat().getCount_200_500_Millis());
map.put("StatementExecuteCount_500_1000_Millis", stat.getStatementStat().getCount_500_1000_Millis());
map.put("StatementExecuteCount_1_2_Seconds", stat.getStatementStat().getCount_1_2_Seconds());
map.put("StatementExecuteCount_2_5_Seconds", stat.getStatementStat().getCount_2_5_Seconds());
map.put("StatementExecuteCount_5_10_Seconds", stat.getStatementStat().getCount_5_10_Seconds());
map.put("StatementExecuteCount_10_30_Seconds", stat.getStatementStat().getCount_10_30_Seconds());
map.put("StatementExecuteCount_30_60_Seconds", stat.getStatementStat().getCount_30_60_Seconds());
map.put("StatementExecuteCount_1_2_Minutes", stat.getStatementStat().getCount_1_2_minutes());
map.put("StatementExecuteCount_2_5_Minutes", stat.getStatementStat().getCount_2_5_minutes());
map.put("StatementExecuteCount_5_10_Minutes", stat.getStatementStat().getCount_5_10_minutes());
map.put("StatementExecuteCount_10_30_Minutes", stat.getStatementStat().getCount_10_30_minutes());
map.put("StatementExecuteCount_30_more_Minutes", stat.getStatementStat().getCount_30_more_minutes());
} else {
// 0 - 4
map.put("ConnectionActiveCount", null);
@@ -1316,47 +1278,8 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
map.put("ConnectionAliveMillisMax", null);
map.put("ConnectionAliveMillisMin", null);
map.put("ConnectionCount_Alive_0_1_Seconds", null);
map.put("ConnectionCount_Alive_1_5_Seconds", null);
map.put("ConnectionCount_Alive_5_10_Seconds", null);
map.put("ConnectionCount_Alive_10_30_Seconds", null);
map.put("ConnectionCount_Alive_30_60_Seconds", null);
map.put("ConnectionCount_Alive_1_5_Minutes", null);
map.put("ConnectionCount_Alive_5_10_Minutes", null);
map.put("ConnectionCount_Alive_10_30_Minutes", null);
map.put("ConnectionCount_Alive_30_60_Minutes", null);
map.put("ConnectionCount_Alive_1_6_Hours", null);
map.put("ConnectionCount_Alive_6_24_Hours", null);
map.put("ConnectionCount_Alive_1_7_Day", null);
map.put("ConnectionCount_Alive_7_30_Day", null);
map.put("ConnectionCount_Alive_30_90_Day", null);
map.put("ConnectionCount_Alive_90_more_Day", null);
map.put("StatementExecuteCount_0_1_Millis", null);
map.put("StatementExecuteCount_1_2_Millis", null);
map.put("StatementExecuteCount_2_5_Millis", null);
map.put("StatementExecuteCount_5_10_Millis", null);
map.put("StatementExecuteCount_10_20_Millis", null);
map.put("StatementExecuteCount_20_50_Millis", null);
map.put("StatementExecuteCount_50_100_Millis", null);
map.put("StatementExecuteCount_100_200_Millis", null);
map.put("StatementExecuteCount_200_500_Millis", null);
map.put("StatementExecuteCount_500_1000_Millis", null);
map.put("StatementExecuteCount_1_2_Seconds", null);
map.put("StatementExecuteCount_2_5_Seconds", null);
map.put("StatementExecuteCount_5_10_Seconds", null);
map.put("StatementExecuteCount_10_30_Seconds", null);
map.put("StatementExecuteCount_30_60_Seconds", null);
map.put("StatementExecuteCount_1_2_Minutes", null);
map.put("StatementExecuteCount_2_5_Minutes", null);
map.put("StatementExecuteCount_5_10_Minutes", null);
map.put("StatementExecuteCount_10_30_Minutes", null);
map.put("StatementExecuteCount_30_more_Minutes", null);
map.put("ConnectionHistogram", new long[0]);
map.put("StatementHistogram", new long[0]);
}
return new CompositeDataSupport(JdbcStatManager.getDataSourceCompositeType(), map);
@@ -19,6 +19,8 @@ public class HADataSource extends MultiDataSource implements DataSource {
private final static Log LOG = LogFactory.getLog(HADataSource.class);
private DruidDataSource masterDataSource;
protected ArrayList<DruidDataSource> dataSources = new ArrayList<DruidDataSource>();
protected final List<DruidDataSource> notAvailableDatasources = new CopyOnWriteArrayList<DruidDataSource>();
@@ -35,7 +37,7 @@ public class HADataSource extends MultiDataSource implements DataSource {
public synchronized void setDataSources(List<DruidDataSource> dataSources) {
this.dataSources = new ArrayList<DruidDataSource>(dataSources);
}
public synchronized void addDataSource(DruidDataSource dataSource) {
ArrayList<DruidDataSource> newList = new ArrayList<DruidDataSource>(dataSources);
newList.add(dataSource);
@@ -286,47 +286,8 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
map.put("ConnectionAliveMillisMax", stat.getConnectionConnectAliveMillisMax());
map.put("ConnectionAliveMillisMin", stat.getConnectionConnectAliveMillisMin());
map.put("ConnectionCount_Alive_0_1_Seconds", stat.getConnectionCount_Alive_0_1_Seconds());
map.put("ConnectionCount_Alive_1_5_Seconds", stat.getConnectionCount_Alive_1_5_Seconds());
map.put("ConnectionCount_Alive_5_10_Seconds", stat.getConnectionCount_Alive_5_10_Seconds());
map.put("ConnectionCount_Alive_10_30_Seconds", stat.getConnectionCount_Alive_10_30_Seconds());
map.put("ConnectionCount_Alive_30_60_Seconds", stat.getConnectionCount_Alive_30_60_Seconds());
map.put("ConnectionCount_Alive_1_5_Minutes", stat.getConnectionCount_Alive_1_5_Minutes());
map.put("ConnectionCount_Alive_5_10_Minutes", stat.getConnectionCount_Alive_5_10_Minutes());
map.put("ConnectionCount_Alive_10_30_Minutes", stat.getConnectionCount_Alive_10_30_Minutes());
map.put("ConnectionCount_Alive_30_60_Minutes", stat.getConnectionCount_Alive_30_60_Minutes());
map.put("ConnectionCount_Alive_1_6_Hours", stat.getConnectionCount_Alive_1_6_Hours());
map.put("ConnectionCount_Alive_6_24_Hours", stat.getConnectionCount_Alive_6_24_Hours());
map.put("ConnectionCount_Alive_1_7_Day", stat.getConnectionCount_Alive_1_7_day());
map.put("ConnectionCount_Alive_7_30_Day", stat.getConnectionCount_Alive_7_30_Day());
map.put("ConnectionCount_Alive_30_90_Day", stat.getConnectionCount_Alive_30_90_Day());
map.put("ConnectionCount_Alive_90_more_Day", stat.getConnectionCount_Alive_90_more_Day());
map.put("StatementExecuteCount_0_1_Millis", stat.getStatementStat().getCount_0_1_Millis());
map.put("StatementExecuteCount_1_2_Millis", stat.getStatementStat().getCount_1_2_Millis());
map.put("StatementExecuteCount_2_5_Millis", stat.getStatementStat().getCount_2_5_Millis());
map.put("StatementExecuteCount_5_10_Millis", stat.getStatementStat().getCount_5_10_Millis());
map.put("StatementExecuteCount_10_20_Millis", stat.getStatementStat().getCount_10_20_Millis());
map.put("StatementExecuteCount_20_50_Millis", stat.getStatementStat().getCount_20_50_Millis());
map.put("StatementExecuteCount_50_100_Millis", stat.getStatementStat().getCount_50_100_Millis());
map.put("StatementExecuteCount_100_200_Millis", stat.getStatementStat().getCount_100_200_Millis());
map.put("StatementExecuteCount_200_500_Millis", stat.getStatementStat().getCount_200_500_Millis());
map.put("StatementExecuteCount_500_1000_Millis", stat.getStatementStat().getCount_500_1000_Millis());
map.put("StatementExecuteCount_1_2_Seconds", stat.getStatementStat().getCount_1_2_Seconds());
map.put("StatementExecuteCount_2_5_Seconds", stat.getStatementStat().getCount_2_5_Seconds());
map.put("StatementExecuteCount_5_10_Seconds", stat.getStatementStat().getCount_5_10_Seconds());
map.put("StatementExecuteCount_10_30_Seconds", stat.getStatementStat().getCount_10_30_Seconds());
map.put("StatementExecuteCount_30_60_Seconds", stat.getStatementStat().getCount_30_60_Seconds());
map.put("StatementExecuteCount_1_2_Minutes", stat.getStatementStat().getCount_1_2_minutes());
map.put("StatementExecuteCount_2_5_Minutes", stat.getStatementStat().getCount_2_5_minutes());
map.put("StatementExecuteCount_5_10_Minutes", stat.getStatementStat().getCount_5_10_minutes());
map.put("StatementExecuteCount_10_30_Minutes", stat.getStatementStat().getCount_10_30_minutes());
map.put("StatementExecuteCount_30_more_Minutes", stat.getStatementStat().getCount_30_more_minutes());
map.put("ConnectionHistogram", stat.getConnectionHistogramValues());
map.put("StatementHistogram", stat.getStatementStat().getHistogramValues());
} else {
map.put("ConnectionActiveCount", null);
map.put("ConnectionActiveCountMax", null);
@@ -381,47 +342,8 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
map.put("ConnectionAliveMillisMax", null);
map.put("ConnectionAliveMillisMin", null);
map.put("ConnectionCount_Alive_0_1_Seconds", null);
map.put("ConnectionCount_Alive_1_5_Seconds", null);
map.put("ConnectionCount_Alive_5_10_Seconds", null);
map.put("ConnectionCount_Alive_10_30_Seconds", null);
map.put("ConnectionCount_Alive_30_60_Seconds", null);
map.put("ConnectionCount_Alive_1_5_Minutes", null);
map.put("ConnectionCount_Alive_5_10_Minutes", null);
map.put("ConnectionCount_Alive_10_30_Minutes", null);
map.put("ConnectionCount_Alive_30_60_Minutes", null);
map.put("ConnectionCount_Alive_1_6_Hours", null);
map.put("ConnectionCount_Alive_6_24_Hours", null);
map.put("ConnectionCount_Alive_1_7_Day", null);
map.put("ConnectionCount_Alive_7_30_Day", null);
map.put("ConnectionCount_Alive_30_90_Day", null);
map.put("ConnectionCount_Alive_90_more_Day", null);
map.put("StatementExecuteCount_0_1_Millis", null);
map.put("StatementExecuteCount_1_2_Millis", null);
map.put("StatementExecuteCount_2_5_Millis", null);
map.put("StatementExecuteCount_5_10_Millis", null);
map.put("StatementExecuteCount_10_20_Millis", null);
map.put("StatementExecuteCount_20_50_Millis", null);
map.put("StatementExecuteCount_50_100_Millis", null);
map.put("StatementExecuteCount_100_200_Millis", null);
map.put("StatementExecuteCount_200_500_Millis", null);
map.put("StatementExecuteCount_500_1000_Millis", null);
map.put("StatementExecuteCount_1_2_Seconds", null);
map.put("StatementExecuteCount_2_5_Seconds", null);
map.put("StatementExecuteCount_5_10_Seconds", null);
map.put("StatementExecuteCount_10_30_Seconds", null);
map.put("StatementExecuteCount_30_60_Seconds", null);
map.put("StatementExecuteCount_1_2_Minutes", null);
map.put("StatementExecuteCount_2_5_Minutes", null);
map.put("StatementExecuteCount_5_10_Minutes", null);
map.put("StatementExecuteCount_10_30_Minutes", null);
map.put("StatementExecuteCount_30_more_Minutes", null);
map.put("ConnectionHistogram", new long[0]);
map.put("StatementHistogram", new long[0]);
}
return new CompositeDataSupport(JdbcStatManager.getDataSourceCompositeType(), map);
@@ -20,6 +20,7 @@ import java.io.StringWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
@@ -29,6 +30,7 @@ import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
import com.alibaba.druid.util.Histogram;
import com.alibaba.druid.util.JMXUtils;
/**
@@ -36,51 +38,36 @@ import com.alibaba.druid.util.JMXUtils;
*/
public class JdbcConnectionStat implements JdbcConnectionStatMBean {
private final AtomicInteger activeCount = new AtomicInteger();
private final AtomicInteger activeCountMax = new AtomicInteger();
private final AtomicInteger activeCount = new AtomicInteger();
private final AtomicInteger activeCountMax = new AtomicInteger();
private final AtomicInteger connectingCount = new AtomicInteger();
private final AtomicInteger connectingMax = new AtomicInteger();
private final AtomicInteger connectingCount = new AtomicInteger();
private final AtomicInteger connectingMax = new AtomicInteger();
private final AtomicLong connectCount = new AtomicLong();
private final AtomicLong connectErrorCount = new AtomicLong();
private final AtomicLong connectCount = new AtomicLong();
private final AtomicLong connectErrorCount = new AtomicLong();
private Throwable connectErrorLast;
private final AtomicLong connectNanoTotal = new AtomicLong(0); // 连接建立消耗时间总和(纳秒)
private final AtomicLong connectNanoMax = new AtomicLong(0); // 连接建立消耗最大时间(纳秒)
private final AtomicLong connectNanoTotal = new AtomicLong(0); // 连接建立消耗时间总和(纳秒)
private final AtomicLong connectNanoMax = new AtomicLong(0); // 连接建立消耗最大时间(纳秒)
private final AtomicLong errorCount = new AtomicLong();
private final AtomicLong errorCount = new AtomicLong();
private final AtomicLong aliveNanoTotal = new AtomicLong();
private final AtomicLong aliveNanoTotal = new AtomicLong();
private Throwable lastError;
private long lastErrorTime;
private long connectLastTime = 0;
private long connectLastTime = 0;
private final AtomicLong closeCount = new AtomicLong(0); // 执行Connection.close的计数
private final AtomicLong transactionStartCount = new AtomicLong(0);
private final AtomicLong commitCount = new AtomicLong(0); // 执行commit的计数
private final AtomicLong rollbackCount = new AtomicLong(0); // 执行rollback的计数
private final AtomicLong closeCount = new AtomicLong(0); // 执行Connection.close的计数
private final AtomicLong transactionStartCount = new AtomicLong(0);
private final AtomicLong commitCount = new AtomicLong(0); // 执行commit的计数
private final AtomicLong rollbackCount = new AtomicLong(0); // 执行rollback的计数
private final AtomicLong aliveNanoMin = new AtomicLong();
private final AtomicLong aliveNanoMax = new AtomicLong();
private final AtomicLong aliveNanoMin = new AtomicLong();
private final AtomicLong aliveNanoMax = new AtomicLong();
private final AtomicLong count_Alive_0_1_Seconds = new AtomicLong();
private final AtomicLong count_Alive_1_5_Seconds = new AtomicLong();
private final AtomicLong count_Alive_5_10_Seconds = new AtomicLong();
private final AtomicLong count_Alive_10_30_Seconds = new AtomicLong();
private final AtomicLong count_Alive_30_60_Seconds = new AtomicLong();
private final AtomicLong count_Alive_1_5_Minutes = new AtomicLong();
private final AtomicLong count_Alive_5_10_Minutes = new AtomicLong();
private final AtomicLong count_Alive_10_30_Minutes = new AtomicLong();
private final AtomicLong count_Alive_30_60_Minutes = new AtomicLong();
private final AtomicLong count_Alive_1_6_Hours = new AtomicLong();
private final AtomicLong count_Alive_6_24_Hours = new AtomicLong();
private final AtomicLong count_Alive_1_7_Day = new AtomicLong();
private final AtomicLong count_Alive_7_30_Day = new AtomicLong();
private final AtomicLong count_Alive_30_90_Day = new AtomicLong();
private final AtomicLong count_Alive_90_more_Day = new AtomicLong();
private final Histogram histogram = new Histogram(TimeUnit.SECONDS, new long[] { //
1, 5, 15, 60, 300, 1800 });
public void reset() {
connectingMax.set(0);
@@ -101,23 +88,7 @@ public class JdbcConnectionStat implements JdbcConnectionStatMBean {
connectNanoTotal.set(0);
connectNanoMax.set(0);
count_Alive_0_1_Seconds.set(0);
count_Alive_1_5_Seconds.set(0);
count_Alive_5_10_Seconds.set(0);
count_Alive_10_30_Seconds.set(0);
count_Alive_30_60_Seconds.set(0);
count_Alive_1_5_Minutes.set(0);
count_Alive_5_10_Minutes.set(0);
count_Alive_10_30_Minutes.set(0);
count_Alive_30_60_Minutes.set(0);
count_Alive_1_6_Hours.set(0);
count_Alive_6_24_Hours.set(0);
count_Alive_1_7_Day.set(0);
count_Alive_7_30_Day.set(0);
count_Alive_30_90_Day.set(0);
count_Alive_90_more_Day.set(0);
histogram.reset();
}
public void beforeConnect() {
@@ -255,44 +226,8 @@ public class JdbcConnectionStat implements JdbcConnectionStatMBean {
}
}
final long SECOND = 1000 * 1000 * 1000;
final long MINUTE = SECOND * 60;
final long HOUR = MINUTE * 60;
final long DAY = HOUR * 24;
if (aliveNano < 1 * SECOND) {
count_Alive_0_1_Seconds.incrementAndGet();
} else if (aliveNano < 5 * SECOND) {
count_Alive_1_5_Seconds.incrementAndGet();
} else if (aliveNano < 10 * SECOND) {
count_Alive_5_10_Seconds.incrementAndGet();
} else if (aliveNano < 30 * SECOND) {
count_Alive_10_30_Seconds.incrementAndGet();
} else if (aliveNano < 60 * SECOND) {
count_Alive_30_60_Seconds.incrementAndGet();
} else if (aliveNano < 5 * MINUTE) {
count_Alive_1_5_Minutes.incrementAndGet();
} else if (aliveNano < 10 * MINUTE) {
count_Alive_5_10_Minutes.incrementAndGet();
} else if (aliveNano < 30 * MINUTE) {
count_Alive_10_30_Minutes.incrementAndGet();
} else if (aliveNano < 60 * MINUTE) {
count_Alive_30_60_Minutes.incrementAndGet();
} else if (aliveNano < 6 * HOUR) {
count_Alive_1_6_Hours.incrementAndGet();
} else if (aliveNano < 24 * HOUR) {
count_Alive_6_24_Hours.incrementAndGet();
} else if (aliveNano < 7 * DAY) {
count_Alive_1_7_Day.incrementAndGet();
} else if (aliveNano < 30 * DAY) {
count_Alive_7_30_Day.incrementAndGet();
} else if (aliveNano < 90 * DAY) {
count_Alive_30_90_Day.incrementAndGet();
} else {
count_Alive_90_more_Day.incrementAndGet();
}
long aliveMillis = aliveNano / (1000 * 1000);
histogram.recode(aliveMillis);
}
public Throwable getErrorLast() {
@@ -381,11 +316,11 @@ public class JdbcConnectionStat implements JdbcConnectionStatMBean {
public void incrementConnectionRollbackCount() {
rollbackCount.incrementAndGet();
}
public void incrementTransactionStartCount() {
transactionStartCount.incrementAndGet();
}
public long getTransactionStartCount() {
return transactionStartCount.get();
}
@@ -564,64 +499,11 @@ public class JdbcConnectionStat implements JdbcConnectionStatMBean {
void reset();
}
public long getCount_Alive_0_1_Seconds() {
return count_Alive_0_1_Seconds.get();
public long[] getHistorgramValues() {
return this.histogram.toArray();
}
public long getCount_Alive_1_5_Seconds() {
return count_Alive_1_5_Seconds.get();
public long[] getHistogramRanges() {
return this.histogram.getRanges();
}
public long getCount_Alive_5_10_Seconds() {
return count_Alive_5_10_Seconds.get();
}
public long getCount_Alive_10_30_Seconds() {
return count_Alive_10_30_Seconds.get();
}
public long getCount_Alive_30_60_Seconds() {
return count_Alive_30_60_Seconds.get();
}
public long getCount_Alive_1_5_Minutes() {
return count_Alive_1_5_Minutes.get();
}
public long getCount_Alive_5_10_Minutes() {
return count_Alive_5_10_Minutes.get();
}
public long getCount_Alive_10_30_Minutes() {
return count_Alive_10_30_Minutes.get();
}
public long getCount_Alive_30_60_Minutes() {
return count_Alive_30_60_Minutes.get();
}
public long getCount_Alive_1_6_Hours() {
return count_Alive_1_6_Hours.get();
}
public long getCount_Alive_6_24_Hours() {
return count_Alive_6_24_Hours.get();
}
public long getCount_Alive_1_7_Day() {
return count_Alive_1_7_Day.get();
}
public long getCount_Alive_7_30_Day() {
return count_Alive_7_30_Day.get();
}
public long getCount_Alive_30_90_Day() {
return count_Alive_30_90_Day.get();
}
public long getCount_Alive_90_more_Day() {
return count_Alive_90_more_Day.get();
}
}
@@ -190,219 +190,12 @@ public class JdbcDataSourceStat implements JdbcDataSourceStatMBean {
return min / (1000 * 1000);
}
final static long SECOND = 1000 * 1000 * 1000;
final static long MINUTE = SECOND * 60;
final static long HOUR = MINUTE * 60;
final static long DAY = HOUR * 24;
public long getConnectionCount_Alive_0_1_Seconds() {
long count = this.getConnectionStat().getCount_Alive_0_1_Seconds();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano < SECOND) {
count++;
}
}
return count;
public long[] getConnectionHistogramRanges() {
return connectionStat.getHistogramRanges();
}
public long getConnectionCount_Alive_1_5_Seconds() {
long count = this.getConnectionStat().getCount_Alive_1_5_Seconds();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= SECOND && connectionAliveNano < 5 * SECOND) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_5_10_Seconds() {
long count = this.getConnectionStat().getCount_Alive_5_10_Seconds();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 5 * SECOND && connectionAliveNano < 10 * SECOND) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_10_30_Seconds() {
long count = this.getConnectionStat().getCount_Alive_10_30_Seconds();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 10 * SECOND && connectionAliveNano < 30 * SECOND) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_30_60_Seconds() {
long count = this.getConnectionStat().getCount_Alive_30_60_Seconds();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 30 * SECOND && connectionAliveNano < 60 * SECOND) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_1_5_Minutes() {
long count = this.getConnectionStat().getCount_Alive_1_5_Minutes();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 1 * MINUTE && connectionAliveNano < 5 * MINUTE) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_5_10_Minutes() {
long count = this.getConnectionStat().getCount_Alive_5_10_Minutes();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 5 * MINUTE && connectionAliveNano < 10 * MINUTE) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_10_30_Minutes() {
long count = this.getConnectionStat().getCount_Alive_10_30_Minutes();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 10 * MINUTE && connectionAliveNano < 30 * MINUTE) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_30_60_Minutes() {
long count = this.getConnectionStat().getCount_Alive_30_60_Minutes();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 30 * MINUTE && connectionAliveNano < 60 * MINUTE) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_1_6_Hours() {
long count = this.getConnectionStat().getCount_Alive_1_6_Hours();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 1 * HOUR && connectionAliveNano < 6 * HOUR) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_6_24_Hours() {
long count = this.getConnectionStat().getCount_Alive_6_24_Hours();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 6 * HOUR && connectionAliveNano < 24 * HOUR) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_1_7_day() {
long count = this.getConnectionStat().getCount_Alive_1_7_Day();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 1 * DAY && connectionAliveNano < 7 * DAY) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_7_30_Day() {
long count = this.getConnectionStat().getCount_Alive_7_30_Day();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 7 * DAY && connectionAliveNano < 30 * DAY) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_30_90_Day() {
long count = this.getConnectionStat().getCount_Alive_30_90_Day();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 30 * DAY && connectionAliveNano < 90 * DAY) {
count++;
}
}
return count;
}
public long getConnectionCount_Alive_90_more_Day() {
long count = this.getConnectionStat().getCount_Alive_90_more_Day();
long nowNano = System.nanoTime();
for (JdbcConnectionStat.Entry connection : connections.values()) {
long connectionAliveNano = nowNano - connection.getEstablishNano();
if (connectionAliveNano >= 90 * DAY) {
count++;
}
}
return count;
public long[] getConnectionHistogramValues() {
return connectionStat.getHistorgramValues();
}
}
@@ -31,4 +31,8 @@ public interface JdbcDataSourceStatMBean {
long getConnectionActiveCount();
long getConnectionConnectAliveMillis();
long[] getConnectionHistogramValues();
long[] getConnectionHistogramRanges();
}
@@ -119,14 +119,7 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
, SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, SimpleType.INTEGER //
, SimpleType.LONG, SimpleType.DATE, SimpleType.LONG, SimpleType.LONG //
//
, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG //
, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG //
, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG //
//
, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG //
, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG //
, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG //
, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG //
, new ArrayType<Long>(SimpleType.LONG, true), new ArrayType<Long>(SimpleType.LONG, true)
//
//
};
@@ -138,7 +131,7 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
"Name",
"FilterClasses",
"CreatedTime", //
// 5 - 9
"RawUrl",
"RawDriverClassName",
@@ -146,7 +139,7 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
"RawDriverMinorVersion",
"Properties" //
,
// 10 - 14
"ConnectionActiveCount",
"ConnectionActiveCountMax",
@@ -168,7 +161,7 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
"StatementExecuteCount",
"StatementRunningCount" //
,
// 25 - 29
"StatementConcurrentMax",
"StatementCloseCount",
@@ -191,51 +184,15 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
"ResultSetLastOpenTime" //
,
// 40 - 44
"ResultSetErrorCount",
"ResultSetOpenningMillisTotal",
"ResultSetLastErrorTime",
"ResultSetLastErrorMessage",
"ResultSetLastErrorStackTrace",
"ConnectionConnectCount",
"ConnectionErrorLastMessage",
"ConnectionErrorLastStackTrace",
"ResultSetErrorCount", "ResultSetOpenningMillisTotal", "ResultSetLastErrorTime",
"ResultSetLastErrorMessage", "ResultSetLastErrorStackTrace", "ConnectionConnectCount",
"ConnectionErrorLastMessage", "ConnectionErrorLastStackTrace",
"ConnectionConnectMillisTotal",
"ConnectionConnectingCountMax" //
,
"ConnectionConnectMillisMax",
"ConnectionErrorLastTime",
"ConnectionAliveMillisMax",
, "ConnectionConnectMillisMax", "ConnectionErrorLastTime", "ConnectionAliveMillisMax",
"ConnectionAliveMillisMin" //
//
,
"ConnectionCount_Alive_0_1_Seconds",
"ConnectionCount_Alive_1_5_Seconds",
"ConnectionCount_Alive_5_10_Seconds",
"ConnectionCount_Alive_10_30_Seconds",
"ConnectionCount_Alive_30_60_Seconds" //
,
"ConnectionCount_Alive_1_5_Minutes",
"ConnectionCount_Alive_5_10_Minutes",
"ConnectionCount_Alive_10_30_Minutes",
"ConnectionCount_Alive_30_60_Minutes",
"ConnectionCount_Alive_1_6_Hours" //
,
"ConnectionCount_Alive_6_24_Hours",
"ConnectionCount_Alive_1_7_Day",
"ConnectionCount_Alive_7_30_Day",
"ConnectionCount_Alive_30_90_Day",
"ConnectionCount_Alive_90_more_Day" //
//
, "StatementExecuteCount_0_1_Millis", "StatementExecuteCount_1_2_Millis",
"StatementExecuteCount_2_5_Millis", "StatementExecuteCount_5_10_Millis",
"StatementExecuteCount_10_20_Millis", "StatementExecuteCount_20_50_Millis",
"StatementExecuteCount_50_100_Millis", "StatementExecuteCount_100_200_Millis",
"StatementExecuteCount_200_500_Millis", "StatementExecuteCount_500_1000_Millis",
"StatementExecuteCount_1_2_Seconds", "StatementExecuteCount_2_5_Seconds",
"StatementExecuteCount_5_10_Seconds", "StatementExecuteCount_10_30_Seconds",
"StatementExecuteCount_30_60_Seconds", "StatementExecuteCount_1_2_Minutes",
"StatementExecuteCount_2_5_Minutes", "StatementExecuteCount_5_10_Minutes",
"StatementExecuteCount_10_30_Minutes", "StatementExecuteCount_30_more_Minutes"
, "ConnectionHistogram", "StatementHistogram",
//
};
@@ -245,7 +202,7 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
return COMPOSITE_TYPE;
}
@Override
public TabularData getDataSourceList() throws JMException {
CompositeType rowType = getDataSourceCompositeType();
@@ -309,7 +266,7 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
}
}
}
for (DruidDataSource instance : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
for (Filter filter : instance.getProxyFilters()) {
if (filter instanceof StatFilter) {
@@ -343,7 +300,7 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
}
}
}
for (DruidDataSource instance : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
for (Filter filter : instance.getProxyFilters()) {
if (filter instanceof StatFilter) {
@@ -22,51 +22,38 @@ import java.util.concurrent.atomic.AtomicLong;
import javax.management.JMException;
import javax.management.openmbean.CompositeData;
import com.alibaba.druid.util.Histogram;
import com.alibaba.druid.util.JMXUtils;
public class JdbcStatementStat implements JdbcStatementStatMBean {
private final AtomicLong createCount = new AtomicLong(0); // 执行createStatement的计数
private final AtomicLong prepareCount = new AtomicLong(0); // 执行parepareStatement的计数
private final AtomicLong prepareCallCount = new AtomicLong(0); // 执行preCall的计数
private final AtomicLong closeCount = new AtomicLong(0); // Statement关闭的计数
private final AtomicLong createCount = new AtomicLong(0); // 执行createStatement的计数
private final AtomicLong prepareCount = new AtomicLong(0); // 执行parepareStatement的计数
private final AtomicLong prepareCallCount = new AtomicLong(0); // 执行preCall的计数
private final AtomicLong closeCount = new AtomicLong(0); // Statement关闭的计数
private final AtomicInteger runningCount = new AtomicInteger();
private final AtomicInteger concurrentMax = new AtomicInteger();
private final AtomicInteger runningCount = new AtomicInteger();
private final AtomicInteger concurrentMax = new AtomicInteger();
private final AtomicLong count = new AtomicLong();
private final AtomicLong errorCount = new AtomicLong();
private final AtomicLong count = new AtomicLong();
private final AtomicLong errorCount = new AtomicLong();
private final AtomicLong nanoTotal = new AtomicLong();
private final AtomicLong nanoTotal = new AtomicLong();
private Throwable lastError;
private long lastErrorTime;
private long lastSampleTime = 0;
private long lastSampleTime = 0;
private AtomicLong count_0_1_Millis = new AtomicLong();
private AtomicLong count_1_2_Millis = new AtomicLong();
private AtomicLong count_2_5_Millis = new AtomicLong();
private AtomicLong count_5_10_Millis = new AtomicLong();
private AtomicLong count_10_20_Millis = new AtomicLong();
private final Histogram histogram = new Histogram(new long[] { 10, 100, 1000, 1000 * 10 });
private AtomicLong count_20_50_Millis = new AtomicLong();
private AtomicLong count_50_100_Millis = new AtomicLong();
private AtomicLong count_100_200_Millis = new AtomicLong();
private AtomicLong count_200_500_Millis = new AtomicLong();
private AtomicLong count_500_1000_Millis = new AtomicLong();
public long[] getHistogramRanges() {
return histogram.getRanges();
}
private AtomicLong count_1_2_Seconds = new AtomicLong();
private AtomicLong count_2_5_Seconds = new AtomicLong();
private AtomicLong count_5_10_Seconds = new AtomicLong();
private AtomicLong count_10_30_Seconds = new AtomicLong();
private AtomicLong count_30_60_Seconds = new AtomicLong();
private AtomicLong count_1_2_minutes = new AtomicLong();
private AtomicLong count_2_5_minutes = new AtomicLong();
private AtomicLong count_5_10_minutes = new AtomicLong();
private AtomicLong count_10_30_minutes = new AtomicLong();
private AtomicLong count_30_more_minutes = new AtomicLong();
public long[] getHistogramValues() {
return histogram.toArray();
}
public void reset() {
runningCount.set(0);
@@ -83,29 +70,7 @@ public class JdbcStatementStat implements JdbcStatementStatMBean {
prepareCallCount.set(0);
closeCount.set(0);
count_0_1_Millis.set(0);
count_1_2_Millis.set(0);
count_2_5_Millis.set(0);
count_5_10_Millis.set(0);
count_10_20_Millis.set(0);
count_20_50_Millis.set(0);
count_50_100_Millis.set(0);
count_100_200_Millis.set(0);
count_200_500_Millis.set(0);
count_500_1000_Millis.set(0);
count_1_2_Seconds.set(0);
count_2_5_Seconds.set(0);
count_5_10_Seconds.set(0);
count_10_30_Seconds.set(0);
count_30_60_Seconds.set(0);
count_1_2_minutes.set(0);
count_2_5_minutes.set(0);
count_5_10_minutes.set(0);
count_10_30_minutes.set(0);
count_30_more_minutes.set(0);
histogram.reset();
}
public void afterExecute(long nanoSpan) {
@@ -113,53 +78,8 @@ public class JdbcStatementStat implements JdbcStatementStatMBean {
nanoTotal.addAndGet(nanoSpan);
final long MILLIS = 1000 * 1000;
final long SECOND = 1000 * MILLIS;
final long MINUTE = 60 * SECOND;
if (nanoSpan < MILLIS) {
count_0_1_Millis.incrementAndGet();
} else if (nanoSpan < 2 * MILLIS) {
count_1_2_Millis.incrementAndGet();
} else if (nanoSpan < 5 * MILLIS) {
count_2_5_Millis.incrementAndGet();
} else if (nanoSpan < 10 * MILLIS) {
count_5_10_Millis.incrementAndGet();
} else if (nanoSpan < 20 * MILLIS) {
count_10_20_Millis.incrementAndGet();
} else if (nanoSpan < 50 * MILLIS) {
count_20_50_Millis.incrementAndGet();
} else if (nanoSpan < 100 * MILLIS) {
count_50_100_Millis.incrementAndGet();
} else if (nanoSpan < 200 * MILLIS) {
count_100_200_Millis.incrementAndGet();
} else if (nanoSpan < 500 * MILLIS) {
count_200_500_Millis.incrementAndGet();
} else if (nanoSpan < 1000 * MILLIS) {
count_500_1000_Millis.incrementAndGet();
} else if (nanoSpan < 2 * SECOND) {
count_1_2_Seconds.incrementAndGet();
} else if (nanoSpan < 5 * SECOND) {
count_2_5_Seconds.incrementAndGet();
} else if (nanoSpan < 10 * SECOND) {
count_5_10_Seconds.incrementAndGet();
} else if (nanoSpan < 30 * SECOND) {
count_10_30_Seconds.incrementAndGet();
} else if (nanoSpan < 60 * SECOND) {
count_30_60_Seconds.incrementAndGet();
} else if (nanoSpan < 2 * MINUTE) {
count_1_2_minutes.incrementAndGet();
} else if (nanoSpan < 5 * MINUTE) {
count_2_5_minutes.incrementAndGet();
} else if (nanoSpan < 10 * MINUTE) {
count_5_10_minutes.incrementAndGet();
} else if (nanoSpan < 30 * MINUTE) {
count_10_30_minutes.incrementAndGet();
} else {
count_30_more_minutes.incrementAndGet();
}
long millis = nanoSpan / (1000 * 1000);
histogram.recode(millis);
}
public void beforeExecute() {
@@ -283,86 +203,6 @@ public class JdbcStatementStat implements JdbcStatementStatMBean {
closeCount.incrementAndGet();
}
public long getCount_0_1_Millis() {
return count_0_1_Millis.get();
}
public long getCount_1_2_Millis() {
return count_1_2_Millis.get();
}
public long getCount_2_5_Millis() {
return count_2_5_Millis.get();
}
public long getCount_5_10_Millis() {
return count_5_10_Millis.get();
}
public long getCount_10_20_Millis() {
return count_10_20_Millis.get();
}
public long getCount_20_50_Millis() {
return count_20_50_Millis.get();
}
public long getCount_50_100_Millis() {
return count_50_100_Millis.get();
}
public long getCount_100_200_Millis() {
return count_100_200_Millis.get();
}
public long getCount_200_500_Millis() {
return count_200_500_Millis.get();
}
public long getCount_500_1000_Millis() {
return count_500_1000_Millis.get();
}
public long getCount_1_2_Seconds() {
return count_1_2_Seconds.get();
}
public long getCount_2_5_Seconds() {
return count_2_5_Seconds.get();
}
public long getCount_5_10_Seconds() {
return count_5_10_Seconds.get();
}
public long getCount_10_30_Seconds() {
return count_10_30_Seconds.get();
}
public long getCount_30_60_Seconds() {
return count_30_60_Seconds.get();
}
public long getCount_1_2_minutes() {
return count_1_2_minutes.get();
}
public long getCount_2_5_minutes() {
return count_2_5_minutes.get();
}
public long getCount_5_10_minutes() {
return count_5_10_minutes.get();
}
public long getCount_10_30_minutes() {
return count_10_30_minutes.get();
}
public long getCount_30_more_minutes() {
return count_30_more_minutes.get();
}
public static class Entry {
private long lastExecuteStartNano;