mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add spring stat support
This commit is contained in:
@@ -48,6 +48,9 @@ public class JSONDruidStatService {
|
||||
|
||||
if (url.equals("/reset-all.json")) {
|
||||
druidStatManager.resetAll();
|
||||
SpringStatManager.getInstance().resetStat();
|
||||
WebAppStatManager.getInstance().resetStat();
|
||||
|
||||
return returnJSONResult(RESULT_CODE_SUCCESS, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,24 @@ public class WebAppStat {
|
||||
return currentLocal.get();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
concurrentMax.set(0);
|
||||
requestCount.set(0);
|
||||
requestCount.set(0);
|
||||
|
||||
sessionStatLock.writeLock().lock();
|
||||
try {
|
||||
sessionStatMap.clear();
|
||||
} finally {
|
||||
sessionStatLock.writeLock().unlock();
|
||||
}
|
||||
|
||||
uriStatMap.clear();
|
||||
|
||||
uriStatMapFullCount.set(0);
|
||||
uriSessionMapFullCount.set(0);
|
||||
}
|
||||
|
||||
public WebAppStat(){
|
||||
this(null);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class WebAppStatManager {
|
||||
|
||||
return statDataList;
|
||||
}
|
||||
|
||||
|
||||
public List<Map<String, Object>> getURIStatData() {
|
||||
Set<Object> stats = getWebAppStatSet();
|
||||
|
||||
@@ -52,17 +52,17 @@ public class WebAppStatManager {
|
||||
|
||||
return allAppUriStatDataList;
|
||||
}
|
||||
|
||||
|
||||
public List<Map<String, Object>> getSessionStatData() {
|
||||
Set<Object> stats = getWebAppStatSet();
|
||||
|
||||
|
||||
List<Map<String, Object>> allAppUriStatDataList = new ArrayList<Map<String, Object>>();
|
||||
|
||||
|
||||
for (Object stat : stats) {
|
||||
List<Map<String, Object>> uriStatDataList = WebAppStatUtils.getSessionStatDataList(stat);
|
||||
allAppUriStatDataList.addAll(uriStatDataList);
|
||||
}
|
||||
|
||||
|
||||
return allAppUriStatDataList;
|
||||
}
|
||||
|
||||
@@ -93,4 +93,12 @@ public class WebAppStatManager {
|
||||
return webAppStats;
|
||||
}
|
||||
|
||||
public void resetStat() {
|
||||
Set<Object> stats = getWebAppStatSet();
|
||||
|
||||
for (Object stat : stats) {
|
||||
WebAppStatUtils.rset(stat);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class WebAppStatUtils {
|
||||
if (webStat.getClass() == WebAppStat.class) {
|
||||
return ((WebAppStat) webStat).getURIStatDataList();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Method method = webStat.getClass().getMethod("getURIStatDataList");
|
||||
Object obj = method.invoke(webStat);
|
||||
@@ -48,7 +48,7 @@ public class WebAppStatUtils {
|
||||
if (webStat.getClass() == WebAppStat.class) {
|
||||
return ((WebAppStat) webStat).getSessionStatDataList();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Method method = webStat.getClass().getMethod("getSessionStatDataList");
|
||||
Object obj = method.invoke(webStat);
|
||||
@@ -58,4 +58,17 @@ public class WebAppStatUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void rset(Object webStat) {
|
||||
if (webStat.getClass() == WebAppStat.class) {
|
||||
((WebAppStat) webStat).reset();
|
||||
}
|
||||
|
||||
try {
|
||||
Method method = webStat.getClass().getMethod("rset");
|
||||
method.invoke(webStat);
|
||||
} catch (Exception e) {
|
||||
LOG.error("reset error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,21 @@ public class SpringMethodStat {
|
||||
public SpringMethodStat(MethodInfo methodInfo){
|
||||
this.methodInfo = methodInfo;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
concurrentMax.set(0);
|
||||
executeCount.set(0);
|
||||
executeErrorCount.set(0);
|
||||
executeTimeNano.set(0);
|
||||
|
||||
jdbcFetchRowCount.set(0);
|
||||
jdbcUpdateCount.set(0);
|
||||
jdbcExecuteCount.set(0);
|
||||
jdbcExecuteTimeNano.set(0);
|
||||
|
||||
jdbcCommitCount.set(0);
|
||||
jdbcRollbackCount.set(0);
|
||||
}
|
||||
|
||||
public MethodInfo getMethodInfo() {
|
||||
return methodInfo;
|
||||
|
||||
@@ -14,6 +14,12 @@ public class SpringStat {
|
||||
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
for (SpringMethodStat stat : methodStats.values()) {
|
||||
stat.reset();
|
||||
}
|
||||
}
|
||||
|
||||
public SpringMethodStat getMethodStat(MethodInfo methodInfo, boolean create) {
|
||||
SpringMethodStat methodStat = methodStats.get(methodInfo);
|
||||
if (methodStat != null) {
|
||||
@@ -27,7 +33,7 @@ public class SpringStat {
|
||||
|
||||
return methodStat;
|
||||
}
|
||||
|
||||
|
||||
public List<Map<String, Object>> getMethodStatDataList() {
|
||||
List<Map<String, Object>> methodStatDataList = new ArrayList<Map<String, Object>>(this.methodStats.size());
|
||||
for (SpringMethodStat methodStat : this.methodStats.values()) {
|
||||
|
||||
@@ -62,4 +62,12 @@ public class SpringStatManager {
|
||||
|
||||
return allMethodStatDataList;
|
||||
}
|
||||
|
||||
public void resetStat() {
|
||||
Set<Object> stats = getSpringStatSet();
|
||||
|
||||
for (Object stat : stats) {
|
||||
SpringStatUtils.rset(stat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,17 @@ public class SpringStatUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void rset(Object webStat) {
|
||||
if (webStat.getClass() == SpringStat.class) {
|
||||
((SpringStat) webStat).reset();
|
||||
}
|
||||
|
||||
try {
|
||||
Method method = webStat.getClass().getMethod("rset");
|
||||
method.invoke(webStat);
|
||||
} catch (Exception e) {
|
||||
LOG.error("reset error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user