Skip to content

Commit

Permalink
cache metrics 112
Browse files Browse the repository at this point in the history
  • Loading branch information
rahatjaan committed Sep 14, 2015
1 parent f774cb2 commit 867935e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 13 additions & 3 deletions server/src/main/java/org/gluu/oxtrust/service/MetricService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.gluu.oxtrust.ldap.service.ApplianceService;
import org.gluu.oxtrust.ldap.service.OrganizationService;
import org.gluu.oxtrust.model.AuthenticationChartDto;
import org.gluu.oxtrust.model.GluuOrganization;
import org.gluu.oxtrust.util.OxTrustConstants;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
Expand All @@ -29,6 +31,7 @@
import org.xdi.model.ApplicationType;
import org.xdi.model.metric.MetricType;
import org.xdi.model.metric.ldap.MetricEntry;
import org.xdi.service.CacheService;

/**
* Store and retrieve metric
Expand All @@ -48,7 +51,10 @@ public class MetricService extends org.xdi.service.metric.MetricService {

@Logger
private Log log;


@In
private CacheService cacheService;

@In
private ApplianceService applianceService;

Expand All @@ -60,8 +66,12 @@ public class MetricService extends org.xdi.service.metric.MetricService {

public AuthenticationChartDto genereateAuthenticationChartDto(int countDays) {
AuthenticationChartDto authenticationChartDto = new AuthenticationChartDto();

Map<MetricType, List<MetricEntry>> entries = findAuthenticationMetrics(-countDays);
String key = OxTrustConstants.CACHE_METRICS_KEY;
Map<MetricType, List<MetricEntry>> entries = (Map<MetricType, List<MetricEntry>>) cacheService.get(OxTrustConstants.CACHE_METRICS_NAME, key);
if (entries== null) {
entries = findAuthenticationMetrics(-countDays);
cacheService.put(OxTrustConstants.CACHE_METRICS_NAME, key, entries);
}

String []labels = new String[countDays];
Map<String, Integer> successStats = calculateStatistics(countDays, entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS));
Expand Down
7 changes: 7 additions & 0 deletions server/src/main/resources/ehcache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,11 @@
timeToLiveSeconds="60"
memoryStoreEvictionPolicy="LRU"/>

<cache name="metricsCache"
maxElementsInMemory="1000"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="60"
timeToLiveSeconds="14400"
memoryStoreEvictionPolicy="LRU"/>
</ehcache>

0 comments on commit 867935e

Please sign in to comment.