mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve springStat
This commit is contained in:
@@ -118,6 +118,12 @@ public class JSONDruidStatService {
|
||||
if (url.startsWith("/spring.json")) {
|
||||
return returnJSONResult(RESULT_CODE_SUCCESS, getSpringStatDataList(parameters));
|
||||
}
|
||||
|
||||
if (url.startsWith("/spring-detail.json")) {
|
||||
String clazz = parameters.get("class");
|
||||
String method = parameters.get("method");
|
||||
return returnJSONResult(RESULT_CODE_SUCCESS, getSpringMethodStatData(clazz, method));
|
||||
}
|
||||
|
||||
return returnJSONResult(RESULT_CODE_ERROR, "Do not support this request, please contact with administrator.");
|
||||
}
|
||||
@@ -139,6 +145,10 @@ public class JSONDruidStatService {
|
||||
private Map<String, Object> getWebSessionStatData(String sessionId) {
|
||||
return WebAppStatManager.getInstance().getSessionStat(sessionId);
|
||||
}
|
||||
|
||||
private Map<String, Object> getSpringMethodStatData(String clazz, String method) {
|
||||
return SpringStatManager.getInstance().getMethodStatData(clazz, method);
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getWebSessionStatDataList(Map<String, String> parameters) {
|
||||
List<Map<String, Object>> array = WebAppStatManager.getInstance().getSessionStatData();
|
||||
|
||||
@@ -421,6 +421,9 @@ public class WebStatFilter implements Filter {
|
||||
SpringMethodStat springMethodStat = SpringMethodStat.current();
|
||||
if (springMethodStat != null) {
|
||||
springMethodStat.addJdbcExecuteTimeNano(nanos);
|
||||
if (error != null) {
|
||||
springMethodStat.incrementJdbcExecuteErrorCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,39 +7,40 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class SpringMethodStat {
|
||||
|
||||
private final static ThreadLocal<SpringMethodStat> currentLocal = new ThreadLocal<SpringMethodStat>();
|
||||
private final static ThreadLocal<SpringMethodStat> currentLocal = new ThreadLocal<SpringMethodStat>();
|
||||
|
||||
private final SpringMethodInfo methodInfo;
|
||||
private final SpringMethodInfo methodInfo;
|
||||
|
||||
private final AtomicInteger runningCount = new AtomicInteger();
|
||||
private final AtomicInteger concurrentMax = new AtomicInteger();
|
||||
private final AtomicLong executeCount = new AtomicLong(0);
|
||||
private final AtomicLong executeErrorCount = new AtomicLong(0);
|
||||
private final AtomicLong executeTimeNano = new AtomicLong();
|
||||
private final AtomicInteger runningCount = new AtomicInteger();
|
||||
private final AtomicInteger concurrentMax = new AtomicInteger();
|
||||
private final AtomicLong executeCount = new AtomicLong(0);
|
||||
private final AtomicLong executeErrorCount = new AtomicLong(0);
|
||||
private final AtomicLong executeTimeNano = new AtomicLong();
|
||||
|
||||
private final AtomicLong jdbcFetchRowCount = new AtomicLong();
|
||||
private final AtomicLong jdbcUpdateCount = new AtomicLong();
|
||||
private final AtomicLong jdbcExecuteCount = new AtomicLong();
|
||||
private final AtomicLong jdbcExecuteTimeNano = new AtomicLong();
|
||||
private final AtomicLong jdbcFetchRowCount = new AtomicLong();
|
||||
private final AtomicLong jdbcUpdateCount = new AtomicLong();
|
||||
private final AtomicLong jdbcExecuteCount = new AtomicLong();
|
||||
private final AtomicLong jdbcExecuteErrorCount = new AtomicLong();
|
||||
private final AtomicLong jdbcExecuteTimeNano = new AtomicLong();
|
||||
|
||||
private final AtomicLong jdbcCommitCount = new AtomicLong();
|
||||
private final AtomicLong jdbcRollbackCount = new AtomicLong();
|
||||
private final AtomicLong jdbcCommitCount = new AtomicLong();
|
||||
private final AtomicLong jdbcRollbackCount = new AtomicLong();
|
||||
|
||||
public SpringMethodStat(SpringMethodInfo 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);
|
||||
}
|
||||
@@ -137,6 +138,18 @@ public class SpringMethodStat {
|
||||
public long getJdbcExecuteCount() {
|
||||
return jdbcExecuteCount.get();
|
||||
}
|
||||
|
||||
public long getJdbcExecuteErrorCount() {
|
||||
return jdbcExecuteErrorCount.get();
|
||||
}
|
||||
|
||||
public void addJdbcExecuteErrorCount(long executeCount) {
|
||||
jdbcExecuteErrorCount.addAndGet(executeCount);
|
||||
}
|
||||
|
||||
public void incrementJdbcExecuteErrorCount() {
|
||||
jdbcExecuteErrorCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public long getJdbcExecuteTimeMillis() {
|
||||
return getJdbcExecuteTimeNano() / (1000 * 1000);
|
||||
@@ -176,7 +189,7 @@ public class SpringMethodStat {
|
||||
|
||||
public Map<String, Object> getStatData() {
|
||||
Map<String, Object> data = new LinkedHashMap<String, Object>();
|
||||
|
||||
|
||||
data.put("Class", this.getMethodInfo().getClassName());
|
||||
data.put("Method", this.getMethodInfo().getSignature());
|
||||
|
||||
@@ -190,6 +203,7 @@ public class SpringMethodStat {
|
||||
data.put("JdbcRollbackCount", this.getJdbcRollbackCount());
|
||||
|
||||
data.put("JdbcExecuteCount", this.getJdbcExecuteCount());
|
||||
data.put("JdbcExecuteErrorCount", this.getJdbcExecuteErrorCount());
|
||||
data.put("JdbcExecuteTimeMillis", this.getJdbcExecuteTimeMillis());
|
||||
data.put("JdbcFetchRowCount", this.getJdbcFetchRowCount());
|
||||
data.put("JdbcUpdateCount", this.getJdbcUpdateCount());
|
||||
|
||||
@@ -50,4 +50,15 @@ public class SpringStat {
|
||||
}
|
||||
return methodStatDataList;
|
||||
}
|
||||
|
||||
public Map<String, Object> getMethodStatData(String clazz, String method) {
|
||||
for (SpringMethodStat methodStat : this.methodStats.values()) {
|
||||
SpringMethodInfo methodInfo = methodStat.getMethodInfo();
|
||||
if (methodInfo.getClassName().equals(clazz) && methodInfo.getSignature().equals(method)) {
|
||||
return methodStat.getStatData();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,19 @@ public class SpringStatManager {
|
||||
return allMethodStatDataList;
|
||||
}
|
||||
|
||||
public Map<String, Object> getMethodStatData(String clazz, String method) {
|
||||
Set<Object> stats = getSpringStatSet();
|
||||
|
||||
for (Object stat : stats) {
|
||||
Map<String, Object> statData = SpringStatUtils.getMethodStatData(stat, clazz, method);
|
||||
if (statData != null) {
|
||||
return statData;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void resetStat() {
|
||||
Set<Object> stats = getSpringStatSet();
|
||||
|
||||
|
||||
@@ -26,6 +26,22 @@ public class SpringStatUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Object> getMethodStatData(Object methodStat, String clazz, String methodSignature) {
|
||||
if (methodStat.getClass() == SpringStat.class) {
|
||||
return ((SpringStat) methodStat).getMethodStatData(clazz, methodSignature);
|
||||
}
|
||||
|
||||
try {
|
||||
Method method = methodStat.getClass().getMethod("getMethodStatData", String.class, String.class);
|
||||
Object obj = method.invoke(methodStat, clazz, methodSignature);
|
||||
return (Map<String, Object>) obj;
|
||||
} catch (Exception e) {
|
||||
LOG.error("getMethodStatDataList error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset(Object webStat) {
|
||||
if (webStat.getClass() == SpringStat.class) {
|
||||
|
||||
Reference in New Issue
Block a user