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@332 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -196,18 +196,20 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
, SimpleType.INTEGER, SimpleType.LONG, SimpleType.LONG, SimpleType.DATE, SimpleType.STRING //
|
||||
, SimpleType.STRING, SimpleType.LONG, SimpleType.INTEGER, SimpleType.DATE, SimpleType.LONG //
|
||||
, SimpleType.LONG, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.LONG, SimpleType.DATE //
|
||||
, SimpleType.LONG, SimpleType.LONG, SimpleType.DATE, SimpleType.STRING, SimpleType.STRING //
|
||||
,
|
||||
//
|
||||
};
|
||||
|
||||
String[] indexNames = { "ID", "URL", "Name", "FilterClasses", "CreatedTime", //
|
||||
"RawUrl", "RawDriverClassName", "RawDriverMajorVersion", "RawDriverMinorVersion", "Properties" //
|
||||
, "ConnectionCount", "ConnectionCountMax", "ConnectionCloseCount", "ConnectionCommitCount", "ConnectionRollbackCount" //
|
||||
, "ConnectLastTime", "ConnectErrorCount", "ConnectLastErrorTime", "ConnectLastErrorMessage", "ConnectLastErrorStackTrace" //
|
||||
, "ConnectionOpenningCount", "ConnectionOpenningCountMax", "ConnectionCloseCount", "ConnectionCommitCount", "ConnectionRollbackCount" //
|
||||
, "ConnectionConnectLastTime", "ConnectionConnectErrorCount", "ConnectLastErrorTime", "ConnectLastErrorMessage", "ConnectLastErrorStackTrace" //
|
||||
, "StatementCreateCount", "StatementPrepareCount", "StatementPreCallCount", "StatementExecuteCount", "StatementRunningCount" //
|
||||
, "StatementConcurrentMax", "StatementCloseCount", "StatementErrorCount", "StatementLastErrorTime", "StatementLastErrorMessage" //
|
||||
, "StatementLastErrorStackTrace", "StatementExecuteMillis", "ConnectingCount", "StatementExecuteLastTime", "ResultSetCloseCount" //
|
||||
, "ResultSetOpenCount", "ResultSetOpenningCount", "ResultSetOpenningMax", "ResultSetFetchRowCount", "ResultSetLastOpenTime"
|
||||
, "ResultSetOpenCount", "ResultSetOpenningCount", "ResultSetOpenningMax", "ResultSetFetchRowCount", "ResultSetLastOpenTime" //
|
||||
, "ResultSetErrorCount", "ResultSetOpenningMillisTotal", "ResultSetLastErrorTime", "ResultSetLastErrorMessage", "ResultSetLastErrorStackTrace"
|
||||
//
|
||||
};
|
||||
|
||||
@@ -244,14 +246,14 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
map.put("Properties", getProperties());
|
||||
|
||||
if (stat != null) {
|
||||
map.put("ConnectionCount", stat.getConnectionActiveCount());
|
||||
map.put("ConnectionCountMax", stat.getConnectionStat().getActiveMax());
|
||||
map.put("ConnectionOpenningCount", stat.getConnectionActiveCount());
|
||||
map.put("ConnectionOpenningCountMax", stat.getConnectionStat().getActiveMax());
|
||||
map.put("ConnectionCloseCount", stat.getConnectionStat().getCloseCount());
|
||||
map.put("ConnectionCommitCount", stat.getConnectionStat().getCommitCount());
|
||||
map.put("ConnectionRollbackCount", stat.getConnectionStat().getRollbackCount());
|
||||
|
||||
map.put("ConnectLastTime", stat.getConnectionStat().getLastConnectTime());
|
||||
map.put("ConnectErrorCount", stat.getConnectionStat().getErrorCount());
|
||||
map.put("ConnectionConnectLastTime", stat.getConnectionStat().getLastConnectTime());
|
||||
map.put("ConnectionConnectErrorCount", stat.getConnectionStat().getErrorCount());
|
||||
Throwable lastConnectionError = stat.getConnectionStat().getLastError();
|
||||
if (lastConnectionError != null) {
|
||||
map.put("ConnectLastErrorTime", stat.getConnectionStat().getLastErrorTime());
|
||||
@@ -294,20 +296,34 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
map.put("ResultSetCloseCount", stat.getResultSetStat().getCloseCount());
|
||||
|
||||
map.put("ResultSetOpenCount", stat.getResultSetStat().getOpenCount());
|
||||
map.put("ResultSetOpenningCount", stat.getResultSetStat().getRunningCount());
|
||||
map.put("ResultSetOpenningMax", stat.getResultSetStat().getConcurrentMax());
|
||||
map.put("ResultSetOpenningCount", stat.getResultSetStat().getOpenningCount());
|
||||
map.put("ResultSetOpenningMax", stat.getResultSetStat().getOpenningMax());
|
||||
map.put("ResultSetFetchRowCount", stat.getResultSetStat().getFetchRowCount());
|
||||
map.put("ResultSetLastOpenTime", stat.getResultSetStat().getLastOpenTime());
|
||||
|
||||
map.put("ResultSetErrorCount", stat.getResultSetStat().getErrorCount());
|
||||
map.put("ResultSetOpenningMillisTotal", stat.getResultSetStat().getOpenningMillisTotal());
|
||||
map.put("ResultSetLastErrorTime", stat.getResultSetStat().getLastErrorTime());
|
||||
Throwable lastResultSetError = stat.getResultSetStat().getLastError();
|
||||
if (lastResultSetError != null) {
|
||||
map.put("ResultSetLastErrorMessage", lastResultSetError.getMessage());
|
||||
StringWriter buf = new StringWriter();
|
||||
lastResultSetError.printStackTrace(new PrintWriter(buf));
|
||||
map.put("ResultSetLastErrorStackTrace", buf.toString());
|
||||
} else {
|
||||
map.put("ResultSetLastErrorMessage", null);
|
||||
map.put("ResultSetLastErrorStackTrace", null);
|
||||
}
|
||||
|
||||
} else {
|
||||
map.put("ConnectionCount", null);
|
||||
map.put("ConnectionCountMax", null);
|
||||
map.put("ConnectionOpenningCount", null);
|
||||
map.put("ConnectionOpenningCountMax", null);
|
||||
map.put("ConnectionCloseCount", null);
|
||||
map.put("ConnectionCommitCount", null);
|
||||
map.put("ConnectionRollbackCount", null);
|
||||
|
||||
map.put("ConnectLastTime", null);
|
||||
map.put("ConnectErrorCount", null);
|
||||
map.put("ConnectionConnectLastTime", null);
|
||||
map.put("ConnectionConnectErrorCount", null);
|
||||
map.put("ConnectLastErrorTime", null);
|
||||
map.put("ConnectLastErrorMessage", null);
|
||||
map.put("ConnectLastErrorStackTrace", null);
|
||||
@@ -335,6 +351,12 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
map.put("ResultSetOpenningMax", null);
|
||||
map.put("ResultSetFetchRowCount", null);
|
||||
map.put("ResultSetLastOpenTime", null);
|
||||
|
||||
map.put("ResultSetLastErrorCount", null);
|
||||
map.put("ResultSetOpenningMillisTotal", null);
|
||||
map.put("ResultSetLastErrorTime", null);
|
||||
map.put("ResultSetLastErrorMessage", null);
|
||||
map.put("ResultSetLastErrorStackTrace", null);
|
||||
}
|
||||
|
||||
return new CompositeDataSupport(getCompositeType(), map);
|
||||
|
||||
@@ -27,24 +27,25 @@ public class JdbcResultSetStat implements JdbcResultSetStatMBean {
|
||||
private final AtomicLong openCount = new AtomicLong();
|
||||
private final AtomicLong errorCount = new AtomicLong();
|
||||
|
||||
private final AtomicLong nanoTotal = new AtomicLong();
|
||||
private final AtomicLong openningNanoTotal = new AtomicLong();
|
||||
private Throwable lastError;
|
||||
private long lastErrorTime;
|
||||
|
||||
private long lastSampleTime = 0;
|
||||
private long lastOpenTime = 0;
|
||||
|
||||
private final AtomicLong fetchRowCounter = new AtomicLong(0); // 总共读取的行数
|
||||
private final AtomicLong fetchRowCount = new AtomicLong(0); // 总共读取的行数
|
||||
private final AtomicLong closeCount = new AtomicLong(0); // ResultSet打开的计数
|
||||
|
||||
public void reset() {
|
||||
openningCount.set(0);
|
||||
opeeningtMax.set(0);
|
||||
openCount.set(0);
|
||||
errorCount.set(0);
|
||||
nanoTotal.set(0);
|
||||
openningNanoTotal.set(0);
|
||||
lastError = null;
|
||||
lastErrorTime = 0;
|
||||
lastSampleTime = 0;
|
||||
lastOpenTime = 0;
|
||||
fetchRowCount.set(0);
|
||||
closeCount.set(0);
|
||||
}
|
||||
|
||||
public void beforeOpen() {
|
||||
@@ -64,18 +65,18 @@ public class JdbcResultSetStat implements JdbcResultSetStatMBean {
|
||||
}
|
||||
|
||||
openCount.incrementAndGet();
|
||||
lastSampleTime = System.currentTimeMillis();
|
||||
lastOpenTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long getErrorCount() {
|
||||
return errorCount.get();
|
||||
}
|
||||
|
||||
public int getRunningCount() {
|
||||
public int getOpenningCount() {
|
||||
return openningCount.get();
|
||||
}
|
||||
|
||||
public int getConcurrentMax() {
|
||||
public int getOpenningMax() {
|
||||
return opeeningtMax.get();
|
||||
}
|
||||
|
||||
@@ -84,21 +85,25 @@ public class JdbcResultSetStat implements JdbcResultSetStatMBean {
|
||||
}
|
||||
|
||||
public Date getLastOpenTime() {
|
||||
if (lastSampleTime == 0) {
|
||||
if (lastOpenTime == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Date(lastSampleTime);
|
||||
return new Date(lastOpenTime);
|
||||
}
|
||||
|
||||
public long getNanoTotal() {
|
||||
return nanoTotal.get();
|
||||
public long getOpenningNanoTotal() {
|
||||
return openningNanoTotal.get();
|
||||
}
|
||||
|
||||
public long getOpenningMillisTotal() {
|
||||
return openningNanoTotal.get() / (1000 * 1000);
|
||||
}
|
||||
|
||||
public void afterClose(long nanoSpan) {
|
||||
openningCount.decrementAndGet();
|
||||
|
||||
nanoTotal.addAndGet(nanoSpan);
|
||||
openningNanoTotal.addAndGet(nanoSpan);
|
||||
}
|
||||
|
||||
public Throwable getLastError() {
|
||||
@@ -121,12 +126,12 @@ public class JdbcResultSetStat implements JdbcResultSetStatMBean {
|
||||
|
||||
@Override
|
||||
public long getHoldMillisTotal() {
|
||||
return JdbcStatManager.getInstance().getResultSetStat().getNanoTotal() / (1000 * 1000);
|
||||
return JdbcStatManager.getInstance().getResultSetStat().getOpenningNanoTotal() / (1000 * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFetchRowCount() {
|
||||
return fetchRowCounter.get();
|
||||
return fetchRowCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,7 +140,7 @@ public class JdbcResultSetStat implements JdbcResultSetStatMBean {
|
||||
}
|
||||
|
||||
public void addFetchRowCount(long fetchCount) {
|
||||
fetchRowCounter.addAndGet(fetchCount);
|
||||
fetchRowCount.addAndGet(fetchCount);
|
||||
}
|
||||
|
||||
public void incrementCloseCounter() {
|
||||
|
||||
@@ -28,9 +28,9 @@ public interface JdbcResultSetStatMBean {
|
||||
|
||||
long getCloseCount();
|
||||
|
||||
int getRunningCount();
|
||||
int getOpenningCount();
|
||||
|
||||
int getConcurrentMax();
|
||||
int getOpenningMax();
|
||||
|
||||
long getErrorCount();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user