diff --git a/src/main/java/com/alibaba/druid/stat/DruidStatService.java b/src/main/java/com/alibaba/druid/stat/DruidStatService.java index 58dbd5e0cb..3e38805d60 100644 --- a/src/main/java/com/alibaba/druid/stat/DruidStatService.java +++ b/src/main/java/com/alibaba/druid/stat/DruidStatService.java @@ -135,6 +135,10 @@ public class DruidStatService implements DruidStatServiceMBean { return returnJSONResult(RESULT_CODE_SUCCESS, getWebURIStatData(uri)); } + if (url.startsWith("/webapp.json")) { + return returnJSONResult(RESULT_CODE_SUCCESS, getWebAppStatDataList(parameters)); + } + if (url.startsWith("/websession.json")) { return returnJSONResult(RESULT_CODE_SUCCESS, getWebSessionStatDataList(parameters)); } @@ -183,6 +187,11 @@ public class DruidStatService implements DruidStatServiceMBean { List> array = WebAppStatManager.getInstance().getSessionStatData(); return comparatorOrderBy(array, parameters); } + + private List> getWebAppStatDataList(Map parameters) { + List> array = WebAppStatManager.getInstance().getWebAppStatData(); + return comparatorOrderBy(array, parameters); + } private List> comparatorOrderBy(List> array, Map parameters) { // when open the stat page before executing some sql diff --git a/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java b/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java index bf63b5748f..ac829818cd 100644 --- a/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java +++ b/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java @@ -38,6 +38,8 @@ public class WebAppStat { public final static int DEFAULT_MAX_STAT_URI_COUNT = 1000; public final static int DEFAULT_MAX_STAT_SESSION_COUNT = 1000; + private final static ThreadLocal currentLocal = new ThreadLocal(); + private volatile int maxStatUriCount = DEFAULT_MAX_STAT_URI_COUNT; private volatile int maxStatSessionCount = DEFAULT_MAX_STAT_SESSION_COUNT; @@ -45,7 +47,13 @@ public class WebAppStat { private final AtomicInteger concurrentMax = new AtomicInteger(); private final AtomicLong requestCount = new AtomicLong(0); - private final static ThreadLocal currentLocal = new ThreadLocal(); + 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 ConcurrentMap uriStatMap = new ConcurrentHashMap(); private final LRUCache sessionStatMap; @@ -63,11 +71,11 @@ public class WebAppStat { private final AtomicLong osOpenBSDCount = new AtomicLong(0); private final AtomicLong osAndroidCount = new AtomicLong(0); - private final AtomicLong osWindows98Count = new AtomicLong(); - private final AtomicLong osWindowsXPCount = new AtomicLong(); - private final AtomicLong osWindows2000Count = new AtomicLong(); - private final AtomicLong osWindowsVistaCount = new AtomicLong(); - private final AtomicLong osWindows7Count = new AtomicLong(); + private final AtomicLong osWindows98Count = new AtomicLong(); + private final AtomicLong osWindowsXPCount = new AtomicLong(); + private final AtomicLong osWindows2000Count = new AtomicLong(); + private final AtomicLong osWindowsVistaCount = new AtomicLong(); + private final AtomicLong osWindows7Count = new AtomicLong(); private final AtomicLong osAndroid15Count = new AtomicLong(0); private final AtomicLong osAndroid16Count = new AtomicLong(0); @@ -122,6 +130,13 @@ public class WebAppStat { concurrentMax.set(0); requestCount.set(0); requestCount.set(0); + + jdbcFetchRowCount.set(0); + jdbcUpdateCount.set(0); + jdbcExecuteCount.set(0); + jdbcExecuteTimeNano.set(0); + jdbcCommitCount.set(0); + jdbcRollbackCount.set(0); sessionStatLock.readLock().lock(); try { @@ -329,6 +344,80 @@ public class WebAppStat { public void afterInvoke(Throwable error, long nanoSpan) { runningCount.decrementAndGet(); currentLocal.set(null); + + 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()); + this.addJdbcExecuteTimeNano(requestStat.getJdbcExecuteTimeNano()); + } + } + + 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 long getJdbcExecuteTimeMillis() { + return getJdbcExecuteTimeNano() / (1000 * 1000); + } + + public long getJdbcExecuteTimeNano() { + return jdbcExecuteTimeNano.get(); + } + + public void addJdbcExecuteTimeNano(long nano) { + jdbcExecuteTimeNano.addAndGet(nano); + } + + 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 int getMaxStatUriCount() { @@ -366,10 +455,68 @@ public class WebAppStat { 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()); - List> uriStatDataList = getURIStatDataList(); + data.put("JdbcExecuteCount", this.getJdbcExecuteCount()); + data.put("JdbcExecuteTimeMillis", this.getJdbcExecuteTimeMillis()); + data.put("JdbcFetchRowCount", this.getJdbcFetchRowCount()); + data.put("JdbcUpdateCount", this.getJdbcUpdateCount()); - data.put("URIList", uriStatDataList); + data.put("OSMacOSXCount", this.getOSMacOSXCount()); + data.put("OSWindowsCount", this.getOSWindowsCount()); + data.put("OSLinuxCount", this.getOSLinuxCount()); + data.put("OSSymbianCount", this.getOSSymbianCount()); + data.put("OSFreeBSDCount", this.getOSFreeBSDCount()); + data.put("OSOpenBSDCount", this.getOSOpenBSDCount()); + data.put("OSAndroidCount", this.getOSAndroidCount()); + data.put("OSWindows98Count", this.getOSWindows98Count()); + data.put("OSWindowsXPCount", this.getOSWindowsXPCount()); + data.put("OSWindows2000Count", this.getOSWindows2000Count()); + data.put("OSWindowsVistaCount", this.getOSWindowsVistaCount()); + data.put("OSWindows7Count", this.getOSWindows7Count()); + + data.put("OSAndroid15Count", this.getOSAndroid15Count()); + data.put("OSAndroid16Count", this.getOSAndroid16Count()); + data.put("OSAndroid20Count", this.getOSAndroid20Count()); + data.put("OSAndroid21Count", this.getOSAndroid21Count()); + data.put("OSAndroid22Count", this.getOSAndroid22Count()); + data.put("OSAndroid23Count", this.getOSAndroid23Count()); + data.put("OSAndroid30Count", this.getOSAndroid30Count()); + data.put("OSAndroid31Count", this.getOSAndroid31Count()); + data.put("OSAndroid32Count", this.getOSAndroid32Count()); + data.put("OSAndroid40Count", this.getOSAndroid40Count()); + data.put("OSLinuxUbuntuCount", this.getOSLinuxUbuntuCount()); + + data.put("BrowserIECount", this.getBrowserIECount()); + data.put("BrowserFirefoxCount", this.getBrowserFirefoxCount()); + data.put("BrowserChromeCount", this.getBrowserChromeCount()); + data.put("BrowserSafariCount", this.getBrowserSafariCount()); + data.put("BrowserOperaCount", this.getBrowserOperaCount()); + + data.put("BrowserIE5Count", this.getBrowserIE5Count()); + data.put("BrowserIE6Count", this.getBrowserIE6Count()); + data.put("BrowserIE7Count", this.getBrowserIE7Count()); + data.put("BrowserIE8Count", this.getBrowserIE8Count()); + data.put("BrowserIE9Count", this.getBrowserIE9Count()); + data.put("BrowserIE10Count", this.getBrowserIE10Count()); + + data.put("Browser360SECount", this.getBrowser360SECount()); + data.put("DeviceAndroidCount", this.getDeviceAndroidCount()); + data.put("DeviceIpadCount", this.getDeviceIpadCount()); + data.put("DeviceIphoneCount", this.getDeviceIphoneCount()); + data.put("DeviceWindowsPhoneCount", this.getDeviceWindowsPhoneCount()); + + data.put("BotCount", this.getBotCount()); + data.put("BotBaiduCount", this.getBotBaiduCount()); + data.put("BotYoudaoCount", this.getBotYoudaoCount()); + data.put("BotGoogleCount", this.getBotGoogleCount()); + data.put("BotMsnCount", this.getBotMsnCount()); + data.put("BotBingCount", this.getBotBingCount()); + data.put("BotSosoCount", this.getBotSosoCount()); + data.put("BotSogouCount", this.getBotSogouCount()); + data.put("BotYahooCount", this.getBotYahooCount()); return data; } diff --git a/src/main/resources/support/http/resources/activeConnectionStackTrace.html b/src/main/resources/support/http/resources/activeConnectionStackTrace.html index 93d1bfe814..92f0e5e7e8 100644 --- a/src/main/resources/support/http/resources/activeConnectionStackTrace.html +++ b/src/main/resources/support/http/resources/activeConnectionStackTrace.html @@ -14,7 +14,7 @@ [View JSON API]
- +
diff --git a/src/main/resources/support/http/resources/api.html b/src/main/resources/support/http/resources/api.html index 8034cf6208..bd3c8b524d 100644 --- a/src/main/resources/support/http/resources/api.html +++ b/src/main/resources/support/http/resources/api.html @@ -9,7 +9,7 @@ diff --git a/src/main/resources/support/http/resources/js/common.js b/src/main/resources/support/http/resources/js/common.js index 67141d45a7..87ebb99882 100644 --- a/src/main/resources/support/http/resources/js/common.js +++ b/src/main/resources/support/http/resources/js/common.js @@ -23,6 +23,7 @@ druid.common = function () { '
  • Index
  • '+ '
  • DataSource
  • '+ '
  • SQL
  • '+ + '
  • WebApp
  • '+ '
  • WebURI
  • '+ '
  • Web Session
  • '+ '
  • Spring
  • '+ @@ -40,7 +41,7 @@ druid.common = function () { buildFooter : function() { var html = ''; $(document.body).append(html); diff --git a/src/main/resources/support/http/resources/spring.html b/src/main/resources/support/http/resources/spring.html index e3c3207df2..00b6250563 100644 --- a/src/main/resources/support/http/resources/spring.html +++ b/src/main/resources/support/http/resources/spring.html @@ -47,7 +47,7 @@ $("#dataTable th a").click(function(obj) { druid.common.setOrderBy(obj.target.id.substring(3)) }) - druid.common.buildHead(5); + druid.common.buildHead(6); druid.common.ajaxuri = 'spring.json?'; druid.common.handleAjaxResult = druid.spring.handleAjaxResult; druid.common.ajaxRequestForBasicInfo(); diff --git a/src/main/resources/support/http/resources/webapp.html b/src/main/resources/support/http/resources/webapp.html new file mode 100644 index 0000000000..b395a63988 --- /dev/null +++ b/src/main/resources/support/http/resources/webapp.html @@ -0,0 +1,156 @@ + + + + Druid WebApp Stat + + + + + + + + +
    +
    +
    +

    + WebAppStat List + View JSON API +

    +
    +
    +
    + + + diff --git a/src/main/resources/support/http/resources/websession.html b/src/main/resources/support/http/resources/websession.html index ab7f3909dc..6e1845a049 100644 --- a/src/main/resources/support/http/resources/websession.html +++ b/src/main/resources/support/http/resources/websession.html @@ -50,7 +50,7 @@ $("#dataTable th a").click(function(obj) { druid.common.setOrderBy(obj.target.id.substring(3)) }) - druid.common.buildHead(4); + druid.common.buildHead(5); druid.common.ajaxuri = 'websession.json?'; druid.common.handleAjaxResult = druid.websession.handleAjaxResult; druid.common.ajaxRequestForBasicInfo(); diff --git a/src/main/resources/support/http/resources/weburi.html b/src/main/resources/support/http/resources/weburi.html index 965488d6c6..6b445e01a2 100644 --- a/src/main/resources/support/http/resources/weburi.html +++ b/src/main/resources/support/http/resources/weburi.html @@ -46,7 +46,7 @@ $("#dataTable th a").click(function(obj) { druid.common.setOrderBy(obj.target.id.substring(3)) }) - druid.common.buildHead(3); + druid.common.buildHead(4); druid.common.ajaxuri = 'weburi.json?'; druid.common.handleAjaxResult = druid.weburi.handleAjaxResult; druid.common.setOrderBy("URI");