Merge pull request #894 from irfen-fork/master

增加重置数据源统计信息,同时记录统计日志
This commit is contained in:
高铁
2015-07-08 23:55:24 +08:00
7 changed files with 53 additions and 4 deletions
@@ -230,6 +230,23 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
}
}
public void logAndResetDataSource() {
IdentityHashMap<Object, ObjectName> dataSources = getInstances();
synchronized (dataSources) {
for (Object item : dataSources.keySet()) {
try {
Method method = item.getClass().getMethod("logStats");
method.invoke(item);
} catch (Exception e) {
LOG.error("resetStat error", e);
}
}
resetCount.incrementAndGet();
}
}
public long getResetCount() {
return resetCount.get();
}
@@ -96,6 +96,13 @@ public final class DruidStatManagerFacade {
resetCount.incrementAndGet();
}
public void logAndResetDataSource() {
if (!isResetEnable()) {
return;
}
DruidDataSourceStatManager.getInstance().logAndResetDataSource();
}
public boolean isResetEnable() {
return resetEnable;
}
@@ -91,6 +91,12 @@ public final class DruidStatService implements DruidStatServiceMBean {
return returnJSONResult(RESULT_CODE_SUCCESS, null);
}
if (url.equals("/log-and-reset.json")) {
statManagerFacade.logAndResetDataSource();
return returnJSONResult(RESULT_CODE_SUCCESS, null);
}
if (url.equals("/datasource.json")) {
return returnJSONResult(RESULT_CODE_SUCCESS, statManagerFacade.getDataSourceStatDataList());
}
File diff suppressed because one or more lines are too long
@@ -18,7 +18,8 @@
<li><a href="api.html" class="lang" langKey="JSON API">JSON API</a></li>
</ul>
<a langKey="ResetAll" class="btn btn-primary lang" href="javascript:druid.common.ajaxRequestForReset();">Reset All</a>
<a langKey="LogAndReset" class="btn btn-primary lang" href="javascript:druid.common.ajaxRequestForLogAndReset();">Log And Reset</a>
</div>
</div>
</div>
</div>
</div>
@@ -50,6 +50,23 @@ druid.common = function () {
dataType: "json"
});
},
ajaxRequestForLogAndReset : function() {
if(!confirm("Are you sure to reset data source stat? It'll clear and log all stat data !")){
return;
}
$.ajax({
type: 'POST',
url: "log-and-reset.json",
success: function(data) {
if (data.ResultCode == 1) {
alert("already reset all stat");
}
},
dataType: "json"
});
},
getAjaxUrl : function(uri) {
var result = uri;
@@ -181,4 +198,4 @@ function replace (data) {
function format(s) {
var str=s+='';
return str.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
}
}
@@ -13,7 +13,8 @@ druid.lang = function() {
'Spring' : ['Spring' , 'spring监控'],
'JSON API' : ['JSON API' , 'JSON API'],
'ResetAll' : ['Reset All' , '重置'],
'LogAndReset' : ['Log And Reset' , '记录日志并重置'],
'StatIndex' : ['Stat Index', '统计索引'],
'ViewJSONAPI' : ['View JSON API','查看JSON API'],
'Version' : ['Version' , '版本'],