add webStat support

This commit is contained in:
wenshao
2012-08-12 14:43:18 +08:00
parent 697a596ec2
commit cef63ebdd6
6 changed files with 135 additions and 5 deletions
@@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map;
import com.alibaba.druid.stat.DruidStatManagerFacade;
import com.alibaba.druid.support.http.stat.WebAppStatManager;
import com.alibaba.druid.util.MapComparator;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
@@ -81,9 +82,18 @@ public class JSONDruidStatService {
Object result = druidStatManager.getSqlStatData(id);
return returnJSONResult(result == null ? RESULT_CODE_ERROR : RESULT_CODE_SUCCESS, result);
}
if (url.startsWith("/weburi.json")) {
return returnJSONResult(RESULT_CODE_SUCCESS, getWebURIStatDataList(parameters));
}
return returnJSONResult(RESULT_CODE_ERROR, "Do not support this request, please contact with administrator.");
}
private List<Map<String, Object>> getWebURIStatDataList(Map<String, String> parameters) {
List<Map<String, Object>> array = WebAppStatManager.getInstance().getWebAppStatData();
return array;
}
private List<Map<String, Object>> getSqlStatDataList(Map<String, String> parameters) {
List<Map<String, Object>> array = druidStatManager.getSqlStatDataList();
@@ -139,7 +139,7 @@ public class WebAppStat {
for (WebURIStat uriStat : this.uriStatMap.values()) {
Map<String, Object> uriStatData = uriStat.getStatData();
long runningCount = (Long) uriStatData.get("RunningCount");
int runningCount = ((Number) uriStatData.get("RunningCount")).intValue();
long requestCount = (Long) uriStatData.get("RequestCount");
if (runningCount == 0 && requestCount == 0) {
@@ -9,7 +9,7 @@
<script >
function init(){
ajaxRequestForDataSourceInfo();
var time2=setInterval("ajaxRequestForDataSourceInfo();",2000);
var time2=setInterval("ajaxRequestForDataSourceInfo();",5000);
}
</script>
</head>
@@ -0,0 +1,103 @@
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 += '&uarr;';
} else if (sqlViewOrderType == 'desc') {
html += '&darr;';
}
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 = 'weburi.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("WebUriStatTable");
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 = subSqlString(sqlStat.URI, 25);
newRow.insertCell(-1).innerHTML = sqlStat.RequestCount;
newRow.insertCell(-1).innerHTML = sqlStat.RunningCount;
newRow.insertCell(-1).innerHTML = sqlStat.ConcurrentMax;
}
}
@@ -9,7 +9,7 @@
<script >
function init(){
ajaxRequestForDataSourceSqlStatInfo();
var time3=setInterval("ajaxRequestForDataSourceSqlStatInfo();",2000);
var time3=setInterval("ajaxRequestForDataSourceSqlStatInfo();",5000);
}
</script>
</head>
@@ -5,15 +5,32 @@
<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/weburi.js" type="text/javascript" charset="utf8"></script>
<script >
function init(){
ajaxRequestForDataSourceSqlStatInfo();
var time3=setInterval("ajaxRequestForDataSourceSqlStatInfo();",2000);
}
</script>
</head>
<body>
<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>
</div>
<br />
<div id="main">
<table cellspacing="1" cellpadding="5" id="WebUriStatTable" width="99%">
<thead>
<tr>
<th class="td_lable">N--</th>
<th class="td_lable"><a id="URI" href="javascript:void(0)" onclick="setOrderBy('URI');">URI</a></th>
<th class="td_lable" width="50"><a id="RequestCount" href="javascript:void(0)" onclick="setOrderBy('RequestCount');">Running 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>
</tr>
</thead>
</table>
</div>
<div id="footer">powered by <a href="mailto:sandzhangtoo@gmail.com">sandzhang</a></div>
</body>