mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve web sessionStat
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.druid.support.http.stat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -20,7 +21,7 @@ public class WebAppStat {
|
||||
private final static Log LOG = LogFactory.getLog(WebAppStat.class);
|
||||
|
||||
public final static int DEFAULT_MAX_STAT_URI_COUNT = 1000;
|
||||
public final static int DEFAULT_MAX_STAT_SESSION_COUNT = 1000 * 100;
|
||||
public final static int DEFAULT_MAX_STAT_SESSION_COUNT = 1000;
|
||||
|
||||
private volatile int maxStatUriCount = DEFAULT_MAX_STAT_URI_COUNT;
|
||||
private volatile int maxStatSessionCount = DEFAULT_MAX_STAT_SESSION_COUNT;
|
||||
@@ -32,7 +33,7 @@ public class WebAppStat {
|
||||
private final static ThreadLocal<WebAppStat> currentLocal = new ThreadLocal<WebAppStat>();
|
||||
|
||||
private final ConcurrentMap<String, WebURIStat> uriStatMap = new ConcurrentHashMap<String, WebURIStat>();
|
||||
private final Map<String, WebSessionStat> sessionStatMap;
|
||||
private final LRUCache<String, WebSessionStat> sessionStatMap;
|
||||
|
||||
private final ReadWriteLock sessionStatLock = new ReentrantReadWriteLock();
|
||||
|
||||
@@ -50,15 +51,20 @@ public class WebAppStat {
|
||||
requestCount.set(0);
|
||||
requestCount.set(0);
|
||||
|
||||
sessionStatLock.writeLock().lock();
|
||||
sessionStatLock.readLock().lock();
|
||||
try {
|
||||
Iterator<Map.Entry<String, WebSessionStat>> iter = sessionStatMap.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<String, WebSessionStat> entry = iter.next();
|
||||
entry.getValue().reset();
|
||||
}
|
||||
sessionStatMap.clear();
|
||||
} finally {
|
||||
sessionStatLock.writeLock().unlock();
|
||||
sessionStatLock.readLock().unlock();
|
||||
}
|
||||
|
||||
|
||||
uriStatMap.clear();
|
||||
|
||||
|
||||
uriStatMapFullCount.set(0);
|
||||
uriSessionMapFullCount.set(0);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ public class WebSessionStat {
|
||||
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();
|
||||
@@ -25,17 +26,34 @@ public class WebSessionStat {
|
||||
private final AtomicLong jdbcCommitCount = new AtomicLong();
|
||||
private final AtomicLong jdbcRollbackCount = new AtomicLong();
|
||||
|
||||
private final AtomicLong requestTimeNano = new AtomicLong();
|
||||
|
||||
private long createTimeMillis = -1L;
|
||||
private long lastAccessTimeMillis = -1L;
|
||||
|
||||
private Set<String> remoteAddresses = new HashSet<String>();
|
||||
|
||||
private String principal = null;
|
||||
|
||||
public WebSessionStat(String sessionId){
|
||||
super();
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
concurrentMax.set(0);
|
||||
requestCount.set(0);
|
||||
requestErrorCount.set(0);
|
||||
requestTimeNano.set(0);
|
||||
|
||||
jdbcFetchRowCount.set(0);
|
||||
jdbcUpdateCount.set(0);
|
||||
jdbcExecuteCount.set(0);
|
||||
jdbcExecuteTimeNano.set(0);
|
||||
jdbcCommitCount.set(0);
|
||||
jdbcRollbackCount.set(0);
|
||||
|
||||
remoteAddresses.clear();
|
||||
principal = null;
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return sessionId;
|
||||
@@ -53,6 +71,14 @@ public class WebSessionStat {
|
||||
return new Date(createTimeMillis);
|
||||
}
|
||||
|
||||
public String getPrincipal() {
|
||||
return principal;
|
||||
}
|
||||
|
||||
public void setPrincipal(String principal) {
|
||||
this.principal = principal;
|
||||
}
|
||||
|
||||
public void setCreateTimeMillis(long createTimeMillis) {
|
||||
this.createTimeMillis = createTimeMillis;
|
||||
}
|
||||
@@ -154,7 +180,7 @@ public class WebSessionStat {
|
||||
public long getRequestCount() {
|
||||
return requestCount.get();
|
||||
}
|
||||
|
||||
|
||||
public long getRequestErrorCount() {
|
||||
return requestErrorCount.get();
|
||||
}
|
||||
@@ -242,6 +268,7 @@ public class WebSessionStat {
|
||||
data.put("CreateTime", this.getCreateTime());
|
||||
data.put("LastAccessTime", this.getLastAccessTime());
|
||||
data.put("RemoteAddress", this.getRemoteAddress());
|
||||
data.put("Principal", this.getPrincipal());
|
||||
|
||||
data.put("JdbcCommitCount", this.getJdbcCommitCount());
|
||||
data.put("JdbcRollbackCount", this.getJdbcRollbackCount());
|
||||
|
||||
Reference in New Issue
Block a user