mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge remote-tracking branch 'zhb/master'
This commit is contained in:
@@ -86,6 +86,10 @@ public class JSONDruidStatService {
|
||||
if (url.startsWith("/weburi.json")) {
|
||||
return returnJSONResult(RESULT_CODE_SUCCESS, getWebURIStatDataList(parameters));
|
||||
}
|
||||
|
||||
if (url.startsWith("/websession.json")) {
|
||||
return returnJSONResult(RESULT_CODE_SUCCESS, getWebSessionStatDataList(parameters));
|
||||
}
|
||||
|
||||
return returnJSONResult(RESULT_CODE_ERROR, "Do not support this request, please contact with administrator.");
|
||||
}
|
||||
@@ -109,6 +113,11 @@ public class JSONDruidStatService {
|
||||
|
||||
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getWebSessionStatDataList(Map<String, String> parameters) {
|
||||
List<Map<String, Object>> array = WebAppStatManager.getInstance().getSessionStatData();
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,14 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.alibaba.druid.filter.stat.StatFilterContext;
|
||||
import com.alibaba.druid.filter.stat.StatFilterContextListenerAdapter;
|
||||
import com.alibaba.druid.support.http.stat.WebAppStat;
|
||||
import com.alibaba.druid.support.http.stat.WebAppStatManager;
|
||||
import com.alibaba.druid.support.http.stat.WebRequestStat;
|
||||
import com.alibaba.druid.support.http.stat.WebSessionStat;
|
||||
import com.alibaba.druid.support.http.stat.WebURIStat;
|
||||
|
||||
public class WebStatFilter implements Filter {
|
||||
@@ -21,6 +24,8 @@ public class WebStatFilter implements Filter {
|
||||
private WebAppStat webAppStat = null;
|
||||
private WebStatFilterContextListener statFilterContextListener = new WebStatFilterContextListener();
|
||||
|
||||
private boolean createSession = false;
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
|
||||
ServletException {
|
||||
@@ -34,17 +39,60 @@ public class WebStatFilter implements Filter {
|
||||
}
|
||||
|
||||
long startNano = System.nanoTime();
|
||||
|
||||
WebRequestStat requestStat = new WebRequestStat(startNano);
|
||||
WebRequestStat.set(requestStat);
|
||||
WebSessionStat sessionStat = getSessionStat(httpRequest);
|
||||
webAppStat.beforeInvoke(requestURI);
|
||||
|
||||
// 第一次访问时,sessionId为null,如果缺省sessionCreate=false,sessionStat就为null。
|
||||
if (sessionStat != null) {
|
||||
sessionStat.beforeInvoke();
|
||||
}
|
||||
|
||||
try {
|
||||
chain.doFilter(request, response);
|
||||
} finally {
|
||||
long nanoSpan = System.nanoTime() - startNano;
|
||||
long endNano = System.nanoTime();
|
||||
requestStat.setEndNano(endNano);
|
||||
|
||||
long nanoSpan = endNano - startNano;
|
||||
webAppStat.afterInvoke(nanoSpan);
|
||||
|
||||
if (sessionStat != null) {
|
||||
sessionStat.afterInvoke(nanoSpan);
|
||||
} else {
|
||||
sessionStat = getSessionStat(httpRequest);
|
||||
if (sessionStat != null) {
|
||||
sessionStat.reacord(nanoSpan);
|
||||
}
|
||||
}
|
||||
|
||||
WebRequestStat.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
public WebSessionStat getSessionStat(HttpServletRequest httpRequest) {
|
||||
WebSessionStat sessionStat = null;
|
||||
String sessionId = getSessionId(httpRequest);
|
||||
if (sessionId != null) {
|
||||
sessionStat = webAppStat.getSessionStat(sessionId);
|
||||
}
|
||||
|
||||
return sessionStat;
|
||||
}
|
||||
|
||||
public String getSessionId(HttpServletRequest httpRequest) {
|
||||
String sessionId = null;
|
||||
|
||||
HttpSession session = httpRequest.getSession(createSession);
|
||||
if (session != null) {
|
||||
sessionId = session.getId();
|
||||
}
|
||||
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public boolean isExclusion(String uri) {
|
||||
return false;
|
||||
}
|
||||
@@ -77,39 +125,69 @@ public class WebStatFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public void addUpdateCount(int updateCount) {
|
||||
WebURIStat stat = WebURIStat.current();
|
||||
if (stat != null) {
|
||||
stat.addJdbcUpdateCount(updateCount);
|
||||
{
|
||||
WebURIStat stat = WebURIStat.current();
|
||||
if (stat != null) {
|
||||
stat.addJdbcUpdateCount(updateCount);
|
||||
}
|
||||
}
|
||||
{
|
||||
|
||||
WebRequestStat localStat = WebRequestStat.current();
|
||||
if (localStat != null) {
|
||||
localStat.addJdbcUpdateCount(updateCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFetchRowCount(int fetchRowCount) {
|
||||
WebURIStat stat = WebURIStat.current();
|
||||
if (stat != null) {
|
||||
stat.addJdbcFetchRowCount(fetchRowCount);
|
||||
{
|
||||
WebURIStat stat = WebURIStat.current();
|
||||
if (stat != null) {
|
||||
stat.addJdbcFetchRowCount(fetchRowCount);
|
||||
}
|
||||
}
|
||||
{
|
||||
WebRequestStat localStat = WebRequestStat.current();
|
||||
if (localStat != null) {
|
||||
localStat.addJdbcFetchRowCount(fetchRowCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeBefore(String sql, boolean inTransaction) {
|
||||
WebURIStat stat = WebURIStat.current();
|
||||
if (stat != null) {
|
||||
stat.incrementJdbcExecuteCount();
|
||||
{
|
||||
WebURIStat stat = WebURIStat.current();
|
||||
if (stat != null) {
|
||||
stat.incrementJdbcExecuteCount();
|
||||
}
|
||||
}
|
||||
{
|
||||
WebRequestStat localStat = WebRequestStat.current();
|
||||
if (localStat != null) {
|
||||
localStat.incrementJdbcExecuteCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeAfter(String sql, long nanoSpan, Throwable error) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void commit() {
|
||||
WebURIStat stat = WebURIStat.current();
|
||||
if (stat != null) {
|
||||
stat.incrementJdbcCommitCount();
|
||||
}
|
||||
{
|
||||
WebRequestStat localStat = WebRequestStat.current();
|
||||
if (localStat != null) {
|
||||
localStat.incrementJdbcCommitCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,6 +196,13 @@ public class WebStatFilter implements Filter {
|
||||
if (stat != null) {
|
||||
stat.incrementJdbcRollbackCount();
|
||||
}
|
||||
|
||||
{
|
||||
WebRequestStat localStat = WebRequestStat.current();
|
||||
if (localStat != null) {
|
||||
localStat.incrementJdbcRollbackCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,23 +14,27 @@ import com.alibaba.druid.support.logging.LogFactory;
|
||||
|
||||
public class WebAppStat {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(WebAppStat.class);
|
||||
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_URI_COUNT = 1000;
|
||||
public final static int DEFAULT_MAX_STAT_SESSION_COUNT = 1000 * 100;
|
||||
|
||||
private volatile int maxStatUriCount = DEFAULT_MAX_STAT_URI_COUNT;
|
||||
private volatile int maxStatUriCount = DEFAULT_MAX_STAT_URI_COUNT;
|
||||
private volatile int maxStatSessionCount = DEFAULT_MAX_STAT_SESSION_COUNT;
|
||||
|
||||
private final AtomicInteger runningCount = new AtomicInteger();
|
||||
private final AtomicInteger concurrentMax = new AtomicInteger();
|
||||
private final AtomicLong requestCount = new AtomicLong(0);
|
||||
private final AtomicInteger runningCount = new AtomicInteger();
|
||||
private final AtomicInteger concurrentMax = new AtomicInteger();
|
||||
private final AtomicLong requestCount = new AtomicLong(0);
|
||||
|
||||
private final static ThreadLocal<WebAppStat> currentLocal = new ThreadLocal<WebAppStat>();
|
||||
private final static ThreadLocal<WebAppStat> currentLocal = new ThreadLocal<WebAppStat>();
|
||||
|
||||
private final ConcurrentMap<String, WebURIStat> uriStatMap = new ConcurrentHashMap<String, WebURIStat>();
|
||||
private final ConcurrentMap<String, WebURIStat> uriStatMap = new ConcurrentHashMap<String, WebURIStat>();
|
||||
private final ConcurrentMap<String, WebSessionStat> sessionStatMap = new ConcurrentHashMap<String, WebSessionStat>();
|
||||
|
||||
private final AtomicLong uriStatMapFullCount = new AtomicLong();
|
||||
private final AtomicLong uriStatMapFullCount = new AtomicLong();
|
||||
private final AtomicLong uriSessionMapFullCount = new AtomicLong();
|
||||
|
||||
private String contextPath;
|
||||
private String contextPath;
|
||||
|
||||
public static WebAppStat current() {
|
||||
return currentLocal.get();
|
||||
@@ -80,7 +84,7 @@ public class WebAppStat {
|
||||
long fullCount = uriStatMapFullCount.getAndIncrement();
|
||||
|
||||
if (fullCount == 0) {
|
||||
LOG.error("urlStatMap is full");
|
||||
LOG.error("uriSessionMapFullCount is full");
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -96,9 +100,30 @@ public class WebAppStat {
|
||||
return uriStat;
|
||||
}
|
||||
|
||||
public WebSessionStat getSessionStat(String sessionId) {
|
||||
if (sessionStatMap.size() >= this.getMaxStatSessionCount()) {
|
||||
long fullCount = uriSessionMapFullCount.getAndIncrement();
|
||||
|
||||
if (fullCount == 0) {
|
||||
LOG.error("sessionStatMap is full");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
WebSessionStat uriStat = sessionStatMap.get(sessionId);
|
||||
|
||||
if (uriStat == null) {
|
||||
sessionStatMap.putIfAbsent(sessionId, new WebSessionStat(sessionId));
|
||||
uriStat = sessionStatMap.get(sessionId);
|
||||
}
|
||||
|
||||
return uriStat;
|
||||
}
|
||||
|
||||
public void afterInvoke(long nanoSpan) {
|
||||
runningCount.decrementAndGet();
|
||||
|
||||
|
||||
WebURIStat uriStat = WebURIStat.current();
|
||||
if (uriStat != null) {
|
||||
uriStat.afterInvoke(nanoSpan);
|
||||
@@ -115,6 +140,14 @@ public class WebAppStat {
|
||||
this.maxStatUriCount = maxStatUriCount;
|
||||
}
|
||||
|
||||
public int getMaxStatSessionCount() {
|
||||
return maxStatSessionCount;
|
||||
}
|
||||
|
||||
public void setMaxStatSessionCount(int maxStatSessionCount) {
|
||||
this.maxStatSessionCount = maxStatSessionCount;
|
||||
}
|
||||
|
||||
public int getRunningCount() {
|
||||
return this.runningCount.get();
|
||||
}
|
||||
@@ -136,7 +169,7 @@ public class WebAppStat {
|
||||
data.put("RequestCount", this.getRequestCount());
|
||||
|
||||
List<Map<String, Object>> uriStatDataList = getURIStatDataList();
|
||||
|
||||
|
||||
data.put("URIList", uriStatDataList);
|
||||
|
||||
return data;
|
||||
@@ -158,5 +191,22 @@ public class WebAppStat {
|
||||
}
|
||||
return uriStatDataList;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getSessionStatDataList() {
|
||||
List<Map<String, Object>> uriStatDataList = new ArrayList<Map<String, Object>>(this.sessionStatMap.size());
|
||||
for (WebSessionStat sessionStat : this.sessionStatMap.values()) {
|
||||
Map<String, Object> sessionStatData = sessionStat.getStatData();
|
||||
|
||||
int runningCount = ((Number) sessionStatData.get("RunningCount")).intValue();
|
||||
long requestCount = (Long) sessionStatData.get("RequestCount");
|
||||
|
||||
if (runningCount == 0 && requestCount == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uriStatDataList.add(sessionStatData);
|
||||
}
|
||||
return uriStatDataList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,6 +52,19 @@ public class WebAppStatManager {
|
||||
|
||||
return allAppUriStatDataList;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getSessionStatData() {
|
||||
Set<Object> stats = getWebAppStatSet();
|
||||
|
||||
List<Map<String, Object>> allAppUriStatDataList = new ArrayList<Map<String, Object>>();
|
||||
|
||||
for (Object stat : stats) {
|
||||
List<Map<String, Object>> uriStatDataList = WebAppStatUtils.getSessionStatDataList(stat);
|
||||
allAppUriStatDataList.addAll(uriStatDataList);
|
||||
}
|
||||
|
||||
return allAppUriStatDataList;
|
||||
}
|
||||
|
||||
public void addWebAppStatSet(Object webAppStat) {
|
||||
getWebAppStatSet().add(webAppStat);
|
||||
|
||||
@@ -34,4 +34,16 @@ public class WebAppStatUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Map<String, Object>> getSessionStatDataList(Object webStat) {
|
||||
try {
|
||||
Method method = webStat.getClass().getMethod("getSessionStatDataList");
|
||||
Object obj = method.invoke(webStat);
|
||||
return (List<Map<String, Object>>) obj;
|
||||
} catch (Exception e) {
|
||||
LOG.error("getSessionStatDataList error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.alibaba.druid.support.http.stat;
|
||||
|
||||
public class WebRequestStat {
|
||||
|
||||
private long startNano;
|
||||
private long endNano;
|
||||
private long jdbcCommitCount;
|
||||
private long jdbcRollbackCount;
|
||||
private long jdbcExecuteCount;
|
||||
private long jdbcUpdateCount;
|
||||
private long jdbcFetchRowCount;
|
||||
|
||||
public WebRequestStat(){
|
||||
|
||||
}
|
||||
|
||||
public WebRequestStat(long startNano){
|
||||
this.startNano = startNano;
|
||||
}
|
||||
|
||||
private static ThreadLocal<WebRequestStat> localRequestStat = new ThreadLocal<WebRequestStat>();
|
||||
|
||||
public static WebRequestStat current() {
|
||||
return localRequestStat.get();
|
||||
}
|
||||
|
||||
public static void set(WebRequestStat requestStat) {
|
||||
localRequestStat.set(requestStat);
|
||||
}
|
||||
|
||||
public long getStartNano() {
|
||||
return startNano;
|
||||
}
|
||||
|
||||
public void setStartNano(long startNano) {
|
||||
this.startNano = startNano;
|
||||
}
|
||||
|
||||
public long getEndNano() {
|
||||
return endNano;
|
||||
}
|
||||
|
||||
public void setEndNano(long endNano) {
|
||||
this.endNano = endNano;
|
||||
}
|
||||
|
||||
public void addJdbcUpdateCount(long count) {
|
||||
this.jdbcUpdateCount += count;
|
||||
}
|
||||
|
||||
public void addJdbcFetchRowCount(long count) {
|
||||
this.jdbcFetchRowCount += count;
|
||||
}
|
||||
|
||||
public void incrementJdbcExecuteCount() {
|
||||
this.jdbcExecuteCount++;
|
||||
}
|
||||
|
||||
public long getJdbcExecuteCount() {
|
||||
return jdbcExecuteCount;
|
||||
}
|
||||
|
||||
public long getJdbcUpdateCount() {
|
||||
return jdbcUpdateCount;
|
||||
}
|
||||
|
||||
public long getJdbcFetchRowCount() {
|
||||
return jdbcFetchRowCount;
|
||||
}
|
||||
|
||||
public long getJdbcCommitCount() {
|
||||
return jdbcCommitCount;
|
||||
}
|
||||
|
||||
public void incrementJdbcCommitCount() {
|
||||
this.jdbcCommitCount++;
|
||||
}
|
||||
|
||||
public long getJdbcRollbackCount() {
|
||||
return jdbcRollbackCount;
|
||||
}
|
||||
|
||||
public void incrementJdbcRollbackCount() {
|
||||
this.jdbcRollbackCount++;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package com.alibaba.druid.support.http.stat;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
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 jdbcFetchRowCount = new AtomicLong();
|
||||
private final AtomicLong jdbcUpdateCount = new AtomicLong();
|
||||
private final AtomicLong jdbcExecuteCount = new AtomicLong();
|
||||
|
||||
private final AtomicLong jdbcCommitCount = new AtomicLong();
|
||||
private final AtomicLong jdbcRollbackCount = new AtomicLong();
|
||||
|
||||
private final AtomicLong requestTimeNano = new AtomicLong();
|
||||
|
||||
public WebSessionStat(String sessionId){
|
||||
super();
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void beforeInvoke() {
|
||||
int running = runningCount.incrementAndGet();
|
||||
|
||||
for (;;) {
|
||||
int max = concurrentMax.get();
|
||||
if (running > max) {
|
||||
if (concurrentMax.compareAndSet(max, running)) {
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
requestCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public void afterInvoke(long nanoSpan) {
|
||||
runningCount.decrementAndGet();
|
||||
|
||||
reacord(nanoSpan);
|
||||
}
|
||||
|
||||
public void reacord(long nanos) {
|
||||
requestTimeNano.addAndGet(nanos);
|
||||
|
||||
WebRequestStat requestStat = WebRequestStat.current();
|
||||
if (requestStat != null) {
|
||||
this.addJdbcExecuteCount(requestStat.getJdbcExecuteCount());
|
||||
this.addJdbcFetchRowCount(requestStat.getJdbcFetchRowCount());
|
||||
this.addJdbcUpdateCount(requestStat.getJdbcUpdateCount());
|
||||
this.addJdbcCommitCount(requestStat.getJdbcCommitCount());
|
||||
this.addJdbcRollbackCount(requestStat.getJdbcRollbackCount());
|
||||
}
|
||||
}
|
||||
|
||||
public int getRunningCount() {
|
||||
return this.runningCount.get();
|
||||
}
|
||||
|
||||
public long getConcurrentMax() {
|
||||
return concurrentMax.get();
|
||||
}
|
||||
|
||||
public long getRequestCount() {
|
||||
return requestCount.get();
|
||||
}
|
||||
|
||||
public void addJdbcFetchRowCount(long delta) {
|
||||
this.jdbcFetchRowCount.addAndGet(delta);
|
||||
}
|
||||
|
||||
public long getJdbcFetchRowCount() {
|
||||
return jdbcFetchRowCount.get();
|
||||
}
|
||||
|
||||
public void addJdbcUpdateCount(long updateCount) {
|
||||
this.jdbcUpdateCount.addAndGet(updateCount);
|
||||
}
|
||||
|
||||
public long getJdbcUpdateCount() {
|
||||
return jdbcUpdateCount.get();
|
||||
}
|
||||
|
||||
public void incrementJdbcExecuteCount() {
|
||||
jdbcExecuteCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public void addJdbcExecuteCount(long executeCount) {
|
||||
jdbcExecuteCount.addAndGet(executeCount);
|
||||
}
|
||||
|
||||
public long getJdbcExecuteCount() {
|
||||
return jdbcExecuteCount.get();
|
||||
}
|
||||
|
||||
public void incrementJdbcCommitCount() {
|
||||
jdbcCommitCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public long getJdbcCommitCount() {
|
||||
return jdbcCommitCount.get();
|
||||
}
|
||||
|
||||
public void addJdbcCommitCount(long commitCount) {
|
||||
this.jdbcCommitCount.addAndGet(commitCount);
|
||||
}
|
||||
|
||||
public void incrementJdbcRollbackCount() {
|
||||
jdbcRollbackCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public long getJdbcRollbackCount() {
|
||||
return jdbcRollbackCount.get();
|
||||
}
|
||||
|
||||
public void addJdbcRollbackCount(long rollbackCount) {
|
||||
this.jdbcRollbackCount.addAndGet(rollbackCount);
|
||||
}
|
||||
|
||||
public Map<String, Object> getStatData() {
|
||||
Map<String, Object> data = new LinkedHashMap<String, Object>();
|
||||
|
||||
data.put("SESSIONID", this.getSessionId());
|
||||
data.put("RunningCount", this.getRunningCount());
|
||||
data.put("ConcurrentMax", this.getConcurrentMax());
|
||||
data.put("RequestCount", this.getRequestCount());
|
||||
|
||||
data.put("JdbcCommitCount", this.getJdbcCommitCount());
|
||||
data.put("JdbcRollbackCount", this.getJdbcRollbackCount());
|
||||
|
||||
data.put("JdbcExecuteCount", this.getJdbcExecuteCount());
|
||||
data.put("JdbcFetchRowCount", this.getJdbcFetchRowCount());
|
||||
data.put("JdbcUpdateCount", this.getJdbcUpdateCount());
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,6 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class WebURIStat {
|
||||
|
||||
static class RequestStat {
|
||||
|
||||
long jdbcExecuteCount;
|
||||
long jdbcUpdateCount;
|
||||
long jdbcFetchRowCount;
|
||||
}
|
||||
|
||||
private final String uri;
|
||||
|
||||
private final AtomicInteger runningCount = new AtomicInteger();
|
||||
@@ -33,7 +26,7 @@ public class WebURIStat {
|
||||
private final AtomicLong jdbcRollbackCount = new AtomicLong();
|
||||
|
||||
private final static ThreadLocal<WebURIStat> currentLocal = new ThreadLocal<WebURIStat>();
|
||||
private static ThreadLocal<RequestStat> localRequestStat = new ThreadLocal<RequestStat>();
|
||||
|
||||
|
||||
public WebURIStat(String uri){
|
||||
super();
|
||||
@@ -50,7 +43,6 @@ public class WebURIStat {
|
||||
|
||||
public void beforeInvoke(String uri) {
|
||||
currentLocal.set(this);
|
||||
localRequestStat.set(new RequestStat());
|
||||
|
||||
int running = runningCount.incrementAndGet();
|
||||
|
||||
@@ -74,10 +66,10 @@ public class WebURIStat {
|
||||
runningCount.decrementAndGet();
|
||||
|
||||
{
|
||||
RequestStat localStat = localRequestStat.get();
|
||||
WebRequestStat localStat = WebRequestStat.current();
|
||||
if (localStat != null) {
|
||||
{
|
||||
long fetchRowCount = localStat.jdbcFetchRowCount;
|
||||
long fetchRowCount = localStat.getJdbcFetchRowCount();
|
||||
|
||||
for (;;) {
|
||||
long peak = jdbcFetchRowPeak.get();
|
||||
@@ -91,7 +83,7 @@ public class WebURIStat {
|
||||
}
|
||||
}
|
||||
{
|
||||
long executeCount = localStat.jdbcExecuteCount;
|
||||
long executeCount = localStat.getJdbcExecuteCount();
|
||||
|
||||
for (;;) {
|
||||
long peak = jdbcExecutePeak.get();
|
||||
@@ -105,7 +97,7 @@ public class WebURIStat {
|
||||
}
|
||||
}
|
||||
{
|
||||
long updateCount = localStat.jdbcUpdateCount;
|
||||
long updateCount = localStat.getJdbcUpdateCount();
|
||||
|
||||
for (;;) {
|
||||
long peak = jdbcUpdatePeak.get();
|
||||
@@ -122,7 +114,6 @@ public class WebURIStat {
|
||||
}
|
||||
|
||||
currentLocal.set(null);
|
||||
localRequestStat.set(null);
|
||||
}
|
||||
|
||||
public int getRunningCount() {
|
||||
@@ -139,11 +130,6 @@ public class WebURIStat {
|
||||
|
||||
public void addJdbcFetchRowCount(long delta) {
|
||||
this.jdbcFetchRowCount.addAndGet(delta);
|
||||
|
||||
RequestStat localStat = localRequestStat.get();
|
||||
if (localStat != null) {
|
||||
localStat.jdbcFetchRowCount += delta;
|
||||
}
|
||||
}
|
||||
|
||||
public long getJdbcFetchRowCount() {
|
||||
@@ -156,11 +142,6 @@ public class WebURIStat {
|
||||
|
||||
public void addJdbcUpdateCount(int updateCount) {
|
||||
this.jdbcUpdateCount.addAndGet(updateCount);
|
||||
|
||||
RequestStat localStat = localRequestStat.get();
|
||||
if (localStat != null) {
|
||||
localStat.jdbcExecuteCount += updateCount;
|
||||
}
|
||||
}
|
||||
|
||||
public long getJdbcUpdateCount() {
|
||||
@@ -173,11 +154,6 @@ public class WebURIStat {
|
||||
|
||||
public void incrementJdbcExecuteCount() {
|
||||
jdbcExecuteCount.incrementAndGet();
|
||||
|
||||
RequestStat localStat = localRequestStat.get();
|
||||
if (localStat != null) {
|
||||
localStat.jdbcExecuteCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public long getJdbcExecuteCount() {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<body onload="init()">
|
||||
<br />
|
||||
<div id="menu" >
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="websession.html">Web Session</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
</div>
|
||||
<br />
|
||||
<div id="main">
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<body>
|
||||
<br />
|
||||
<div id="menu" >
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="websession.html">Web Session</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
</div>
|
||||
<br />
|
||||
<div id="main">
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<body onload="init()">
|
||||
<br />
|
||||
<div id="menu" >
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="websession.html">Web Session</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
</div>
|
||||
<br />
|
||||
<div id="main">
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<body onload="init()">
|
||||
<br />
|
||||
<div id="menu" >
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="websession.html">Web Session</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
</div>
|
||||
<br />
|
||||
<div id="main">
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<body onload="init()">
|
||||
<br />
|
||||
<div id="menu" >
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="websession.html">Web Session</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
</div>
|
||||
<br />
|
||||
<div id="main">
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
|
||||
var xmlHttpForDataSourceSqlStatInfo;
|
||||
|
||||
var sqlViewOrderBy = '';
|
||||
var sqlViewOrderBy_old = '';
|
||||
var sqlViewOrderType = 'asc';
|
||||
|
||||
// only one page for now
|
||||
var sqlViewPage = 1;
|
||||
var sqlViewPerPageCount = 1000000;
|
||||
|
||||
function resetSortMark() {
|
||||
var divObj = document.getElementById('th-' + sqlViewOrderBy);
|
||||
var old_divObj = document.getElementById('th-' + sqlViewOrderBy_old);
|
||||
var replaceToStr = '';
|
||||
if (old_divObj) {
|
||||
var html = old_divObj.innerHTML;
|
||||
if (sqlViewOrderBy_old.indexOf('[') > 0)
|
||||
replaceToStr = '-';
|
||||
html = html.replace('↑', replaceToStr);
|
||||
html = html.replace('↓', replaceToStr);
|
||||
old_divObj.innerHTML = html
|
||||
}
|
||||
if (divObj) {
|
||||
var html = divObj.innerHTML;
|
||||
if (sqlViewOrderBy.indexOf('[') > 0)
|
||||
html = '';
|
||||
|
||||
if (sqlViewOrderType == 'asc') {
|
||||
html += '↑';
|
||||
} else if (sqlViewOrderType == 'desc') {
|
||||
html += '↓';
|
||||
}
|
||||
divObj.innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
function setOrderBy(orderBy) {
|
||||
if (sqlViewOrderBy != orderBy) {
|
||||
sqlViewOrderBy_old = sqlViewOrderBy;
|
||||
sqlViewOrderBy = orderBy;
|
||||
sqlViewOrderType = 'desc';
|
||||
resetSortMark();
|
||||
return;
|
||||
}
|
||||
|
||||
sqlViewOrderBy_old = sqlViewOrderBy;
|
||||
|
||||
if (sqlViewOrderType == 'asc')
|
||||
sqlViewOrderType = 'desc'
|
||||
else
|
||||
sqlViewOrderType = 'asc';
|
||||
|
||||
resetSortMark();
|
||||
|
||||
}
|
||||
|
||||
function getSqlViewJsonUrl() {
|
||||
var result = 'websession.json?';
|
||||
|
||||
if (sqlViewOrderBy != undefined)
|
||||
result += 'orderBy=' + sqlViewOrderBy + '&';
|
||||
|
||||
if (sqlViewOrderType != undefined)
|
||||
result += 'orderType=' + sqlViewOrderType + '&';
|
||||
|
||||
if (sqlViewPage != undefined)
|
||||
result += 'page=' + sqlViewPage + '&';
|
||||
|
||||
if (sqlViewPerPageCount != undefined)
|
||||
result += 'perPageCount=' + sqlViewPerPageCount + '&';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function ajaxRequestForDataSourceSqlStatInfo() {
|
||||
xmlHttpForDataSourceSqlStatInfo = getRequestObject();
|
||||
sendRequest(xmlHttpForDataSourceSqlStatInfo,getSqlViewJsonUrl(),ajaxResponseForDataSourceSqlStatInfo)
|
||||
}
|
||||
|
||||
function subSqlString(sql, len) {
|
||||
if (sql.length <= len)
|
||||
return sql;
|
||||
return sql.substr(0, len) + '...';
|
||||
}
|
||||
function ajaxResponseForDataSourceSqlStatInfo() {
|
||||
var sqlStatList = getJSONResponseContent(xmlHttpForDataSourceSqlStatInfo);
|
||||
if(sqlStatList==null) return;
|
||||
|
||||
var sqlStatTable = document.getElementById("WebSessionStatTable");
|
||||
while (sqlStatTable.rows.length > 1) {
|
||||
sqlStatTable.deleteRow(1);
|
||||
}
|
||||
for ( var i = 0; i < sqlStatList.length; i++) {
|
||||
var sqlStat = sqlStatList[i];
|
||||
var newRow = sqlStatTable.insertRow(-1);
|
||||
newRow.insertCell(-1).innerHTML = i+1;
|
||||
newRow.insertCell(-1).innerHTML = sqlStat.SESSIONID;
|
||||
newRow.insertCell(-1).innerHTML = sqlStat.RequestCount;
|
||||
newRow.insertCell(-1).innerHTML = sqlStat.RunningCount;
|
||||
newRow.insertCell(-1).innerHTML = sqlStat.ConcurrentMax;
|
||||
newRow.insertCell(-1).innerHTML = sqlStat.JdbcExecuteCount;
|
||||
newRow.insertCell(-1).innerHTML = sqlStat.JdbcCommitCount;
|
||||
newRow.insertCell(-1).innerHTML = sqlStat.JdbcRollbackCount;
|
||||
newRow.insertCell(-1).innerHTML = sqlStat.JdbcFetchRowCount;
|
||||
newRow.insertCell(-1).innerHTML = sqlStat.JdbcUpdateCount;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
<body onload="init()">
|
||||
<br />
|
||||
<div id="menu" >
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="websession.html">Web Session</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
</div>
|
||||
<br />
|
||||
<div id="main">
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Druid Web Session Stat</title>
|
||||
<link href="css/style.css" type="text/css" rel="stylesheet"/>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
|
||||
<script src="js/common.js" type="text/javascript" charset="utf8"></script>
|
||||
<script src="js/websession.js" type="text/javascript" charset="utf8"></script>
|
||||
<script >
|
||||
function init(){
|
||||
ajaxRequestForDataSourceSqlStatInfo();
|
||||
var time3=setInterval("ajaxRequestForDataSourceSqlStatInfo();",2000);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<br />
|
||||
<div id="menu" >
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="websession.html">Web Session</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
</div>
|
||||
<br />
|
||||
<div id="main">
|
||||
<table cellspacing="1" cellpadding="5" id="WebSessionStatTable" width="99%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="td_lable">N--</th>
|
||||
<th class="td_lable"><a id="SESSIONID" href="javascript:void(0)" onclick="setOrderBy('SESSIONID');">SESSIONID</a></th>
|
||||
<th class="td_lable" width="50"><a id="RequestCount" href="javascript:void(0)" onclick="setOrderBy('RequestCount');">Request Count</a></th>
|
||||
<th class="td_lable" width="50"><a id="th-RunningCount" href="javascript:void(0)" onclick="setOrderBy('RunningCount');">Running Count</a></th>
|
||||
<th class="td_lable" width="80"><a id="th-ConcurrentMax" href="javascript:void(0)" onclick="setOrderBy('ConcurrentMax');">Concurrent Max</a></th>
|
||||
<th class="td_lable" width="80"><a id="th-JdbcExecuteCount" href="javascript:void(0)" onclick="setOrderBy('JdbcExecuteCount');">JdbcExecuteCount</a></th>
|
||||
<th class="td_lable" width="80"><a id="th-JdbcCommitCount" href="javascript:void(0)" onclick="setOrderBy('JdbcCommitCount');">JdbcCommitCount</a></th>
|
||||
<th class="td_lable" width="80"><a id="th-JdbcRollbackCount" href="javascript:void(0)" onclick="setOrderBy('JdbcRollbackCount');">JdbcRollbackCount</a></th>
|
||||
<th class="td_lable" width="80"><a id="th-JdbcFetchRowCount" href="javascript:void(0)" onclick="setOrderBy('JdbcFetchRowCount');">JdbcFetchRowCount</a></th>
|
||||
<th class="td_lable" width="80"><a id="th-JdbcUpdateCount" href="javascript:void(0)" onclick="setOrderBy('JdbcUpdateCount');">JdbcUpdateCount</a></th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
<div id="footer">powered by <a href="mailto:sandzhangtoo@gmail.com">sandzhang</a></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>{title}</title>
|
||||
<title>Druid Web URI Stat</title>
|
||||
<link href="css/style.css" type="text/css" rel="stylesheet"/>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
|
||||
<script src="js/common.js" type="text/javascript" charset="utf8"></script>
|
||||
@@ -16,7 +16,7 @@
|
||||
<body onload="init()">
|
||||
<br />
|
||||
<div id="menu" >
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
<a href="index.html">Index</a> | <a href="datasource.html">DataSource</a> | <a href="sql.html">Sql</a> | <a href="weburi.html">WebURI</a> | <a href="websession.html">Web Session</a> | <a href="#" onclick="ajaxRequestForReset()">Reset All</a> | <a href="api.html">JSON API</a>
|
||||
</div>
|
||||
<br />
|
||||
<div id="main">
|
||||
|
||||
Reference in New Issue
Block a user