refactor StatServlet

This commit is contained in:
sand
2012-07-19 15:09:20 +08:00
parent 92b106565b
commit a01ded5627
6 changed files with 406 additions and 305 deletions
@@ -22,6 +22,7 @@ import com.alibaba.druid.stat.DruidDataSourceStatManager;
import com.alibaba.druid.stat.JdbcSqlStat;
import com.alibaba.druid.util.IOUtils;
import com.alibaba.druid.util.JdbcUtils;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
/**
@@ -37,47 +38,55 @@ public class StatServlet extends HttpServlet {
private final static int RESULT_CODE_SUCCESS = 1;
private final static int RESULT_CODE_ERROR = -1;
public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String contextPath = req.getContextPath();
String servletPath = req.getServletPath();
String requestURI = req.getRequestURI();
if (contextPath == null) { // root context
contextPath = "";
}
String path = requestURI.substring(contextPath.length() + servletPath.length());
if (path.length() == 0 || path.equals("index.html")) {
// TODO home page
} else if (path.equals("datasource")) {
// TODO datasource list page
} else if (path.equals("datasource.json")) {
// TODO datasource list json
} else if (path.startsWith("datasource-")) {
// TODO datasource single
} else if (path.equals("sql")) {
// TODO sql page
} else if (path.equals("sql.json")) {
// TODO sql json
} else if (path.startsWith("sql-")) {
}
if (path.startsWith("/json/basic")) {
returnJSON_BasicStat(req, resp);
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String contextPath = request.getContextPath();
String servletPath = request.getServletPath();
String requestURI = request.getRequestURI();
if (contextPath == null) { // root context
contextPath = "";
}
String path = requestURI.substring(contextPath.length() + servletPath.length());
if (path.length() == 0) {
returnResourceFile("/index.html", response);
return;
}
if (path.startsWith("/json/datasource")) {
returnJSON_DataSourceStat(req, resp);
if (path.equals("/basic.json")) {
returnJSONBasicStat(request, response);
return;
}
if (path.startsWith("/json/sql")) {
returnJSON_DataSourceSqlStat(req, resp);
if (path.equals("/datasource.html")) {
returnResourceFile(path, response);
return;
}
// find file in jar resources path
returnResourceFile(path, resp);
if (path.equals("/datasource.json")) {
returnJSONResult(request, response, RESULT_CODE_SUCCESS, getJSONDataSourceStatList());
return;
}
if (path.startsWith("/datasource-")) {
Integer id = StringUtils.subStringToInteger(path, "datasource-", ".");
Object result = getJSONDataSourceStat(id);
returnJSONResult(request, response, result == null ? RESULT_CODE_ERROR : RESULT_CODE_SUCCESS, result);
return;
}
if (path.equals("/sql.json")) {
returnJSONResult(request, response, RESULT_CODE_SUCCESS, getJSONSqlStat());
return;
}
if (path.startsWith("/sql-")) {
Integer id = StringUtils.subStringToInteger(path, "sql-", ".");
Object result = getJSONSqlStat(id);
returnJSONResult(request, response, result == null ? RESULT_CODE_ERROR : RESULT_CODE_SUCCESS, result);
return;
}
// find file in resources path
returnResourceFile(path, response);
}
private List<String> getJSONDrivers() {
@@ -89,64 +98,45 @@ public class StatServlet extends HttpServlet {
return drivers;
}
private void returnJSON_BasicStat(HttpServletRequest req, HttpServletResponse resp) throws IOException {
private void returnJSONBasicStat(HttpServletRequest request, HttpServletResponse response) throws IOException {
Map<String, Object> json = new HashMap<String, Object>();
json.put("Version", VERSION.getVersionNumber());
json.put("Drivers", getJSONDrivers());
json.put("DataSources", getJSONDataSources());
returnJSONResult(req, resp, RESULT_CODE_SUCCESS, json);
returnJSONResult(request, response, RESULT_CODE_SUCCESS, json);
}
private void returnJSON_DataSourceStat(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Integer identity = null;
try {
identity = Integer.parseInt(req.getParameter("identity"));
} catch (Exception e) {
}
Map<String, Object> json = getJSONDataSourceStat(identity);
if (identity == null) {
returnJSONResult(req, resp, RESULT_CODE_ERROR, null);
} else {
returnJSONResult(req, resp, RESULT_CODE_SUCCESS, json);
}
}
private void returnJSON_DataSourceSqlStat(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Integer identity = null;
try {
identity = Integer.parseInt(req.getParameter("identity"));
} catch (Exception e) {
}
List<Object> sqlStatList = getJSONDataSourceSqlStat(identity);
if (identity == null || sqlStatList == null) {
returnJSONResult(req, resp, RESULT_CODE_ERROR, null);
} else {
returnJSONResult(req, resp, RESULT_CODE_SUCCESS, sqlStatList);
}
}
private List<Object> getJSONDataSources() {
List<Object> drivers = new ArrayList<Object>();
private List<Object> getJSONDataSourceStatList() {
List<Object> datasourceList = new ArrayList<Object>();
for (DruidDataSource dataSource : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
drivers.add(getJSONDataSource(dataSource));
datasourceList.add(toJSONDataSource(dataSource));
}
return drivers;
return datasourceList;
}
private Map<String, Object> getJSONDataSourceStat(Integer id) {
if (id == null) {
return null;
}
DruidDataSource ds = getDruidDataSourceById(id);
if (ds == null) {
DruidDataSource datasource = getDruidDataSourceById(id);
return datasource == null ? null : toJSONDataSource(datasource);
}
private Map<String, Object> getJSONSqlStat(Integer id) {
if (id == null) {
return null;
}
JdbcSqlStat sqlStat = getSqlStatById(id);
return sqlStat == null ? null : toJSONSqlStat(sqlStat);
}
return getJSONDataSource(ds);
private JdbcSqlStat getSqlStatById(Integer id) {
for (DruidDataSource ds : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
JdbcSqlStat sqlStat = ds.getDataSourceStat().getSqlStat(id);
if (sqlStat != null) return sqlStat;
}
return null;
}
private DruidDataSource getDruidDataSourceById(Integer identity) {
@@ -161,40 +151,39 @@ public class StatServlet extends HttpServlet {
return null;
}
private List<Object> getJSONDataSourceSqlStat(Integer id) {
if (id == null) {
return null;
}
DruidDataSource ds = getDruidDataSourceById(id);
if (ds == null) {
return null;
}
private List<Object> getJSONSqlStat() {
List<Object> array = new ArrayList<Object>();
for (JdbcSqlStat sqlStat : ds.getDataSourceStat().getSqlStatMap().values()) {
Map<String, Object> json = new HashMap<String, Object>();
json.put("SQL", sqlStat.getSql());
json.put("File", sqlStat.getFile());
json.put("Name", sqlStat.getName());
json.put("ExecuteCount", sqlStat.getExecuteCount());
json.put("ExecuteMillisTotal", sqlStat.getExecuteMillisTotal());
json.put("ExecuteMillisMax", sqlStat.getExecuteMillisMax());
json.put("InTxnCount", sqlStat.getInTransactionCount());
json.put("ErrorCount", sqlStat.getErrorCount());
json.put("UpdateCount", sqlStat.getUpdateCount());
json.put("FetchRowCount", sqlStat.getFetchRowCount());
json.put("RunningCount", sqlStat.getRunningCount());
json.put("ConcurrentMax", sqlStat.getConcurrentMax());
json.put("ExecHistogram", sqlStat.getHistogram().toArray());
json.put("FetchRowHistogram", sqlStat.getFetchRowCountHistogram().toArray());
json.put("UpdateCountHistogram", sqlStat.getUpdateCountHistogram().toArray());
json.put("ExecAndRsHoldHistogram", sqlStat.getExecuteAndResultHoldTimeHistogram().toArray());
array.add(json);
for (DruidDataSource datasource : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
for (JdbcSqlStat sqlStat : datasource.getDataSourceStat().getSqlStatMap().values()) {
array.add(toJSONSqlStat(sqlStat));
}
}
return array;
}
private Map<String, Object> getJSONDataSource(DruidDataSource dataSource) {
private Map<String, Object> toJSONSqlStat(JdbcSqlStat sqlStat) {
Map<String, Object> json = new HashMap<String, Object>();
json.put("SQL", sqlStat.getSql());
json.put("File", sqlStat.getFile());
json.put("Name", sqlStat.getName());
json.put("ExecuteCount", sqlStat.getExecuteCount());
json.put("ExecuteMillisTotal", sqlStat.getExecuteMillisTotal());
json.put("ExecuteMillisMax", sqlStat.getExecuteMillisMax());
json.put("InTxnCount", sqlStat.getInTransactionCount());
json.put("ErrorCount", sqlStat.getErrorCount());
json.put("UpdateCount", sqlStat.getUpdateCount());
json.put("FetchRowCount", sqlStat.getFetchRowCount());
json.put("RunningCount", sqlStat.getRunningCount());
json.put("ConcurrentMax", sqlStat.getConcurrentMax());
json.put("ExecHistogram", sqlStat.getHistogram().toArray());
json.put("FetchRowHistogram", sqlStat.getFetchRowCountHistogram().toArray());
json.put("UpdateCountHistogram", sqlStat.getUpdateCountHistogram().toArray());
json.put("ExecAndRsHoldHistogram", sqlStat.getExecuteAndResultHoldTimeHistogram().toArray());
return json;
}
private Map<String, Object> toJSONDataSource(DruidDataSource dataSource) {
Map<String, Object> json = new HashMap<String, Object>();
json.put("Identity", System.identityHashCode(dataSource));
@@ -220,9 +209,9 @@ public class StatServlet extends HttpServlet {
return json;
}
private void returnJSONResult(HttpServletRequest req, HttpServletResponse resp, int resultCode, Object content)
throws IOException {
PrintWriter out = resp.getWriter();
private void returnJSONResult(HttpServletRequest request, HttpServletResponse response, int resultCode,
Object content) throws IOException {
PrintWriter out = response.getWriter();
Map<String, Object> json = new HashMap<String, Object>();
json.put("ResultCode", resultCode);
@@ -0,0 +1,70 @@
package com.alibaba.druid.util;
/**
* @author sandzhang<sandzhangtoo@gmail.com>
*/
public class StringUtils {
/**
* Example: subString("12345","1","4")=23
*
* @param src
* @param start
* @param to
* @return
*/
public static Integer subStringToInteger(String src, String start, String to) {
return stringToInteger(subString(src, start, to));
}
/**
* Example: subString("abcd","a","c")="b"
*
* @param src
* @param start
* @param to
* @return
*/
public static String subString(String src, String start, String to) {
int indexFrom = src.indexOf(start);
int indexTo = src.indexOf(to);
if (indexFrom < 0 || indexTo < 0 || indexFrom < indexTo) {
return null;
}
indexFrom += start.length();
indexTo += to.length();
return src.substring(indexFrom, indexTo);
}
/**
* @param in
* @return
*/
public static Integer stringToInteger(String in) {
if (in == null) return null;
in = in.trim();
if (in.length() == 0) return null;
try {
return Integer.parseInt(in);
} catch (NumberFormatException e) {
return null;
}
}
/**
* @param in
* @return
*/
public static Long stringToLong(String in) {
if (in == null) return null;
in = in.trim();
if (in.length() == 0) return null;
try {
return Long.parseLong(in);
} catch (NumberFormatException e) {
return null;
}
}
}
@@ -0,0 +1,25 @@
<!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 DataSource Stat List</title>
<link href="style.css" type="text/css" rel="stylesheet"/>
<script src="js.js" type="text/javascript"></script>
<script >
function init(){
ajaxRequestForDataSourceInfo();
var time2=setInterval("ajaxRequestForDataSourceInfo();",2000);
}
</script>
</head>
<body onload="init()">
</br>
<div id="menu" >
<a href="index.html">Index</a> | <a href="datasource.html">DataSourceStatList</a> | <a href="sql.html">SqlStatList</a>
</div>
</br>
<div id="main">
<div id="dataSourceStatList">
</div>
</div>
</body>
</html>
@@ -1,13 +1,23 @@
<!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 Stat</title>
<title>Druid Stat Index</title>
<link href="style.css" type="text/css" rel="stylesheet"/>
<script src="js.js" type="text/javascript"></script>
<script >
function init(){
ajaxRequestForBasicInfo();
}
</script>
</head>
<body onload="init()">
</br>
<div id="menu" >
<a href="index.html">Index</a> | <a href="datasource.html">DataSourceStatList</a> | <a href="sql.html">SqlStatList</a>
</div>
</br>
<div id="main">
<h2>Stat Index</h2>
<table cellspacing="1" cellpadding="5">
<tr >
<td valign="top" width="100" class="td_lable">
@@ -26,67 +36,6 @@
</td>
</tr>
</table>
</br>
</br>
<div id="menu" >
&nbsp;
</div>
<div id="dataSourceInfo">
<h2>Basic Info : <span id="DS-Info-Title"></span></h2>
<table cellpadding="5" cellspacing="1" width="960">
<tr >
<td class="td_lable" width="150">UserName</td><td width="150" id="DS-Info-UserName">&nbsp;</td>
<td class="td_lable" width="140">URL</td><td id="DS-Info-URL" colspan="3">&nbsp;</td>
</tr>
<tr >
<td class="td_lable">DbType</td><td id="DS-Info-DbType">&nbsp;</td>
<td class="td_lable">DriverClassName</td><td id="DS-Info-DriverClassName" colspan="3">&nbsp;</td>
</tr>
<tr>
<td class="td_lable">TestOnBorrow</td><td id="DS-Info-TestOnBorrow">&nbsp;</td>
<td class="td_lable">TestWhileIdle</td><td id="DS-Info-TestWhileIdle" colspan="3">&nbsp;</td>
</tr>
<tr>
<td class="td_lable">InitialSize</td><td id="DS-Info-InitialSize">&nbsp;</td>
<td class="td_lable">MinIdle</td><td id="DS-Info-MinIdle" width="150">&nbsp;</td>
<td class="td_lable" width="190">MaxActive</td><td id="DS-Info-MaxActive">&nbsp;</td>
</tr>
<tr>
<td class="td_lable">LogicConnectCount</td><td id="DS-Info-LogicConnectCount">&nbsp;</td>
<td class="td_lable">LogicCloseCount</td><td id="DS-Info-LogicCloseCount">&nbsp;</td>
<td class="td_lable">LogicConnectErrorCount</td><td id="DS-Info-LogicConnectErrorCount">&nbsp;</td>
</tr>
<tr>
<td class="td_lable">PhysicalConnectCount</td><td id="DS-Info-PhysicalConnectCount">&nbsp;</td>
<td class="td_lable">PhysicalCloseCount</td><td id="DS-Info-PhysicalCloseCount">&nbsp;</td>
<td class="td_lable">PhysicalConnectErrorCount</td><td id="DS-Info-PhysicalConnectErrorCount">&nbsp;</td>
</tr>
<tr>
<td class="td_lable">PSCacheAccessCount</td><td id="DS-Info-PSCacheAccessCount">&nbsp;</td>
<td class="td_lable">PSCacheHitCount</td><td id="DS-Info-PSCacheHitCount">&nbsp;</td>
<td class="td_lable">PSCacheMissCount</td><td id="DS-Info-PSCacheMissCount">&nbsp;</td>
</tr>
</table>
</br>
<h2>SqlStat Info</h2>
<table cellspacing="1" cellpadding="5" id="SqlStatTable" width="99%">
<thead>
<th class="td_lable">SQL</th>
<th class="td_lable">File</th>
<th class="td_lable">Name</th>
<th class="td_lable" width="50">Execute Count</th>
<th class="td_lable" width="50">Execute Millis Total</th>
<th class="td_lable" width="50">Execute Millis Max</th>
<th class="td_lable" width="50">InTxn Count</th>
<th class="td_lable" width="50">Error Count</th>
<th class="td_lable" width="50">Effected Row Count</th>
<th class="td_lable" width="50">Fetch Row Count</th>
<th class="td_lable" width="50">Running Count</th>
<th class="td_lable" width="80">Concurrent Max</th>
<th class="td_lable" width="370">Histogram</th>
</thead>
</table>
</div>
</div>
</body>
</html>
+163 -136
View File
@@ -1,152 +1,179 @@
var datasourceId;
var xmlHttpForBasicInfo;
var xmlHttpForDataSourceInfo;
var xmlHttpForDataSourceSqlStatInfo;
function ajaxRequestForBasicInfo(){
if(window.XMLHttpRequest) xmlHttpForBasicInfo=new XMLHttpRequest();
else if(window.ActiveXObject) xmlHttpForBasicInfo=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttpForBasicInfo.onreadystatechange=ajaxResponseForBasicInfo;
xmlHttpForBasicInfo.open("GET",'json/basic',true);
xmlHttpForBasicInfo.send(null);
function ajaxRequestForBasicInfo() {
if (window.XMLHttpRequest)
xmlHttpForBasicInfo = new XMLHttpRequest();
else if (window.ActiveXObject)
xmlHttpForBasicInfo = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttpForBasicInfo.onreadystatechange = ajaxResponseForBasicInfo;
xmlHttpForBasicInfo.open("GET", 'basic.json', true);
xmlHttpForBasicInfo.send(null);
}
function ajaxRequestForDataSourceSqlStatInfo(){
if(!datasourceId){
return;
}
if(window.XMLHttpRequest) xmlHttpForDataSourceSqlStatInfo=new XMLHttpRequest();
else if(window.ActiveXObject) xmlHttpForDataSourceSqlStatInfo=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttpForDataSourceSqlStatInfo.onreadystatechange=ajaxResponseForDataSourceSqlStatInfo;
xmlHttpForDataSourceSqlStatInfo.open("GET",'json/sql?identity='+datasourceId,true);
xmlHttpForDataSourceSqlStatInfo.send(null);
function ajaxRequestForDataSourceSqlStatInfo() {
if (window.XMLHttpRequest)
xmlHttpForDataSourceSqlStatInfo = new XMLHttpRequest();
else if (window.ActiveXObject)
xmlHttpForDataSourceSqlStatInfo = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttpForDataSourceSqlStatInfo.onreadystatechange = ajaxResponseForDataSourceSqlStatInfo;
xmlHttpForDataSourceSqlStatInfo.open("GET", 'sql.json', true);
xmlHttpForDataSourceSqlStatInfo.send(null);
}
function ajaxRequestForDataSourceInfo(){
if(!datasourceId){
return;
}
if(window.XMLHttpRequest) xmlHttpForDataSourceInfo=new XMLHttpRequest();
else if(window.ActiveXObject) xmlHttpForDataSourceInfo=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttpForDataSourceInfo.onreadystatechange=ajaxResponseForDataSourceInfo;
xmlHttpForDataSourceInfo.open("GET",'json/datasource?identity='+datasourceId,true);
xmlHttpForDataSourceInfo.send(null);
function ajaxRequestForDataSourceInfo() {
if (window.XMLHttpRequest)
xmlHttpForDataSourceInfo = new XMLHttpRequest();
else if (window.ActiveXObject)
xmlHttpForDataSourceInfo = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttpForDataSourceInfo.onreadystatechange = ajaxResponseForDataSourceInfo;
xmlHttpForDataSourceInfo.open("GET", 'datasource.json', true);
xmlHttpForDataSourceInfo.send(null);
}
function ajaxResponseForBasicInfo(){
var html='';
var tabHtml='';
if(xmlHttpForBasicInfo.readyState==4){
if(xmlHttpForBasicInfo.status==200){
var jsonResp=eval("("+xmlHttpForBasicInfo.responseText+")");
if(jsonResp.ResultCode==1){
document.getElementById("DruidVersion").innerHTML=jsonResp.Content.Version;
var driversList=jsonResp.Content.Drivers;
if(driversList){
var driverHtml='';
for(var i=0;i<driversList.length;i++){
var driver=driversList[i];
driverHtml+=driver +' , ';
function ajaxResponseForBasicInfo() {
var html = '';
if (xmlHttpForBasicInfo.readyState == 4) {
if (xmlHttpForBasicInfo.status == 200) {
var jsonResp = eval("(" + xmlHttpForBasicInfo.responseText + ")");
if (jsonResp.ResultCode == 1) {
document.getElementById("DruidVersion").innerHTML = jsonResp.Content.Version;
var driversList = jsonResp.Content.Drivers;
if (driversList) {
var driverHtml = '';
for ( var i = 0; i < driversList.length; i++) {
var driver = driversList[i];
driverHtml += driver + ' , ';
}
document.getElementById("DruidDrivers").innerHTML=driverHtml;
document.getElementById("DruidDrivers").innerHTML = driverHtml;
}
var dsList=jsonResp.Content.DataSources;
if(dsList){
//start get default info
if(!datasourceId){
datasourceId=dsList[0].Identity;
ajaxRequestForDataSourceSqlStatInfo();
ajaxRequestForDataSourceInfo();
}
}
}
}
function changeInnerHtml(id, divHtml) {
var divObj = document.getElementById(id);
if (divObj) {
divObj.innerHTML = divHtml;
}
}
function fillDataSourceInfo(datasource) {
changeInnerHtml("DS-Info-Title" + datasource.Identity, datasource.Name);
changeInnerHtml("DS-Info-UserName" + datasource.Identity, datasource.UserName);
changeInnerHtml("DS-Info-URL" + datasource.Identity, datasource.URL);
changeInnerHtml("DS-Info-DbType" + datasource.Identity, datasource.DbType);
changeInnerHtml("DS-Info-DriverClassName" + datasource.Identity, datasource.DriverClassName);
changeInnerHtml("DS-Info-TestOnBorrow" + datasource.Identity, datasource.TestOnBorrow);
changeInnerHtml("DS-Info-TestWhileIdle" + datasource.Identity, datasource.TestWhileIdle);
changeInnerHtml("DS-Info-InitialSize" + datasource.Identity, datasource.InitialSize);
changeInnerHtml("DS-Info-MinIdle" + datasource.Identity, datasource.MinIdle);
changeInnerHtml("DS-Info-MaxActive" + datasource.Identity, datasource.MaxActive);
changeInnerHtml("DS-Info-LogicConnectCount" + datasource.Identity, datasource.LogicConnectCount);
changeInnerHtml("DS-Info-LogicCloseCount" + datasource.Identity, datasource.LogicCloseCount);
changeInnerHtml("DS-Info-LogicConnectErrorCount" + datasource.Identity, datasource.LogicConnectErrorCount);
changeInnerHtml("DS-Info-PhysicalConnectCount" + datasource.Identity, datasource.PhysicalConnectCount);
changeInnerHtml("DS-Info-PhysicalCloseCount" + datasource.Identity, datasource.PhysicalCloseCount);
changeInnerHtml("DS-Info-PhysicalConnectErrorCount" + datasource.Identity, datasource.PhysicalConnectErrorCount);
changeInnerHtml("DS-Info-PSCacheAccessCount" + datasource.Identity, datasource.PSCacheAccessCount);
changeInnerHtml("DS-Info-PSCacheHitCount" + datasource.Identity, datasource.PSCacheHitCount);
changeInnerHtml("DS-Info-PSCacheMissCount" + datasource.Identity, datasource.PSCacheMissCount);
}
function ajaxResponseForDataSourceInfo() {
if (xmlHttpForDataSourceInfo.readyState == 4) {
if (xmlHttpForDataSourceInfo.status == 200) {
var jsonResp = eval("(" + xmlHttpForDataSourceInfo.responseText + ")");
if (jsonResp.ResultCode == 1) {
var datasourceList = jsonResp.Content;
for ( var i = 0; i < datasourceList.length; i++) {
var datasource = datasourceList[i];
if (!document.getElementById("dataSourceStat" + datasource.Identity)) {
var listHtml = '';
var datasourceId = datasource.Identity;
listHtml += '<div id="dataSourceStat' + datasourceId + '">';
listHtml += '<h2>Basic Info For <span id="DS-Info-Title' + datasourceId + '"></span></h2>';
listHtml += '<table cellpadding="5" cellspacing="1" width="960">';
listHtml += '<tr>';
listHtml += '<td class="td_lable" width="150">UserName</td><td width="150" id="DS-Info-UserName' + datasourceId + '">&nbsp;</td>';
listHtml += '<td class="td_lable" width="140">URL</td><td id="DS-Info-URL' + datasourceId + '" colspan="3">&nbsp;</td>';
listHtml += '</tr>';
listHtml += '<tr >';
listHtml += '<td class="td_lable">DbType</td><td id="DS-Info-DbType' + datasourceId + '">&nbsp;</td>';
listHtml += '<td class="td_lable">DriverClassName</td><td id="DS-Info-DriverClassName' + datasourceId + '" colspan="3">&nbsp;</td>';
listHtml += '</tr>';
listHtml += '<tr>';
listHtml += '<td class="td_lable">TestOnBorrow</td><td id="DS-Info-TestOnBorrow' + datasourceId + '">&nbsp;</td>';
listHtml += '<td class="td_lable">TestWhileIdle</td><td id="DS-Info-TestWhileIdle' + datasourceId + '" colspan="3">&nbsp;</td>';
listHtml += '</tr>';
listHtml += '<tr>';
listHtml += '<td class="td_lable">InitialSize</td><td id="DS-Info-InitialSize' + datasourceId + '">&nbsp;</td>';
listHtml += '<td class="td_lable">MinIdle</td><td id="DS-Info-MinIdle' + datasourceId + '" width="150">&nbsp;</td>';
listHtml += '<td class="td_lable" width="190">MaxActive</td><td id="DS-Info-MaxActive' + datasourceId + '">&nbsp;</td>';
listHtml += '</tr>';
listHtml += '<tr>';
listHtml += '<td class="td_lable">LogicConnectCount</td><td id="DS-Info-LogicConnectCount' + datasourceId + '">&nbsp;</td>';
listHtml += '<td class="td_lable">LogicCloseCount</td><td id="DS-Info-LogicCloseCount' + datasourceId + '">&nbsp;</td>';
listHtml += '<td class="td_lable">LogicConnectErrorCount</td><td id="DS-Info-LogicConnectErrorCount' + datasourceId + '">&nbsp;</td>';
listHtml += '</tr>';
listHtml += '<tr>';
listHtml += '<td class="td_lable">PhysicalConnectCount</td><td id="DS-Info-PhysicalConnectCount' + datasourceId + '">&nbsp;</td>';
listHtml += '<td class="td_lable">PhysicalCloseCount</td><td id="DS-Info-PhysicalCloseCount' + datasourceId + '">&nbsp;</td>';
listHtml += '<td class="td_lable">PhysicalConnectErrorCount</td><td id="DS-Info-PhysicalConnectErrorCount' + datasourceId + '">&nbsp;</td>';
listHtml += '</tr>';
listHtml += '<tr>';
listHtml += '<td class="td_lable">PSCacheAccessCount</td><td id="DS-Info-PSCacheAccessCount' + datasourceId + '">&nbsp;</td>';
listHtml += '<td class="td_lable">PSCacheHitCount</td><td id="DS-Info-PSCacheHitCount' + datasourceId + '">&nbsp;</td>';
listHtml += '<td class="td_lable">PSCacheMissCount</td><td id="DS-Info-PSCacheMissCount' + datasourceId + '">&nbsp;</td>';
listHtml += '</tr>';
listHtml += '</table>';
listHtml += '</div>';
document.getElementById("dataSourceStatList").innerHTML += listHtml;
}
for(var i=0;i<dsList.length;i++){
var ds=dsList[i];
tabHtml+='<a href="javascript:showDataSource('+ds.Identity+')">['+ds.Name+']</a> ';
}
fillDataSourceInfo(datasource);
}
}
document.getElementById("menu").innerHTML=tabHtml;
}
}
}
}
}
}
function ajaxResponseForDataSourceInfo(){
var html='';
if(xmlHttpForDataSourceInfo.readyState==4){
if(xmlHttpForDataSourceInfo.status==200){
var jsonResp=eval("("+xmlHttpForDataSourceInfo.responseText+")");
if(jsonResp.ResultCode==1){
var ds=jsonResp.Content;
document.getElementById("DS-Info-Title").innerHTML=ds.Name;
document.getElementById("DS-Info-UserName").innerHTML=ds.UserName;
document.getElementById("DS-Info-URL").innerHTML=ds.URL;
document.getElementById("DS-Info-DbType").innerHTML=ds.DbType;
document.getElementById("DS-Info-DriverClassName").innerHTML=ds.DriverClassName;
document.getElementById("DS-Info-TestOnBorrow").innerHTML=ds.TestOnBorrow;
document.getElementById("DS-Info-TestWhileIdle").innerHTML=ds.TestWhileIdle;
document.getElementById("DS-Info-InitialSize").innerHTML=ds.InitialSize;
document.getElementById("DS-Info-MinIdle").innerHTML=ds.MinIdle;
document.getElementById("DS-Info-MaxActive").innerHTML=ds.MaxActive;
document.getElementById("DS-Info-LogicConnectCount").innerHTML=ds.LogicConnectCount;
document.getElementById("DS-Info-LogicCloseCount").innerHTML=ds.LogicCloseCount;
document.getElementById("DS-Info-LogicConnectErrorCount").innerHTML=ds.LogicConnectErrorCount;
document.getElementById("DS-Info-PhysicalConnectCount").innerHTML=ds.PhysicalConnectCount;
document.getElementById("DS-Info-PhysicalCloseCount").innerHTML=ds.PhysicalCloseCount;
document.getElementById("DS-Info-PhysicalConnectErrorCount").innerHTML=ds.PhysicalConnectErrorCount;
document.getElementById("DS-Info-PSCacheAccessCount").innerHTML=ds.PSCacheAccessCount;
document.getElementById("DS-Info-PSCacheHitCount").innerHTML=ds.PSCacheHitCount;
document.getElementById("DS-Info-PSCacheMissCount").innerHTML=ds.PSCacheMissCount;
}
}
}
}
function ajaxResponseForDataSourceSqlStatInfo(){
if(xmlHttpForDataSourceSqlStatInfo.readyState==4){
if(xmlHttpForDataSourceSqlStatInfo.status==200){
var jsonResp=eval("("+xmlHttpForDataSourceSqlStatInfo.responseText+")");
if(jsonResp.ResultCode==1){
var sqlStatList=jsonResp.Content;
var sqlStatTable=document.getElementById("SqlStatTable");
while(sqlStatTable.rows.length>1){
function ajaxResponseForDataSourceSqlStatInfo() {
if (xmlHttpForDataSourceSqlStatInfo.readyState == 4) {
if (xmlHttpForDataSourceSqlStatInfo.status == 200) {
var jsonResp = eval("(" + xmlHttpForDataSourceSqlStatInfo.responseText + ")");
if (jsonResp.ResultCode == 1) {
var sqlStatList = jsonResp.Content;
var sqlStatTable = document.getElementById("SqlStatTable");
while (sqlStatTable.rows.length > 1) {
sqlStatTable.deleteRow(1);
}
for(var i=0;i<sqlStatList.length;i++){
var sqlStat=sqlStatList[i];
for ( var i = 0; i < sqlStatList.length; i++) {
var sqlStat = sqlStatList[i];
var newRow = sqlStatTable.insertRow(-1);
newRow.insertCell(-1).innerHTML=sqlStat.SQL;
if(sqlStat.File) newRow.insertCell(-1).innerHTML=sqlStat.File;
else newRow.insertCell(-1).innerHTML='';
if(sqlStat.Name) newRow.insertCell(-1).innerHTML=sqlStat.Name;
else newRow.insertCell(-1).innerHTML='';
newRow.insertCell(-1).innerHTML=sqlStat.ExecuteCount;
newRow.insertCell(-1).innerHTML=sqlStat.ExecuteMillisTotal;
newRow.insertCell(-1).innerHTML=sqlStat.ExecuteMillisMax;
newRow.insertCell(-1).innerHTML=sqlStat.InTxnCount;
newRow.insertCell(-1).innerHTML=sqlStat.ErrorCount;
newRow.insertCell(-1).innerHTML=sqlStat.UpdateCount;
newRow.insertCell(-1).innerHTML=sqlStat.FetchRowCount;
newRow.insertCell(-1).innerHTML=sqlStat.RunningCount;
newRow.insertCell(-1).innerHTML=sqlStat.ConcurrentMax;
var hi=newRow.insertCell(-1);
var hiHtml='';
hiHtml+='<a href="#'+sqlStat.ExecHistogram+'">ExecHistogram</a> |';
hiHtml+='<a href="#'+sqlStat.FetchRowHistogram+'">FetchRow</a> | ';
hiHtml+='<a href="#'+sqlStat.UpdateCountHistogram+'">UpdateCount</a> | ';
hiHtml+='<a href="#'+sqlStat.ExecAndRsHoldHistogram+'">ExecAndRsHold</a>';
hi.innerHTML=hiHtml;
newRow.insertCell(-1).innerHTML = sqlStat.SQL;
if (sqlStat.File)
newRow.insertCell(-1).innerHTML = sqlStat.File;
else
newRow.insertCell(-1).innerHTML = '';
if (sqlStat.Name)
newRow.insertCell(-1).innerHTML = sqlStat.Name;
else
newRow.insertCell(-1).innerHTML = '';
newRow.insertCell(-1).innerHTML = sqlStat.ExecuteCount;
newRow.insertCell(-1).innerHTML = sqlStat.ExecuteMillisTotal;
newRow.insertCell(-1).innerHTML = sqlStat.ExecuteMillisMax;
newRow.insertCell(-1).innerHTML = sqlStat.InTxnCount;
newRow.insertCell(-1).innerHTML = sqlStat.ErrorCount;
newRow.insertCell(-1).innerHTML = sqlStat.UpdateCount;
newRow.insertCell(-1).innerHTML = sqlStat.FetchRowCount;
newRow.insertCell(-1).innerHTML = sqlStat.RunningCount;
newRow.insertCell(-1).innerHTML = sqlStat.ConcurrentMax;
var hi = newRow.insertCell(-1);
var hiHtml = '';
hiHtml += '<a href="#' + sqlStat.ExecHistogram + '">ExecHistogram</a> |';
hiHtml += '<a href="#' + sqlStat.FetchRowHistogram + '">FetchRow</a> | ';
hiHtml += '<a href="#' + sqlStat.UpdateCountHistogram + '">UpdateCount</a> | ';
hiHtml += '<a href="#' + sqlStat.ExecAndRsHoldHistogram + '">ExecAndRsHold</a>';
hi.innerHTML = hiHtml;
}
}
}
}
}
function showDataSource(id){
datasourceId=id;
ajaxRequestForDataSourceInfo();
ajaxRequestForDataSourceSqlStatInfo();
}
function init(){
ajaxRequestForBasicInfo();
var time1=setInterval("ajaxRequestForBasicInfo();",1000);
var time2=setInterval("ajaxRequestForDataSourceInfo();",1000);
var time3=setInterval("ajaxRequestForDataSourceSqlStatInfo();",1000);
}
}
}
}
@@ -0,0 +1,41 @@
<!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 SqlStat List</title>
<link href="style.css" type="text/css" rel="stylesheet"/>
<script src="js.js" type="text/javascript"></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">DataSourceStatList</a> | <a href="sql.html">SqlStatList</a>
</div>
</br>
<div id="main">
<h2>SqlStat List</h2>
<table cellspacing="1" cellpadding="5" id="SqlStatTable" width="99%">
<thead>
<th class="td_lable">SQL</th>
<th class="td_lable">File</th>
<th class="td_lable">Name</th>
<th class="td_lable" width="50">Execute Count</th>
<th class="td_lable" width="50">Execute Millis Total</th>
<th class="td_lable" width="50">Execute Millis Max</th>
<th class="td_lable" width="50">InTxn Count</th>
<th class="td_lable" width="50">Error Count</th>
<th class="td_lable" width="50">Effected Row Count</th>
<th class="td_lable" width="50">Fetch Row Count</th>
<th class="td_lable" width="50">Running Count</th>
<th class="td_lable" width="80">Concurrent Max</th>
<th class="td_lable" width="370">Histogram</th>
</thead>
</table>
</div>
</body>
</html>