mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve WebSessionStat
This commit is contained in:
@@ -89,10 +89,6 @@ public class WebStatFilter implements Filter {
|
||||
WebRequestStat.set(requestStat);
|
||||
|
||||
WebSessionStat sessionStat = getSessionStat(httpRequest);
|
||||
if (sessionStat != null) {
|
||||
sessionStat.beforeInvoke();
|
||||
}
|
||||
|
||||
webAppStat.beforeInvoke();
|
||||
|
||||
WebURIStat uriStat = webAppStat.getURIStat(requestURI, false);
|
||||
|
||||
@@ -8,33 +8,37 @@ import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.alibaba.druid.util.Histogram;
|
||||
|
||||
public class WebSessionStat {
|
||||
|
||||
private final String sessionId;
|
||||
|
||||
private final AtomicInteger runningCount = new AtomicInteger();
|
||||
private final AtomicInteger concurrentMax = new AtomicInteger();
|
||||
private final AtomicLong requestCount = new AtomicLong(0);
|
||||
private final AtomicLong requestErrorCount = new AtomicLong(0);
|
||||
private final AtomicLong requestTimeNano = new AtomicLong();
|
||||
private final AtomicInteger runningCount = new AtomicInteger();
|
||||
private final AtomicInteger concurrentMax = new AtomicInteger();
|
||||
private final AtomicLong requestCount = new AtomicLong(0);
|
||||
private final AtomicLong requestErrorCount = new AtomicLong(0);
|
||||
private final AtomicLong requestTimeNano = new AtomicLong();
|
||||
|
||||
private final AtomicLong jdbcFetchRowCount = new AtomicLong();
|
||||
private final AtomicLong jdbcUpdateCount = new AtomicLong();
|
||||
private final AtomicLong jdbcExecuteCount = new AtomicLong();
|
||||
private final AtomicLong jdbcExecuteTimeNano = new AtomicLong();
|
||||
private final AtomicLong jdbcFetchRowCount = new AtomicLong();
|
||||
private final AtomicLong jdbcUpdateCount = new AtomicLong();
|
||||
private final AtomicLong jdbcExecuteCount = new AtomicLong();
|
||||
private final AtomicLong jdbcExecuteTimeNano = new AtomicLong();
|
||||
|
||||
private final AtomicLong jdbcCommitCount = new AtomicLong();
|
||||
private final AtomicLong jdbcRollbackCount = new AtomicLong();
|
||||
private final AtomicLong jdbcCommitCount = new AtomicLong();
|
||||
private final AtomicLong jdbcRollbackCount = new AtomicLong();
|
||||
|
||||
private long createTimeMillis = -1L;
|
||||
private long lastAccessTimeMillis = -1L;
|
||||
private long createTimeMillis = -1L;
|
||||
private volatile long lastAccessTimeMillis = -1L;
|
||||
|
||||
private Set<String> remoteAddresses = new HashSet<String>();
|
||||
private Set<String> remoteAddresses = new HashSet<String>();
|
||||
|
||||
private String principal = null;
|
||||
private String principal = null;
|
||||
|
||||
private String userAgent;
|
||||
|
||||
private Histogram requestIntervalHistogram = Histogram.makeHistogram(8);
|
||||
|
||||
public WebSessionStat(String sessionId){
|
||||
super();
|
||||
this.sessionId = sessionId;
|
||||
@@ -55,6 +59,8 @@ public class WebSessionStat {
|
||||
|
||||
remoteAddresses.clear();
|
||||
principal = null;
|
||||
|
||||
requestIntervalHistogram.reset();
|
||||
}
|
||||
|
||||
public String getUserAgent() {
|
||||
@@ -130,6 +136,10 @@ public class WebSessionStat {
|
||||
}
|
||||
|
||||
public void setLastAccessTimeMillis(long lastAccessTimeMillis) {
|
||||
if (this.lastAccessTimeMillis > 0) {
|
||||
long interval = lastAccessTimeMillis - this.lastAccessTimeMillis;
|
||||
requestIntervalHistogram.record(interval);
|
||||
}
|
||||
this.lastAccessTimeMillis = lastAccessTimeMillis;
|
||||
}
|
||||
|
||||
@@ -150,7 +160,7 @@ public class WebSessionStat {
|
||||
}
|
||||
|
||||
incrementRequestCount();
|
||||
|
||||
|
||||
WebRequestStat requestStat = WebRequestStat.current();
|
||||
if (requestStat != null) {
|
||||
this.setLastAccessTimeMillis(requestStat.getStartMillis());
|
||||
@@ -161,9 +171,9 @@ public class WebSessionStat {
|
||||
requestCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public void afterInvoke(Throwable error, long nanoSpan) {
|
||||
public void afterInvoke(Throwable error, long nanos) {
|
||||
runningCount.decrementAndGet();
|
||||
reacord(nanoSpan);
|
||||
reacord(nanos);
|
||||
}
|
||||
|
||||
public void reacord(long nanos) {
|
||||
@@ -272,6 +282,10 @@ public class WebSessionStat {
|
||||
this.jdbcRollbackCount.addAndGet(rollbackCount);
|
||||
}
|
||||
|
||||
public long[] getRequestInterval() {
|
||||
return requestIntervalHistogram.toArray();
|
||||
}
|
||||
|
||||
public Map<String, Object> getStatData() {
|
||||
Map<String, Object> data = new LinkedHashMap<String, Object>();
|
||||
|
||||
@@ -293,8 +307,9 @@ public class WebSessionStat {
|
||||
data.put("JdbcExecuteTimeMillis", this.getJdbcExecuteTimeMillis());
|
||||
data.put("JdbcFetchRowCount", this.getJdbcFetchRowCount());
|
||||
data.put("JdbcUpdateCount", this.getJdbcUpdateCount());
|
||||
|
||||
|
||||
data.put("UserAgent", this.getUserAgent());
|
||||
data.put("RequestInterval", this.getRequestInterval());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,16 @@ public class Histogram {
|
||||
rangeCounters[i] = new AtomicLong();
|
||||
}
|
||||
}
|
||||
|
||||
public static Histogram makeHistogram(int rangeCount) {
|
||||
long[] rangeValues = new long[rangeCount];
|
||||
|
||||
for (int i = 0; i < rangeValues.length; ++i) {
|
||||
rangeValues[i] = (long) Math.pow(10, i);
|
||||
}
|
||||
|
||||
return new Histogram(rangeValues);
|
||||
}
|
||||
|
||||
public Histogram(TimeUnit timeUnit, long... ranges){
|
||||
this.ranges = new long[ranges.length];
|
||||
|
||||
Reference in New Issue
Block a user