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@334 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -198,7 +198,7 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
, SimpleType.LONG, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.LONG, SimpleType.DATE //
|
||||
, SimpleType.LONG, SimpleType.LONG, SimpleType.DATE, SimpleType.STRING, SimpleType.STRING //
|
||||
, SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, SimpleType.INTEGER //
|
||||
, SimpleType.LONG
|
||||
, SimpleType.LONG, SimpleType.DATE, SimpleType.LONG, SimpleType.LONG
|
||||
//
|
||||
};
|
||||
|
||||
@@ -211,8 +211,8 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
, "StatementLastErrorStackTrace", "StatementExecuteMillis", "ConnectionConnectingCount", "StatementExecuteLastTime", "ResultSetCloseCount" //
|
||||
, "ResultSetOpenCount", "ResultSetOpenningCount", "ResultSetOpenningMax", "ResultSetFetchRowCount", "ResultSetLastOpenTime" //
|
||||
, "ResultSetErrorCount", "ResultSetOpenningMillisTotal", "ResultSetLastErrorTime", "ResultSetLastErrorMessage", "ResultSetLastErrorStackTrace"
|
||||
, "ConnectionConnectCount", "ConnectionErrorLastMessage", "ConnectionErrorLastStackTrace", "ConnectionConnectMillis", "ConnectionConnectingCountMax" //
|
||||
, "ConnectionConnectMillisMax"
|
||||
, "ConnectionConnectCount", "ConnectionErrorLastMessage", "ConnectionErrorLastStackTrace", "ConnectionConnectMillisTotal", "ConnectionConnectingCountMax" //
|
||||
, "ConnectionConnectMillisMax", "ConnectionErrorLastTime", "ConnectionAliveMillisMax", "ConnectionAliveMillisMin"
|
||||
//
|
||||
};
|
||||
|
||||
@@ -329,9 +329,13 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
map.put("ConnectionErrorLastMessage", null);
|
||||
map.put("ConnectionErrorLastStackTrace", null);
|
||||
}
|
||||
map.put("ConnectionConnectMillis", stat.getConnectionStat().getConnectMillis());
|
||||
map.put("ConnectionConnectMillisTotal", stat.getConnectionStat().getConnectMillis());
|
||||
map.put("ConnectionConnectingCountMax", stat.getConnectionStat().getConnectingMax());
|
||||
|
||||
map.put("ConnectionConnectMillisMax", stat.getConnectionStat().getConnectMillisMax());
|
||||
map.put("ConnectionErrorLastTime", stat.getConnectionStat().getErrorLastTime());
|
||||
map.put("ConnectionAliveMillisMax", stat.getConnectionStat().getAliveMillisMax());
|
||||
map.put("ConnectionAliveMillisMin", stat.getConnectionStat().getAliveMillisMin());
|
||||
} else {
|
||||
map.put("ConnectionActiveCount", null);
|
||||
map.put("ConnectionActiveCountMax", null);
|
||||
@@ -378,9 +382,13 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
map.put("ConnectionConnectCount", null);
|
||||
map.put("ConnectionErrorLastMessage", null);
|
||||
map.put("ConnectionErrorLastStackTrace", null);
|
||||
map.put("ConnectionConnectMillis", null);
|
||||
map.put("ConnectionConnectMillisTotal", null);
|
||||
map.put("ConnectionConnectingCountMax", null);
|
||||
|
||||
map.put("ConnectionConnectMillisMax", null);
|
||||
map.put("ConnectionErrorLastTime", null);
|
||||
map.put("ConnectionAliveMillisMax", null);
|
||||
map.put("ConnectionAliveMillisMin", null);
|
||||
}
|
||||
|
||||
return new CompositeDataSupport(getCompositeType(), map);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class JdbcConnectionStat implements JdbcConnectionStatMBean {
|
||||
|
||||
private final AtomicLong errorCount = new AtomicLong();
|
||||
|
||||
private final AtomicLong nanoTotal = new AtomicLong();
|
||||
private final AtomicLong aliveNanoTotal = new AtomicLong();
|
||||
private Throwable lastError;
|
||||
private long lastErrorTime;
|
||||
|
||||
@@ -59,12 +59,17 @@ public class JdbcConnectionStat implements JdbcConnectionStatMBean {
|
||||
private final AtomicLong closeCount = new AtomicLong(0); // 执行Connection.close的计数
|
||||
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();
|
||||
|
||||
public void reset() {
|
||||
connectingMax.set(0);
|
||||
connectErrorCount.set(0);
|
||||
errorCount.set(0);
|
||||
nanoTotal.set(0);
|
||||
aliveNanoTotal.set(0);
|
||||
aliveNanoMin.set(0);
|
||||
aliveNanoMax.set(0);
|
||||
lastError = null;
|
||||
lastErrorTime = 0;
|
||||
connectLastTime = 0;
|
||||
@@ -162,13 +167,56 @@ public class JdbcConnectionStat implements JdbcConnectionStatMBean {
|
||||
return connectingMax.get();
|
||||
}
|
||||
|
||||
public long getNanoTotal() {
|
||||
return nanoTotal.get();
|
||||
public long getAliveTotal() {
|
||||
return aliveNanoTotal.get();
|
||||
}
|
||||
|
||||
public long getAliveNanoMin() {
|
||||
return aliveNanoMin.get();
|
||||
}
|
||||
|
||||
public long getAliveMillisMin() {
|
||||
return aliveNanoMin.get() / (1000 * 1000);
|
||||
}
|
||||
|
||||
public long getAliveNanoMax() {
|
||||
return aliveNanoMax.get();
|
||||
}
|
||||
|
||||
public long getAliveMillisMax() {
|
||||
return aliveNanoMax.get() / (1000 * 1000);
|
||||
}
|
||||
|
||||
public void afterClose(long nanoSpan) {
|
||||
public void afterClose(long aliveNano) {
|
||||
activeCount.decrementAndGet();
|
||||
nanoTotal.addAndGet(nanoSpan);
|
||||
aliveNanoTotal.addAndGet(aliveNano);
|
||||
|
||||
for (;;) {
|
||||
long max = aliveNanoMax.get();
|
||||
if (aliveNano > max) {
|
||||
if (aliveNanoMax.compareAndSet(max, aliveNano)) {
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
long min = aliveNanoMin.get();
|
||||
if (aliveNano < min) {
|
||||
if (aliveNanoMax.compareAndSet(min, aliveNano)) {
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//holdTimeMin
|
||||
}
|
||||
|
||||
public Throwable getErrorLast() {
|
||||
|
||||
@@ -155,7 +155,7 @@ public class JdbcDataSourceStat implements JdbcDataSourceStatMBean {
|
||||
@Override
|
||||
public long getConnectionConnectAliveMillis() {
|
||||
long nowNano = System.nanoTime();
|
||||
long aliveNanoSpan = this.getConnectionStat().getNanoTotal();
|
||||
long aliveNanoSpan = this.getConnectionStat().getAliveTotal();
|
||||
|
||||
for (JdbcConnectionStat.Entry connection : connections.values()) {
|
||||
aliveNanoSpan += nowNano - connection.getEstablishNano();
|
||||
|
||||
Reference in New Issue
Block a user