Search in sources :

Example 1 with AuthenticationChartDto

use of org.gluu.oxtrust.model.AuthenticationChartDto in project oxTrust by GluuFederation.

the class MetricService method genereateAuthenticationChartDto.

public AuthenticationChartDto genereateAuthenticationChartDto(int countDays) {
    String key = OxTrustConstants.CACHE_METRICS_KEY + "#home";
    AuthenticationChartDto authenticationChartDto = (AuthenticationChartDto) cacheService.get(OxTrustConstants.CACHE_METRICS_NAME, key);
    if (authenticationChartDto != null) {
        return authenticationChartDto;
    }
    Map<MetricType, List<? extends MetricEntry>> entries = findAuthenticationMetrics(ApplicationType.OX_AUTH, -countDays);
    Map<MetricType, List<? extends MetricEntry>> yearlyEntris = findAuthenticationMetrics(ApplicationType.OX_AUTH, -YEARLY);
    Map<String, Long> yearlySuccessStats = calculateCounterStatistics(YEARLY, (List<CounterMetricEntry>) yearlyEntris.get(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS));
    Long yearlySuccessfullRequest = yearlySuccessStats.values().stream().mapToLong(Long::valueOf).sum();
    Map<String, Long> yearlyFailureStats = calculateCounterStatistics(YEARLY, (List<CounterMetricEntry>) yearlyEntris.get(MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES));
    Long yearlyFailsRequest = yearlyFailureStats.values().stream().mapToLong(Long::valueOf).sum();
    String[] labels = new String[countDays + 1];
    Long[] values = new Long[countDays + 1];
    Map<String, Long> successStats = calculateCounterStatistics(countDays, (List<CounterMetricEntry>) entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS));
    labels = successStats.keySet().toArray(labels);
    values = successStats.values().toArray(values);
    authenticationChartDto = new AuthenticationChartDto();
    authenticationChartDto.setLabels(labels);
    authenticationChartDto.setSuccess(values);
    Map<String, Long> failureStats = calculateCounterStatistics(countDays, (List<CounterMetricEntry>) entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES));
    values = new Long[countDays];
    authenticationChartDto.setFailure(failureStats.values().toArray(values));
    authenticationChartDto.setYearlyRequest(yearlySuccessfullRequest + yearlyFailsRequest);
    cacheService.put(key, authenticationChartDto);
    return authenticationChartDto;
}
Also used : AuthenticationChartDto(org.gluu.oxtrust.model.AuthenticationChartDto) MetricType(org.gluu.model.metric.MetricType) CounterMetricEntry(org.gluu.model.metric.counter.CounterMetricEntry) MetricEntry(org.gluu.model.metric.ldap.MetricEntry) CounterMetricEntry(org.gluu.model.metric.counter.CounterMetricEntry)

Aggregations

MetricType (org.gluu.model.metric.MetricType)1 CounterMetricEntry (org.gluu.model.metric.counter.CounterMetricEntry)1 MetricEntry (org.gluu.model.metric.ldap.MetricEntry)1 AuthenticationChartDto (org.gluu.oxtrust.model.AuthenticationChartDto)1