mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed sql runningCount & add statLog support
This commit is contained in:
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.druid.stat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -257,7 +258,7 @@ public class JdbcDataSourceStat implements JdbcDataSourceStatMBean {
|
||||
}
|
||||
|
||||
public Map<String, JdbcSqlStat> getSqlStatMap() {
|
||||
Map<String, JdbcSqlStat> map = new HashMap<String, JdbcSqlStat>();
|
||||
Map<String, JdbcSqlStat> map = new LinkedHashMap<String, JdbcSqlStat>(sqlStatMap.size());
|
||||
lock.readLock().lock();
|
||||
try {
|
||||
map.putAll(sqlStatMap);
|
||||
@@ -266,6 +267,34 @@ public class JdbcDataSourceStat implements JdbcDataSourceStatMBean {
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public List<JdbcSqlStatValue> getSqlStatMapAndReset() {
|
||||
List<JdbcSqlStat> stats = new ArrayList<JdbcSqlStat>(sqlStatMap.size());
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
Iterator<Map.Entry<String, JdbcSqlStat>> iter = sqlStatMap.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<String, JdbcSqlStat> entry = iter.next();
|
||||
JdbcSqlStat stat = entry.getValue();
|
||||
if (stat.getExecuteCount() == 0 && stat.getRunningCount() == 0) {
|
||||
stat.setRemoved(true);
|
||||
iter.remove();
|
||||
} else {
|
||||
stats.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
|
||||
List<JdbcSqlStatValue> values = new ArrayList<JdbcSqlStatValue>(stats.size());
|
||||
for (int i = 0; i < stats.size(); ++i) {
|
||||
JdbcSqlStat stat = stats.get(i);
|
||||
JdbcSqlStatValue value = stat.getValueAndReset();
|
||||
values.add(value);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public JdbcSqlStat getSqlStat(String sql) {
|
||||
lock.readLock().lock();
|
||||
@@ -346,6 +375,10 @@ public class JdbcDataSourceStat implements JdbcDataSourceStatMBean {
|
||||
public long getClobOpenCount() {
|
||||
return clobOpenCount.get();
|
||||
}
|
||||
|
||||
public long getClobOpenCountAndReset() {
|
||||
return clobOpenCount.getAndSet(0);
|
||||
}
|
||||
|
||||
public void incrementClobOpenCount() {
|
||||
clobOpenCount.incrementAndGet();
|
||||
@@ -354,6 +387,10 @@ public class JdbcDataSourceStat implements JdbcDataSourceStatMBean {
|
||||
public long getBlobOpenCount() {
|
||||
return blobOpenCount.get();
|
||||
}
|
||||
|
||||
public long getBlobOpenCountAndReset() {
|
||||
return blobOpenCount.getAndSet(0);
|
||||
}
|
||||
|
||||
public void incrementBlobOpenCount() {
|
||||
blobOpenCount.incrementAndGet();
|
||||
|
||||
@@ -323,7 +323,6 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
executeSpanNanoTotalUpdater.set(this, 0);
|
||||
executeSpanNanoMaxUpdater.set(this, 0);
|
||||
executeNanoSpanMaxOccurTime = 0;
|
||||
runningCountUpdater.set(this, 0);
|
||||
concurrentMaxUpdater.set(this, 0);
|
||||
|
||||
executeErrorCountUpdater.set(this, 0);
|
||||
@@ -380,6 +379,87 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
readerOpenCountUpdater.set(this, 0);
|
||||
}
|
||||
|
||||
public JdbcSqlStatValue getValueAndReset() {
|
||||
JdbcSqlStatValue val = new JdbcSqlStatValue();
|
||||
|
||||
val.executeLastStartTime = executeLastStartTime;
|
||||
executeLastStartTime = 0;
|
||||
|
||||
val.executeBatchSizeTotal = executeBatchSizeTotalUpdater.getAndSet(this, 0);
|
||||
val.executeBatchSizeMax = executeBatchSizeMaxUpdater.getAndSet(this, 0);
|
||||
|
||||
val.executeSuccessCount = executeSuccessCountUpdater.getAndSet(this, 0);
|
||||
val.executeSpanNanoTotal = executeSpanNanoTotalUpdater.getAndSet(this, 0);
|
||||
val.executeSpanNanoMax = executeSpanNanoMaxUpdater.getAndSet(this, 0);
|
||||
val.executeNanoSpanMaxOccurTime = executeNanoSpanMaxOccurTime;
|
||||
executeNanoSpanMaxOccurTime = 0;
|
||||
|
||||
val.runningCount = this.runningCount;
|
||||
|
||||
val.concurrentMax = concurrentMaxUpdater.getAndSet(this, 0);
|
||||
|
||||
val.executeErrorCount = executeErrorCountUpdater.getAndSet(this, 0);
|
||||
|
||||
val.executeErrorLast = executeErrorLast;
|
||||
executeErrorLast = null;
|
||||
|
||||
val.executeErrorLastTime = executeErrorLastTime;
|
||||
executeErrorLastTime = 0;
|
||||
|
||||
val.updateCount = updateCountUpdater.getAndSet(this, 0);
|
||||
val.updateCountMax = updateCountMaxUpdater.getAndSet(this, 0);
|
||||
val.fetchRowCount = fetchRowCountUpdater.getAndSet(this, 0);
|
||||
val.fetchRowCountMax = fetchRowCountMaxUpdater.getAndSet(this, 0);
|
||||
|
||||
val.histogram_0_1 = histogram_0_1_Updater.getAndSet(this, 0);
|
||||
val.histogram_1_10 = histogram_1_10_Updater.getAndSet(this, 0);
|
||||
val.histogram_10_100 = histogram_10_100_Updater.getAndSet(this, 0);
|
||||
val.histogram_100_1000 = histogram_100_1000_Updater.getAndSet(this, 0);
|
||||
val.histogram_1000_10000 = histogram_1000_10000_Updater.getAndSet(this, 0);
|
||||
val.histogram_10000_100000 = histogram_10000_100000_Updater.getAndSet(this, 0);
|
||||
val.histogram_100000_1000000 = histogram_100000_1000000_Updater.getAndSet(this, 0);
|
||||
val.histogram_1000000_more = histogram_1000000_more_Updater.getAndSet(this, 0);
|
||||
|
||||
val.lastSlowParameters = lastSlowParameters;
|
||||
lastSlowParameters = null;
|
||||
|
||||
val.inTransactionCount = inTransactionCountUpdater.getAndSet(this, 0);
|
||||
val.resultSetHoldTimeNano = resultSetHoldTimeNanoUpdater.getAndSet(this, 0);
|
||||
val.executeAndResultSetHoldTime = executeAndResultSetHoldTimeUpdater.getAndSet(this, 0);
|
||||
|
||||
val.fetchRowCount_0_1 = fetchRowCount_0_1_Updater.getAndSet(this, 0);
|
||||
val.fetchRowCount_1_10 = fetchRowCount_1_10_Updater.getAndSet(this, 0);
|
||||
val.fetchRowCount_10_100 = fetchRowCount_10_100_Updater.getAndSet(this, 0);
|
||||
val.fetchRowCount_100_1000 = fetchRowCount_100_1000_Updater.getAndSet(this, 0);
|
||||
val.fetchRowCount_1000_10000 = fetchRowCount_1000_10000_Updater.getAndSet(this, 0);
|
||||
val.fetchRowCount_10000_more = fetchRowCount_10000_more_Updater.getAndSet(this, 0);
|
||||
|
||||
val.updateCount_0_1 = updateCount_0_1_Updater.getAndSet(this, 0);
|
||||
val.updateCount_1_10 = updateCount_1_10_Updater.getAndSet(this, 0);
|
||||
val.updateCount_10_100 = updateCount_10_100_Updater.getAndSet(this, 0);
|
||||
val.updateCount_100_1000 = updateCount_100_1000_Updater.getAndSet(this, 0);
|
||||
val.updateCount_1000_10000 = updateCount_1000_10000_Updater.getAndSet(this, 0);
|
||||
val.updateCount_10000_more = updateCount_10000_more_Updater.getAndSet(this, 0);
|
||||
|
||||
val.executeAndResultHoldTime_0_1 = executeAndResultHoldTime_0_1_Updater.getAndSet(this, 0);
|
||||
val.executeAndResultHoldTime_1_10 = executeAndResultHoldTime_1_10_Updater.getAndSet(this, 0);
|
||||
val.executeAndResultHoldTime_10_100 = executeAndResultHoldTime_10_100_Updater.getAndSet(this, 0);
|
||||
val.executeAndResultHoldTime_100_1000 = executeAndResultHoldTime_100_1000_Updater.getAndSet(this, 0);
|
||||
val.executeAndResultHoldTime_1000_10000 = executeAndResultHoldTime_1000_10000_Updater.getAndSet(this, 0);
|
||||
val.executeAndResultHoldTime_10000_100000 = executeAndResultHoldTime_10000_100000_Updater.getAndSet(this, 0);
|
||||
val.executeAndResultHoldTime_100000_1000000 = executeAndResultHoldTime_100000_1000000_Updater.getAndSet(this, 0);
|
||||
val.executeAndResultHoldTime_1000000_more = executeAndResultHoldTime_1000000_more_Updater.getAndSet(this, 0);
|
||||
|
||||
val.blobOpenCount = blobOpenCountUpdater.getAndSet(this, 0);
|
||||
val.clobOpenCount = clobOpenCountUpdater.getAndSet(this, 0);
|
||||
val.readStringLength = readStringLengthUpdater.getAndSet(this, 0);
|
||||
val.readBytesLength = readBytesLengthUpdater.getAndSet(this, 0);
|
||||
val.inputStreamOpenCount = inputStreamOpenCountUpdater.getAndSet(this, 0);
|
||||
val.readerOpenCount = readerOpenCountUpdater.getAndSet(this, 0);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public long getConcurrentMax() {
|
||||
return concurrentMax;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.stat;
|
||||
|
||||
public class JdbcSqlStatValue {
|
||||
|
||||
public String sql;
|
||||
public long id;
|
||||
public String dataSource;
|
||||
public long executeLastStartTime;
|
||||
|
||||
public long executeBatchSizeTotal;
|
||||
public int executeBatchSizeMax;
|
||||
|
||||
public long executeSuccessCount;
|
||||
public long executeSpanNanoTotal;
|
||||
public long executeSpanNanoMax;
|
||||
public int runningCount;
|
||||
public int concurrentMax;
|
||||
public long resultSetHoldTimeNano;
|
||||
public long executeAndResultSetHoldTime;
|
||||
|
||||
public String name;
|
||||
public String file;
|
||||
public String dbType;
|
||||
|
||||
public long executeNanoSpanMaxOccurTime;
|
||||
|
||||
public long executeErrorCount;
|
||||
public Throwable executeErrorLast;
|
||||
public long executeErrorLastTime;
|
||||
|
||||
public long updateCount;
|
||||
public long updateCountMax;
|
||||
public long fetchRowCount;
|
||||
public long fetchRowCountMax;
|
||||
|
||||
public long inTransactionCount;
|
||||
|
||||
public String lastSlowParameters;
|
||||
|
||||
public long clobOpenCount;
|
||||
public long blobOpenCount;
|
||||
public long readStringLength;
|
||||
public long readBytesLength;
|
||||
|
||||
public long inputStreamOpenCount;
|
||||
public long readerOpenCount;
|
||||
|
||||
public long histogram_0_1;
|
||||
public long histogram_1_10;
|
||||
public int histogram_10_100;
|
||||
public int histogram_100_1000;
|
||||
public int histogram_1000_10000;
|
||||
public int histogram_10000_100000;
|
||||
public int histogram_100000_1000000;
|
||||
public int histogram_1000000_more;
|
||||
|
||||
public long executeAndResultHoldTime_0_1;
|
||||
public long executeAndResultHoldTime_1_10;
|
||||
public int executeAndResultHoldTime_10_100;
|
||||
public int executeAndResultHoldTime_100_1000;
|
||||
public int executeAndResultHoldTime_1000_10000;
|
||||
public int executeAndResultHoldTime_10000_100000;
|
||||
public int executeAndResultHoldTime_100000_1000000;
|
||||
public int executeAndResultHoldTime_1000000_more;
|
||||
|
||||
public long fetchRowCount_0_1;
|
||||
public long fetchRowCount_1_10;
|
||||
public long fetchRowCount_10_100;
|
||||
public int fetchRowCount_100_1000;
|
||||
public int fetchRowCount_1000_10000;
|
||||
public int fetchRowCount_10000_more;
|
||||
|
||||
public long updateCount_0_1;
|
||||
public long updateCount_1_10;
|
||||
public long updateCount_10_100;
|
||||
public int updateCount_100_1000;
|
||||
public int updateCount_1000_10000;
|
||||
public int updateCount_10000_more;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user