增强监控

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@343 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-07-01 04:09:47 +00:00
parent 7792ee8fe3
commit abf17fbfda
4 changed files with 227 additions and 16 deletions
@@ -902,6 +902,24 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
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_1000_2000_Millis", stat.getStatementStat().getCount_1000_2000_Millis());
map.put("StatementExecuteCount_2000_5000_Millis", stat.getStatementStat().getCount_2000_5000_Millis());
map.put("StatementExecuteCount_5000_10000_Millis", stat.getStatementStat().getCount_5000_10000_Millis());
map.put("StatementExecuteCount_10000_20000_Millis", stat.getStatementStat().getCount_10000_20000_Millis());
map.put("StatementExecuteCount_20000_more_Millis", stat.getStatementStat().getCount_20000_more_Millis());
} else {
map.put("ConnectionActiveCount", null);
map.put("ConnectionActiveCountMax", null);
@@ -973,6 +991,24 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
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_1000_2000_Millis", null);
map.put("StatementExecuteCount_2000_5000_Millis", null);
map.put("StatementExecuteCount_5000_10000_Millis", null);
map.put("StatementExecuteCount_10000_20000_Millis", null);
map.put("StatementExecuteCount_20000_more_Millis", null);
}
return new CompositeDataSupport(JdbcStatManager.getDataSourceCompositeType(), map);
@@ -308,6 +308,24 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
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_1000_2000_Millis", stat.getStatementStat().getCount_1000_2000_Millis());
map.put("StatementExecuteCount_2000_5000_Millis", stat.getStatementStat().getCount_2000_5000_Millis());
map.put("StatementExecuteCount_5000_10000_Millis", stat.getStatementStat().getCount_5000_10000_Millis());
map.put("StatementExecuteCount_10000_20000_Millis", stat.getStatementStat().getCount_10000_20000_Millis());
map.put("StatementExecuteCount_20000_more_Millis", stat.getStatementStat().getCount_20000_more_Millis());
} else {
map.put("ConnectionActiveCount", null);
map.put("ConnectionActiveCountMax", null);
@@ -380,6 +398,24 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
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_1000_2000_Millis", null);
map.put("StatementExecuteCount_2000_5000_Millis", null);
map.put("StatementExecuteCount_5000_10000_Millis", null);
map.put("StatementExecuteCount_10000_20000_Millis", null);
map.put("StatementExecuteCount_20000_more_Millis", null);
}
return new CompositeDataSupport(JdbcStatManager.getDataSourceCompositeType(), map);
@@ -121,6 +121,10 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
, 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 //
//
//
};
@@ -139,6 +143,10 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
, "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_1000_2000_Millis", "StatementExecuteCount_2000_5000_Millis", "StatementExecuteCount_5000_10000_Millis", "StatementExecuteCount_10000_20000_Millis", "StatementExecuteCount_20000_more_Millis"
//
};
@@ -26,23 +26,41 @@ 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 = new AtomicLong();
private AtomicLong count_1_2 = new AtomicLong();
private AtomicLong count_2_5 = new AtomicLong();
private AtomicLong count_5_10 = new AtomicLong();
private AtomicLong count_10_20 = new AtomicLong();
private AtomicLong count_20_50 = new AtomicLong();
private AtomicLong count_50_100 = new AtomicLong();
private AtomicLong count_100_200 = new AtomicLong();
private AtomicLong count_200_500 = new AtomicLong();
private AtomicLong count_500_1000 = new AtomicLong();
private AtomicLong count_1000_2000 = new AtomicLong();
private AtomicLong count_2000_5000 = new AtomicLong();
private AtomicLong count_5000_10000 = new AtomicLong();
private AtomicLong count_10000_20000 = new AtomicLong();
private AtomicLong count_20000_more = new AtomicLong();
public void reset() {
runningCount.set(0);
@@ -58,6 +76,65 @@ public class JdbcStatementStat implements JdbcStatementStatMBean {
prepareCount.set(0);
prepareCallCount.set(0);
closeCount.set(0);
count_0_1.set(0);
count_1_2.set(0);
count_2_5.set(0);
count_5_10.set(0);
count_10_20.set(0);
count_20_50.set(0);
count_50_100.set(0);
count_100_200.set(0);
count_200_500.set(0);
count_500_1000.set(0);
count_1000_2000.set(0);
count_2000_5000.set(0);
count_5000_10000.set(0);
count_10000_20000.set(0);
count_20000_more.set(0);
}
public void afterExecute(long nanoSpan) {
runningCount.decrementAndGet();
nanoTotal.addAndGet(nanoSpan);
final long MILLIS = 1000 * 100;
if (nanoSpan < MILLIS) {
count_0_1.incrementAndGet();
} else if (nanoSpan < 2 * MILLIS) {
count_1_2.incrementAndGet();
} else if (nanoSpan < 5 * MILLIS) {
count_2_5.incrementAndGet();
} else if (nanoSpan < 10 * MILLIS) {
count_5_10.incrementAndGet();
} else if (nanoSpan < 20 * MILLIS) {
count_10_20.incrementAndGet();
} else if (nanoSpan < 50 * MILLIS) {
count_20_50.incrementAndGet();
} else if (nanoSpan < 100 * MILLIS) {
count_50_100.incrementAndGet();
} else if (nanoSpan < 200 * MILLIS) {
count_100_200.incrementAndGet();
} else if (nanoSpan < 500 * MILLIS) {
count_200_500.incrementAndGet();
} else if (nanoSpan < 1000 * MILLIS) {
count_500_1000.incrementAndGet();
} else if (nanoSpan < 2000 * MILLIS) {
count_1000_2000.incrementAndGet();
} else if (nanoSpan < 5000 * MILLIS) {
count_2000_5000.incrementAndGet();
} else if (nanoSpan < 10000 * MILLIS) {
count_5000_10000.incrementAndGet();
} else if (nanoSpan < 20000 * MILLIS) {
count_10000_20000.incrementAndGet();
} else {
count_20000_more.incrementAndGet();
}
}
public void beforeExecute() {
@@ -80,12 +157,6 @@ public class JdbcStatementStat implements JdbcStatementStatMBean {
lastSampleTime = System.currentTimeMillis();
}
public void afterExecute(long nanoSpan) {
runningCount.decrementAndGet();
nanoTotal.addAndGet(nanoSpan);
}
public long getErrorCount() {
return errorCount.get();
}
@@ -187,6 +258,66 @@ public class JdbcStatementStat implements JdbcStatementStatMBean {
closeCount.incrementAndGet();
}
public long getCount_0_1_Millis() {
return count_0_1.get();
}
public long getCount_1_2_Millis() {
return count_1_2.get();
}
public long getCount_2_5_Millis() {
return count_2_5.get();
}
public long getCount_5_10_Millis() {
return count_5_10.get();
}
public long getCount_10_20_Millis() {
return count_10_20.get();
}
public long getCount_20_50_Millis() {
return count_20_50.get();
}
public long getCount_50_100_Millis() {
return count_50_100.get();
}
public long getCount_100_200_Millis() {
return count_100_200.get();
}
public long getCount_200_500_Millis() {
return count_200_500.get();
}
public long getCount_500_1000_Millis() {
return count_500_1000.get();
}
public long getCount_1000_2000_Millis() {
return count_1000_2000.get();
}
public long getCount_2000_5000_Millis() {
return count_2000_5000.get();
}
public long getCount_5000_10000_Millis() {
return count_5000_10000.get();
}
public long getCount_10000_20000_Millis() {
return count_10000_20000.get();
}
public long getCount_20000_more_Millis() {
return count_20000_more.get();
}
public static class Entry {
private long lastExecuteStartNano;