mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve sessionStat
This commit is contained in:
@@ -27,7 +27,7 @@ public class JSONDruidStatService {
|
||||
|
||||
private final static JSONDruidStatService instance = new JSONDruidStatService();
|
||||
|
||||
private static DruidStatManagerFacade statManagerFacade = DruidStatManagerFacade.getInstance();
|
||||
private static DruidStatManagerFacade statManagerFacade = DruidStatManagerFacade.getInstance();
|
||||
|
||||
public final static int RESULT_CODE_SUCCESS = 1;
|
||||
public final static int RESULT_CODE_ERROR = -1;
|
||||
@@ -105,6 +105,11 @@ public class JSONDruidStatService {
|
||||
return returnJSONResult(RESULT_CODE_SUCCESS, getWebSessionStatDataList(parameters));
|
||||
}
|
||||
|
||||
if (url.startsWith("/websession-") && url.indexOf(".json") > 0) {
|
||||
String id = StringUtils.subString(url, "websession-", ".json");
|
||||
return returnJSONResult(RESULT_CODE_SUCCESS, getWebSessionDetail(id));
|
||||
}
|
||||
|
||||
if (url.startsWith("/spring.json")) {
|
||||
return returnJSONResult(RESULT_CODE_SUCCESS, getSpringStatDataList(parameters));
|
||||
}
|
||||
@@ -122,6 +127,10 @@ public class JSONDruidStatService {
|
||||
return comparatorOrderBy(array, parameters);
|
||||
}
|
||||
|
||||
private Map<String, Object> getWebSessionDetail(String sessionId) {
|
||||
return WebAppStatManager.getInstance().getSessionStat(sessionId);
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getWebSessionStatDataList(Map<String, String> parameters) {
|
||||
List<Map<String, Object>> array = WebAppStatManager.getInstance().getSessionStatData();
|
||||
return array;
|
||||
|
||||
@@ -145,6 +145,16 @@ public class WebAppStat {
|
||||
public WebSessionStat getSessionStat(String sessionId) {
|
||||
return getSessionStat(sessionId, false);
|
||||
}
|
||||
|
||||
public Map<String, Object> getSessionStatData(String sessionId) {
|
||||
WebSessionStat uriStat = sessionStatMap.get(sessionId);
|
||||
|
||||
if (uriStat == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return uriStat.getStatData();
|
||||
}
|
||||
|
||||
public WebSessionStat getSessionStat(String sessionId, boolean create) {
|
||||
sessionStatLock.readLock().lock();
|
||||
|
||||
@@ -65,6 +65,19 @@ public class WebAppStatManager {
|
||||
|
||||
return allAppUriStatDataList;
|
||||
}
|
||||
|
||||
public Map<String, Object> getSessionStat(String sessionId) {
|
||||
Set<Object> stats = getWebAppStatSet();
|
||||
|
||||
for (Object stat : stats) {
|
||||
Map<String, Object> statData = WebAppStatUtils.getSessionStatData(stat, sessionId);
|
||||
if (statData != null) {
|
||||
return statData;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addWebAppStatSet(Object webAppStat) {
|
||||
getWebAppStatSet().add(webAppStat);
|
||||
|
||||
@@ -58,6 +58,22 @@ public class WebAppStatUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Object> getSessionStatData(Object webStat, String sessionId) {
|
||||
if (webStat.getClass() == WebAppStat.class) {
|
||||
return ((WebAppStat) webStat).getSessionStatData(sessionId);
|
||||
}
|
||||
|
||||
try {
|
||||
Method method = webStat.getClass().getMethod("getSessionStatData", String.class);
|
||||
Object obj = method.invoke(webStat);
|
||||
return (Map<String, Object>) obj;
|
||||
} catch (Exception e) {
|
||||
LOG.error("getSessionStatData error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset(Object webStat) {
|
||||
if (webStat.getClass() == WebAppStat.class) {
|
||||
|
||||
Reference in New Issue
Block a user