Author: taylor
Date: Mon Apr 27 03:10:51 2015
New Revision: 1676189
URL: http://svn.apache.org/r1676189
Log:
JS2-1320: adding cache statistics to chart portlets
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/StatisticsManagementService.java
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/StatisticsManagementService.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/StatisticsManagementService.java?rev=1676189&r1=1676188&r2=1676189&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/StatisticsManagementService.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/StatisticsManagementService.java
Mon Apr 27 03:10:51 2015
@@ -17,10 +17,15 @@
package org.apache.jetspeed.services.rest;
import org.apache.jetspeed.JetspeedActions;
+import org.apache.jetspeed.cache.CacheMonitorState;
+import org.apache.jetspeed.cache.JetspeedCacheMonitor;
import org.apache.jetspeed.exception.JetspeedException;
import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.statistics.AggregateStatistics;
+import org.apache.jetspeed.statistics.InvalidCriteriaException;
import org.apache.jetspeed.statistics.PortalStatistics;
+import org.apache.jetspeed.statistics.StatisticsQueryCriteria;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,6 +36,7 @@ import javax.ws.rs.WebApplicationExcepti
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
@@ -41,35 +47,218 @@ import java.util.Map;
@Path("/statistics/")
public class StatisticsManagementService {
- private static Logger log =
LoggerFactory.getLogger(ProfilerManagementService.class);
+ private static Logger log =
LoggerFactory.getLogger(StatisticsManagementService.class);
private PortalStatistics statistics;
private PortletActionSecurityBehavior securityBehavior;
+ private JetspeedCacheMonitor cacheMonitor;
public StatisticsManagementService(PortalStatistics statistics,
- PortletActionSecurityBehavior
securityBehavior) {
+ PortletActionSecurityBehavior
securityBehavior,
+ JetspeedCacheMonitor cache) {
this.statistics = statistics;
this.securityBehavior = securityBehavior;
+ this.cacheMonitor = cache;
}
/**
- * Retrieve JVM memory info
+ * Retrieve JVM runtime memory usage info
*
* @param servletRequest
* @param uriInfo
* @return
*/
@GET
- @Path("/runtime")
- public Map<String,Map<String,Long>> runtimeInfo(@Context
HttpServletRequest servletRequest, @Context UriInfo uriInfo) {
+ @Path("/memory")
+ public Map<String,Map<String,Long>> memoryInfo(@Context HttpServletRequest
servletRequest, @Context UriInfo uriInfo) {
+
checkPrivilege(servletRequest, JetspeedActions.VIEW);
+
Runtime runtime = Runtime.getRuntime();
+
Map<String,Long> memory = new HashMap<>();
memory.put("total", runtime.totalMemory());
memory.put("free", runtime.freeMemory());
//memory.put("max", runtime.maxMemory());
Map<String,Map<String,Long>> result = new HashMap<>();
result.put("memory", memory);
+
+ return result;
+ }
+
+ /**
+ * Retrieve Portal top page usage info
+ *
+ * @param servletRequest
+ * @param uriInfo
+ * @return
+ */
+ @GET
+ @Path("/pages")
+ public Map<String,Map<String,Long>> pagesInfo(@Context HttpServletRequest
servletRequest, @Context UriInfo uriInfo) {
+
+ checkPrivilege(servletRequest, JetspeedActions.VIEW);
+
+ Map<String,Long> pages = new HashMap<>();
+
+ StatisticsQueryCriteria criteria =
statistics.createStatisticsQueryCriteria();
+ criteria.setQueryType("page");
+ try {
+ AggregateStatistics pageStats =
statistics.queryStatistics(criteria);
+ List statList = pageStats.getStatlist();
+ int size = statList.size();
+
+ for (int i=0; i<size; i++){
+ HashMap<String,String> stats = (HashMap)statList.get(i);
+ String pageName = stats.get("groupColumn");
+ String pageCount = stats.get("count");
+ pages.put(pageName.replaceAll("/(.+)/", "/"),
Long.valueOf(pageCount));
+ }
+ }
+ catch (InvalidCriteriaException e) {
+ throw new WebApplicationException(new
IllegalArgumentException("Statistics query criteria invalid"));
+ }
+
+// pages.put("/default-page", (long)300);
+// pages.put("/four-rows", (long)120);
+// pages.put("/login", (long)90);
+// pages.put("/register", (long)62);
+// pages.put("/dashboard", (long)17);
+
+ Map<String,Map<String,Long>> result = new HashMap<>();
+ result.put("pages", pages);
+
+ return result;
+ }
+
+ /**
+ * Retrieve Portal top user session usage info
+ *
+ * @param servletRequest
+ * @param uriInfo
+ * @return
+ */
+ @GET
+ @Path("/users")
+ public Map<String,Map<String,Long>> usersInfo(@Context HttpServletRequest
servletRequest, @Context UriInfo uriInfo) {
+
+ checkPrivilege(servletRequest, JetspeedActions.VIEW);
+
+ Map<String,Long> users = new HashMap<>();
+
+ StatisticsQueryCriteria criteria =
statistics.createStatisticsQueryCriteria();
+ criteria.setQueryType("user");
+ try {
+ AggregateStatistics pageStats =
statistics.queryStatistics(criteria);
+ List statList = pageStats.getStatlist();
+ int size = statList.size();
+
+ for (int i=0; i<size; i++){
+ HashMap<String,String> stats = (HashMap)statList.get(i);
+ String pageName = stats.get("groupColumn");
+ if (!pageName.equals("guest")) {
+ String pageCount = stats.get("count");
+ users.put(pageName, Long.valueOf(pageCount));
+ }
+ }
+ }
+ catch (InvalidCriteriaException e) {
+ throw new WebApplicationException(new
IllegalArgumentException("Statistics query criteria invalid"));
+ }
+
+// Map<String,Long> users = new HashMap<>();
+// users.put("Admin", (long)19);
+// users.put("Mary", (long)9);
+// users.put("Ron", (long)5);
+// users.put("David", (long)12);
+// users.put("John", (long) 10);
+// users.put("Luke", (long) 1);
+
+ Map<String,Map<String,Long>> result = new HashMap<>();
+ result.put("users", users);
+
+ return result;
+ }
+
+ /**
+ * Retrieve Portal top caches usage info
+ *
+ * @param servletRequest
+ * @param uriInfo
+ * @return
+ */
+ @GET
+ @Path("/caches")
+ public Map<String,Map<String,Map<String,Long>>> cachesInfo(@Context
HttpServletRequest servletRequest, @Context UriInfo uriInfo) {
+
+ checkPrivilege(servletRequest, JetspeedActions.VIEW);
+
+ final String PREFERENCES = "preferencesCache";
+ final String PORTLET_DEFINITION_NAME = "portletDefinitionNameCache";
+ final String PORTLET_APPLICATION_NAME = "portletApplicationNameCache";
+ final String PAGE_FILE = "pageFileCache";
+ final String PAGE_MANAGER_PATH = "pageManagerPathCache";
+
+ Map<String,Map<String,Long>> caches = new HashMap<>();
+
+ /* Loads all of the caches counts except those with all zeros counts
+ List<CacheMonitorState> stateList = cacheMonitor.snapshotStatistics();
+ int size = stateList.size();
+ for (int i=0; i<size; i++) {
+ CacheMonitorState state = stateList.get(i);
+ Map<String, Long> counts = new HashMap<>();
+ Long hits = state.getCacheHits();
+ Long misses = state.getCacheMisses();
+ Long evictions = state.getEvictionCount();
+ if (hits > 0 || misses > 0 || evictions != 0) {
+ counts.put("hits", hits);
+ counts.put("misses", misses);
+ counts.put("evictions", evictions);
+ caches.put(state.getCacheName(), counts);
+ }
+ }*/
+
+ CacheMonitorState cacheState =
cacheMonitor.snapshotStatistics(PREFERENCES);
+ Map<String,Long> preferences = new HashMap<>();
+ preferences.put("hits", cacheState.getCacheHits());
+ preferences.put("misses", cacheState.getCacheMisses());
+ preferences.put("evictions", cacheState.getEvictionCount());
+ caches.put("Preferences", preferences);
+
+ cacheState = cacheMonitor.snapshotStatistics(PORTLET_DEFINITION_NAME);
+ Map<String,Long> portlet = new HashMap<>();
+ portlet.put("hits", cacheState.getCacheHits());
+ portlet.put("misses", cacheState.getCacheMisses());
+ portlet.put("evictions", cacheState.getEvictionCount());
+ caches.put("Portlets", portlet);
+
+ cacheState = cacheMonitor.snapshotStatistics(PORTLET_APPLICATION_NAME);
+ Map<String,Long> portletApp = new HashMap<>();
+ portletApp.put("hits", cacheState.getCacheHits());
+ portletApp.put("misses", cacheState.getCacheMisses());
+ portletApp.put("evictions", cacheState.getEvictionCount());
+ caches.put("PortletApps", portletApp);
+
+ CacheMonitorState fileState =
cacheMonitor.snapshotStatistics(PAGE_FILE);
+ Map<String,Long> pageFile = new HashMap<>();
+ if (fileState.getMemoryStoreSize() > 0) {
+ pageFile.put("hits", fileState.getCacheHits());
+ pageFile.put("misses", fileState.getCacheMisses());
+ pageFile.put("evictions", fileState.getEvictionCount());
+ caches.put("PSML-Files", pageFile);
+ }
+ else {
+ CacheMonitorState pathState =
cacheMonitor.snapshotStatistics(PAGE_MANAGER_PATH);
+ pageFile.put("hits", pathState.getCacheHits());
+ pageFile.put("misses", pathState.getCacheMisses());
+ pageFile.put("evictions", pathState.getEvictionCount());
+ caches.put("DBPSML", pageFile);
+ }
+
+ Map<String,Map<String,Map<String,Long>>> result;
+ result = new HashMap<>();
+ result.put("caches", caches);
+
return result;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]