增加重置数据源统计信息,同时记录统计日志

This commit is contained in:
zhaoye
2015-07-08 16:19:03 +08:00
parent 8954735ada
commit 35ff7bafad
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());
}