mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
support logStats
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.druid.pool;
|
||||
|
||||
import static com.alibaba.druid.util.JdbcSqlStatUtils.rtrim;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -37,24 +39,43 @@ public class DruidDataSourceStatLoggerImpl implements DruidDataSourceStatLogger
|
||||
map.put("dbType", statValue.dbType);
|
||||
map.put("name", statValue.name);
|
||||
map.put("activeCount", statValue.activeCount);
|
||||
map.put("activePeak", statValue.activePeak);
|
||||
|
||||
map.put("activePeakTime", statValue.getActivePeakTime());
|
||||
if (statValue.activePeak > 0) {
|
||||
map.put("activePeak", statValue.activePeak);
|
||||
map.put("activePeakTime", statValue.getActivePeakTime());
|
||||
}
|
||||
map.put("poolingCount", statValue.poolingCount);
|
||||
map.put("poolingPeak", statValue.poolingPeak);
|
||||
map.put("poolingPeakTime", statValue.getPoolingPeakTime());
|
||||
if (statValue.poolingPeak > 0) {
|
||||
map.put("poolingPeak", statValue.poolingPeak);
|
||||
map.put("poolingPeakTime", statValue.getPoolingPeakTime());
|
||||
}
|
||||
map.put("connectCount", statValue.connectCount);
|
||||
|
||||
map.put("closeCount", statValue.closeCount);
|
||||
map.put("waitThreadCount", statValue.waitThreadCount);
|
||||
map.put("notEmptyWaitCount", statValue.notEmptyWaitCount);
|
||||
map.put("notEmptyWaitMillis", statValue.getNotEmptyWaitMillis());
|
||||
map.put("logicConnectErrorCount", statValue.logicConnectErrorCount);
|
||||
|
||||
map.put("physicalConnectCount", statValue.physicalConnectCount);
|
||||
map.put("physicalCloseCount", statValue.physicalCloseCount);
|
||||
map.put("physicalConnectErrorCount", statValue.physicalConnectErrorCount);
|
||||
map.put("executeCount", statValue.executeCount);
|
||||
if (statValue.waitThreadCount > 0) {
|
||||
map.put("waitThreadCount", statValue.waitThreadCount);
|
||||
}
|
||||
if (statValue.notEmptyWaitCount > 0) {
|
||||
map.put("notEmptyWaitCount", statValue.notEmptyWaitCount);
|
||||
}
|
||||
if (statValue.getNotEmptyWaitMillis() > 0) {
|
||||
map.put("notEmptyWaitMillis", statValue.getNotEmptyWaitMillis());
|
||||
}
|
||||
if (statValue.logicConnectErrorCount > 0) {
|
||||
map.put("logicConnectErrorCount", statValue.logicConnectErrorCount);
|
||||
}
|
||||
if (statValue.physicalConnectCount > 0) {
|
||||
map.put("physicalConnectCount", statValue.physicalConnectCount);
|
||||
}
|
||||
if (statValue.physicalCloseCount > 0) {
|
||||
map.put("physicalCloseCount", statValue.physicalCloseCount);
|
||||
}
|
||||
if (statValue.physicalConnectErrorCount > 0) {
|
||||
map.put("physicalConnectErrorCount", statValue.physicalConnectErrorCount);
|
||||
}
|
||||
if (statValue.executeCount > 0) {
|
||||
map.put("executeCount", statValue.executeCount);
|
||||
}
|
||||
if (statValue.errorCount > 0) {
|
||||
map.put("errorCount", statValue.errorCount);
|
||||
}
|
||||
@@ -64,13 +85,19 @@ public class DruidDataSourceStatLoggerImpl implements DruidDataSourceStatLogger
|
||||
if (statValue.rollbackCount > 0) {
|
||||
map.put("rollbackCount", statValue.rollbackCount);
|
||||
}
|
||||
map.put("pstmtCacheHitCount", statValue.pstmtCacheHitCount);
|
||||
map.put("pstmtCacheMissCount", statValue.pstmtCacheMissCount);
|
||||
if (statValue.pstmtCacheHitCount > 0) {
|
||||
map.put("pstmtCacheHitCount", statValue.pstmtCacheHitCount);
|
||||
}
|
||||
if (statValue.pstmtCacheMissCount > 0) {
|
||||
map.put("pstmtCacheMissCount", statValue.pstmtCacheMissCount);
|
||||
}
|
||||
if (statValue.startTransactionCount > 0) {
|
||||
map.put("startTransactionCount", statValue.startTransactionCount);
|
||||
map.put("transactionHistogram", statValue.transactionHistogram);
|
||||
map.put("transactionHistogram", rtrim(statValue.transactionHistogram));
|
||||
}
|
||||
if (statValue.connectCount > 0) {
|
||||
map.put("connectionHoldTimeHistogram", rtrim(statValue.connectionHoldTimeHistogram));
|
||||
}
|
||||
map.put("connectionHoldTimeHistogram", statValue.connectionHoldTimeHistogram);
|
||||
if (statValue.clobOpenCount > 0) {
|
||||
map.put("clobOpenCount", statValue.clobOpenCount);
|
||||
}
|
||||
@@ -79,47 +106,57 @@ public class DruidDataSourceStatLoggerImpl implements DruidDataSourceStatLogger
|
||||
}
|
||||
|
||||
ArrayList<Map<String, Object>> sqlList = new ArrayList<Map<String, Object>>();
|
||||
for (JdbcSqlStatValue sqlStat : statValue.sqlList) {
|
||||
Map<String, Object> sqlStatMap = new LinkedHashMap<String, Object>();
|
||||
sqlStatMap.put("sql", sqlStat.sql);
|
||||
sqlStatMap.put("executeCount", sqlStat.getExecuteCount());
|
||||
if (sqlStat.executeErrorCount > 0) {
|
||||
sqlStatMap.put("executeErrorCount", sqlStat.executeErrorCount);
|
||||
}
|
||||
if (sqlStat.runningCount > 0) {
|
||||
sqlStatMap.put("runningCount", sqlStat.runningCount);
|
||||
}
|
||||
sqlStatMap.put("concurrentMax", sqlStat.concurrentMax);
|
||||
if (statValue.sqlList.size() > 0) {
|
||||
for (JdbcSqlStatValue sqlStat : statValue.sqlList) {
|
||||
Map<String, Object> sqlStatMap = new LinkedHashMap<String, Object>();
|
||||
sqlStatMap.put("sql", sqlStat.sql);
|
||||
|
||||
sqlStatMap.put("executeMillisMax", sqlStat.getExecuteMillisMax());
|
||||
sqlStatMap.put("executeMillisTotal", sqlStat.getExecuteMillisTotal());
|
||||
if (sqlStat.getExecuteCount() > 0) {
|
||||
sqlStatMap.put("executeCount", sqlStat.getExecuteCount());
|
||||
sqlStatMap.put("executeMillisMax", sqlStat.getExecuteMillisMax());
|
||||
sqlStatMap.put("executeMillisTotal", sqlStat.getExecuteMillisTotal());
|
||||
|
||||
sqlStatMap.put("executeHistogram", sqlStat.getExecuteHistogram());
|
||||
sqlStatMap.put("executeAndResultHoldHistogram", sqlStat.getExecuteAndResultHoldHistogram());
|
||||
if (sqlStat.fetchRowCount > 0) {
|
||||
sqlStatMap.put("fetchRowCount", sqlStat.fetchRowCount);
|
||||
sqlStatMap.put("fetchRowCount", sqlStat.fetchRowCountMax);
|
||||
sqlStatMap.put("fetchRowHistogram", sqlStat.getFetchRowHistogram());
|
||||
}
|
||||
sqlStatMap.put("executeHistogram", rtrim(sqlStat.getExecuteHistogram()));
|
||||
sqlStatMap.put("executeAndResultHoldHistogram",
|
||||
rtrim(sqlStat.getExecuteAndResultHoldHistogram()));
|
||||
}
|
||||
|
||||
if (sqlStat.updateCount > 0) {
|
||||
sqlStatMap.put("updateCount", sqlStat.updateCount);
|
||||
sqlStatMap.put("updateCountMax", sqlStat.updateCountMax);
|
||||
sqlStatMap.put("updateHistogram", sqlStat.getUpdateHistogram());
|
||||
}
|
||||
if (sqlStat.executeErrorCount > 0) {
|
||||
sqlStatMap.put("executeErrorCount", sqlStat.executeErrorCount);
|
||||
}
|
||||
if (sqlStat.runningCount > 0) {
|
||||
sqlStatMap.put("runningCount", sqlStat.runningCount);
|
||||
}
|
||||
sqlStatMap.put("concurrentMax", sqlStat.concurrentMax);
|
||||
|
||||
if (sqlStat.inTransactionCount > 0) {
|
||||
sqlStatMap.put("inTransactionCount", sqlStat.inTransactionCount);
|
||||
}
|
||||
if (sqlStat.fetchRowCount > 0) {
|
||||
sqlStatMap.put("fetchRowCount", sqlStat.fetchRowCount);
|
||||
sqlStatMap.put("fetchRowCount", sqlStat.fetchRowCountMax);
|
||||
sqlStatMap.put("fetchRowHistogram", rtrim(sqlStat.getFetchRowHistogram()));
|
||||
}
|
||||
|
||||
if (sqlStat.clobOpenCount > 0) {
|
||||
sqlStatMap.put("clobOpenCount", sqlStat.clobOpenCount);
|
||||
}
|
||||
if (sqlStat.updateCount > 0) {
|
||||
sqlStatMap.put("updateCount", sqlStat.updateCount);
|
||||
sqlStatMap.put("updateCountMax", sqlStat.updateCountMax);
|
||||
sqlStatMap.put("updateHistogram", rtrim(sqlStat.getUpdateHistogram()));
|
||||
}
|
||||
|
||||
if (sqlStat.blobOpenCount > 0) {
|
||||
sqlStatMap.put("blobOpenCount", sqlStat.blobOpenCount);
|
||||
if (sqlStat.inTransactionCount > 0) {
|
||||
sqlStatMap.put("inTransactionCount", sqlStat.inTransactionCount);
|
||||
}
|
||||
|
||||
if (sqlStat.clobOpenCount > 0) {
|
||||
sqlStatMap.put("clobOpenCount", sqlStat.clobOpenCount);
|
||||
}
|
||||
|
||||
if (sqlStat.blobOpenCount > 0) {
|
||||
sqlStatMap.put("blobOpenCount", sqlStat.blobOpenCount);
|
||||
}
|
||||
|
||||
sqlList.add(sqlStatMap);
|
||||
}
|
||||
|
||||
map.put("sqlList", sqlList);
|
||||
}
|
||||
|
||||
String text = JSONUtils.toJSONString(map);
|
||||
|
||||
Reference in New Issue
Block a user