From 811fd56f9793b8f0046d311ed3c17e73a1d74853 Mon Sep 17 00:00:00 2001 From: sand Date: Tue, 31 Jul 2012 23:40:00 +0800 Subject: [PATCH] StatViewServlet:add PollingConnectionInfo,mv .js and .css into js and css folder --- .../druid/support/http/StatViewServlet.java | 26 ++++ .../resources/activeConnectionStackTrace.html | 8 +- .../resources/support/http/resources/api.html | 4 +- .../http/resources/connectionInfo.html | 52 +++++++ .../http/resources/{ => css}/style.css | 0 .../support/http/resources/datasource.html | 6 +- .../support/http/resources/index.html | 6 +- .../{ => js}/activeConnectionStackTrace.js | 0 .../http/resources/{ => js}/basicStat.js | 0 .../support/http/resources/{ => js}/common.js | 0 .../http/resources/js/connectionInfo.js | 127 ++++++++++++++++++ .../http/resources/{ => js}/datasource.js | 14 +- .../support/http/resources/{ => js}/sql.js | 0 .../resources/support/http/resources/sql.html | 69 +++++----- .../support/http/resources/template.html | 4 +- 15 files changed, 264 insertions(+), 52 deletions(-) create mode 100644 src/main/resources/support/http/resources/connectionInfo.html rename src/main/resources/support/http/resources/{ => css}/style.css (100%) rename src/main/resources/support/http/resources/{ => js}/activeConnectionStackTrace.js (100%) rename src/main/resources/support/http/resources/{ => js}/basicStat.js (100%) rename src/main/resources/support/http/resources/{ => js}/common.js (100%) create mode 100644 src/main/resources/support/http/resources/js/connectionInfo.js rename src/main/resources/support/http/resources/{ => js}/datasource.js (95%) rename src/main/resources/support/http/resources/{ => js}/sql.js (100%) diff --git a/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java b/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java index 8111617fa3..0ff53d061c 100644 --- a/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java +++ b/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java @@ -102,6 +102,22 @@ public class StatViewServlet extends HttpServlet { return; } + if (path.startsWith("/connectionInfo-")) { + Integer id = StringUtils.subStringToInteger(path, "connectionInfo-", "."); + DruidDataSource datasource = getDruidDataSourceById(id); + + if (path.endsWith(".json")) { + if (datasource == null) returnJSONResult(request, response, RESULT_CODE_ERROR, null); + else returnJSONResult(request, response, RESULT_CODE_SUCCESS, datasource.getPoolingConnectionInfo()); + return; + } + + if (path.endsWith(".html")) { + returnViewConnectionInfo(datasource, request, response); + return; + } + } + if (path.startsWith("/activeConnectionStackTrace-")) { Integer id = StringUtils.subStringToInteger(path, "activeConnectionStackTrace-", "."); DruidDataSource datasource = getDruidDataSourceById(id); @@ -119,6 +135,7 @@ public class StatViewServlet extends HttpServlet { if (path.startsWith("/sql-")) { Integer id = StringUtils.subStringToInteger(path, "sql-", "."); + if (path.endsWith(".json")) { Object result = getSqlStatData(id); returnJSONResult(request, response, result == null ? RESULT_CODE_ERROR : RESULT_CODE_SUCCESS, result); @@ -161,6 +178,15 @@ public class StatViewServlet extends HttpServlet { response.getWriter().print(text); } + private void returnViewConnectionInfo(DruidDataSource datasource, HttpServletRequest request, + HttpServletResponse response) throws IOException { + if (datasource == null) return; + + String text = IOUtils.readFromResource(RESOURCE_PATH + "/connectionInfo.html"); + text = text.replaceAll("\\{datasourceId\\}", String.valueOf(System.identityHashCode(datasource))); + response.getWriter().print(text); + } + private void returnViewSqlStat(JdbcSqlStat sqlStat, HttpServletResponse response) throws IOException { if (sqlStat == null) return; diff --git a/src/main/resources/support/http/resources/activeConnectionStackTrace.html b/src/main/resources/support/http/resources/activeConnectionStackTrace.html index 3c73713d64..24081be637 100644 --- a/src/main/resources/support/http/resources/activeConnectionStackTrace.html +++ b/src/main/resources/support/http/resources/activeConnectionStackTrace.html @@ -3,9 +3,9 @@ Druid ActiveConnection StackTrace - - - + + + + +
diff --git a/src/main/resources/support/http/resources/connectionInfo.html b/src/main/resources/support/http/resources/connectionInfo.html new file mode 100644 index 0000000000..52e55b681d --- /dev/null +++ b/src/main/resources/support/http/resources/connectionInfo.html @@ -0,0 +1,52 @@ + + + + Druid SqlStat + + + + + + + +
+ +
+
+

Pooling Connection Info List for Datasource {datasourceId}[View JSON API]

+ + + + + + + + + + + + + + +
IDUse CountLast ActiveTimeConnectTimeHoldabilityTransaction IsolationAutoCommitReadoOnly + Pscache
+ + + + + + + +
sqldefault Row Pretchrow Prefetchhit Count
+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/support/http/resources/style.css b/src/main/resources/support/http/resources/css/style.css similarity index 100% rename from src/main/resources/support/http/resources/style.css rename to src/main/resources/support/http/resources/css/style.css diff --git a/src/main/resources/support/http/resources/datasource.html b/src/main/resources/support/http/resources/datasource.html index 6e5b47f54c..059833a02b 100644 --- a/src/main/resources/support/http/resources/datasource.html +++ b/src/main/resources/support/http/resources/datasource.html @@ -3,9 +3,9 @@ Druid DataSourceStat - - - + + + - + + + - + + + +