mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
增加重置数据源统计信息,同时记录统计日志
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user