mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve weburi stat
This commit is contained in:
@@ -48,7 +48,7 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
|
||||
protected StatementExecuteType lastExecuteType;
|
||||
|
||||
protected Integer updateCount = null;
|
||||
protected Integer updateCount = null;
|
||||
|
||||
private FilterChainImpl filterChain = null;
|
||||
|
||||
@@ -319,9 +319,11 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
|
||||
@Override
|
||||
public boolean getMoreResults() throws SQLException {
|
||||
updateCount = null;
|
||||
FilterChainImpl chain = createChain();
|
||||
boolean value = chain.statement_getMoreResults(this);
|
||||
if (value) {
|
||||
updateCount = null;
|
||||
}
|
||||
recycleFilterChain(chain);
|
||||
return value;
|
||||
}
|
||||
@@ -549,21 +551,21 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro
|
||||
public boolean isFirstResultSet() {
|
||||
return firstResultSet;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
if (iface == StatementProxy.class) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
||||
return super.unwrap(iface);
|
||||
}
|
||||
|
||||
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
if (iface == StatementProxy.class) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return super.isWrapperFor(iface);
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +102,32 @@ public class WebURIStat {
|
||||
|
||||
private final static ThreadLocal<WebURIStat> currentLocal = new ThreadLocal<WebURIStat>();
|
||||
|
||||
private volatile long histogram_0_1;
|
||||
private volatile long histogram_1_10;
|
||||
private volatile long histogram_10_100;
|
||||
private volatile long histogram_100_1000;
|
||||
private volatile int histogram_1000_10000;
|
||||
private volatile int histogram_10000_100000;
|
||||
private volatile int histogram_100000_1000000;
|
||||
private volatile int histogram_1000000_more;
|
||||
|
||||
final static AtomicLongFieldUpdater<WebURIStat> histogram_0_1_Updater = AtomicLongFieldUpdater.newUpdater(WebURIStat.class,
|
||||
"histogram_0_1");
|
||||
final static AtomicLongFieldUpdater<WebURIStat> histogram_1_10_Updater = AtomicLongFieldUpdater.newUpdater(WebURIStat.class,
|
||||
"histogram_1_10");
|
||||
final static AtomicLongFieldUpdater<WebURIStat> histogram_10_100_Updater = AtomicLongFieldUpdater.newUpdater(WebURIStat.class,
|
||||
"histogram_10_100");
|
||||
final static AtomicLongFieldUpdater<WebURIStat> histogram_100_1000_Updater = AtomicLongFieldUpdater.newUpdater(WebURIStat.class,
|
||||
"histogram_100_1000");
|
||||
final static AtomicIntegerFieldUpdater<WebURIStat> histogram_1000_10000_Updater = AtomicIntegerFieldUpdater.newUpdater(WebURIStat.class,
|
||||
"histogram_1000_10000");
|
||||
final static AtomicIntegerFieldUpdater<WebURIStat> histogram_10000_100000_Updater = AtomicIntegerFieldUpdater.newUpdater(WebURIStat.class,
|
||||
"histogram_10000_100000");
|
||||
final static AtomicIntegerFieldUpdater<WebURIStat> histogram_100000_1000000_Updater = AtomicIntegerFieldUpdater.newUpdater(WebURIStat.class,
|
||||
"histogram_100000_1000000");
|
||||
final static AtomicIntegerFieldUpdater<WebURIStat> histogram_1000000_more_Updater = AtomicIntegerFieldUpdater.newUpdater(WebURIStat.class,
|
||||
"histogram_1000000_more");
|
||||
|
||||
public WebURIStat(String uri){
|
||||
super();
|
||||
this.uri = uri;
|
||||
@@ -145,6 +171,8 @@ public class WebURIStat {
|
||||
runningCountUpdater.decrementAndGet(this);
|
||||
requestTimeNanoUpdater.addAndGet(this, nanos);
|
||||
|
||||
histogramRecord(nanos);
|
||||
|
||||
if (error != null) {
|
||||
errorCountUpdater.incrementAndGet(this);
|
||||
}
|
||||
@@ -212,6 +240,28 @@ public class WebURIStat {
|
||||
currentLocal.set(null);
|
||||
}
|
||||
|
||||
private void histogramRecord(long nanos) {
|
||||
final long millis = nanos / 1000 / 1000;
|
||||
|
||||
if (millis < 1) {
|
||||
histogram_0_1_Updater.incrementAndGet(this);
|
||||
} else if (millis < 10) {
|
||||
histogram_1_10_Updater.incrementAndGet(this);
|
||||
} else if (millis < 100) {
|
||||
histogram_10_100_Updater.incrementAndGet(this);
|
||||
} else if (millis < 1000) {
|
||||
histogram_100_1000_Updater.incrementAndGet(this);
|
||||
} else if (millis < 10000) {
|
||||
histogram_1000_10000_Updater.incrementAndGet(this);
|
||||
} else if (millis < 100000) {
|
||||
histogram_10000_100000_Updater.incrementAndGet(this);
|
||||
} else if (millis < 1000000) {
|
||||
histogram_100000_1000000_Updater.incrementAndGet(this);
|
||||
} else {
|
||||
histogram_1000000_more_Updater.incrementAndGet(this);
|
||||
}
|
||||
}
|
||||
|
||||
public int getRunningCount() {
|
||||
return this.runningCount;
|
||||
}
|
||||
@@ -364,6 +414,20 @@ public class WebURIStat {
|
||||
return profiletat;
|
||||
}
|
||||
|
||||
public long[] getHistogramValues() {
|
||||
return new long[] {
|
||||
//
|
||||
histogram_0_1, //
|
||||
histogram_1_10, //
|
||||
histogram_10_100, //
|
||||
histogram_100_1000, //
|
||||
histogram_1000_10000, //
|
||||
histogram_10000_100000, //
|
||||
histogram_100000_1000000, //
|
||||
histogram_1000000_more //
|
||||
};
|
||||
}
|
||||
|
||||
public WebURIStatValue getValue(boolean reset) {
|
||||
WebURIStatValue val = new WebURIStatValue();
|
||||
|
||||
@@ -399,11 +463,20 @@ public class WebURIStat {
|
||||
val.setLastAccessTimeMillis(get(this, lastAccessTimeMillisUpdater, reset));
|
||||
|
||||
val.setProfileEntryStatValueList(this.getProfiletat().getStatValue(reset));
|
||||
|
||||
val.histogram_0_1 = get(this, histogram_0_1_Updater, reset);
|
||||
val.histogram_1_10 = get(this, histogram_1_10_Updater, reset);
|
||||
val.histogram_10_100 = get(this, histogram_10_100_Updater, reset);
|
||||
val.histogram_100_1000 = get(this, histogram_100_1000_Updater, reset);
|
||||
val.histogram_1000_10000 = get(this, histogram_1000_10000_Updater, reset);
|
||||
val.histogram_10000_100000 = get(this, histogram_10000_100000_Updater, reset);
|
||||
val.histogram_100000_1000000 = get(this, histogram_100000_1000000_Updater, reset);
|
||||
val.histogram_1000000_more = get(this, histogram_1000000_more_Updater, reset);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public Map<String, Object> getStatData() {
|
||||
return getValue(false).getStatData();
|
||||
return getValue(false).getStatData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,27 @@ public class WebURIStatValue {
|
||||
|
||||
private List<ProfileEntryStatValue> profileEntryStatValueList;
|
||||
|
||||
protected long histogram_0_1;
|
||||
protected long histogram_1_10;
|
||||
protected long histogram_10_100;
|
||||
protected long histogram_100_1000;
|
||||
protected int histogram_1000_10000;
|
||||
protected int histogram_10000_100000;
|
||||
protected int histogram_100000_1000000;
|
||||
protected int histogram_1000000_more;
|
||||
|
||||
public long[] getHistogram() {
|
||||
return new long[] { histogram_0_1, //
|
||||
histogram_1_10, //
|
||||
histogram_10_100, //
|
||||
histogram_100_1000, //
|
||||
histogram_1000_10000, //
|
||||
histogram_10000_100000, //
|
||||
histogram_100000_1000000, //
|
||||
histogram_1000000_more, //
|
||||
};
|
||||
}
|
||||
|
||||
public List<ProfileEntryStatValue> getProfileEntryStatValueList() {
|
||||
return profileEntryStatValueList;
|
||||
}
|
||||
@@ -280,6 +301,7 @@ public class WebURIStatValue {
|
||||
|
||||
data.put("JdbcResultSetOpenCount", this.getJdbcResultSetOpenCount());
|
||||
data.put("JdbcResultSetCloseCount", this.getJdbcResultSetCloseCount());
|
||||
data.put("Histogram", this.getHistogram());
|
||||
|
||||
if (this.profileEntryStatValueList != null) {
|
||||
int size = profileEntryStatValueList.size();
|
||||
|
||||
Reference in New Issue
Block a user