Search in sources :

Example 1 with CounterMetricEntry

use of org.gluu.model.metric.counter.CounterMetricEntry in project oxCore by GluuFederation.

the class LdapEntryReporter method builCounterEntries.

private List<MetricEntry> builCounterEntries(SortedMap<String, Counter> counters, Set<MetricType> registeredMetricTypes) {
    List<MetricEntry> result = new ArrayList<MetricEntry>();
    Set<MetricType> currentRegisteredMetricTypes = new HashSet<MetricType>(registeredMetricTypes);
    for (MetricType metricType : currentRegisteredMetricTypes) {
        Counter counter = counters.get(metricType.getValue());
        if (counter != null) {
            long count = counter.getCount();
            // Remove to avoid writing not changed statistic
            // registeredMetricTypes.remove(metricType);
            CounterMetricData counterMetricData = new CounterMetricData(count);
            CounterMetricEntry counterMetricEntry = new CounterMetricEntry();
            counterMetricEntry.setMetricData(counterMetricData);
            counterMetricEntry.setMetricType(metricType);
            result.add(counterMetricEntry);
        }
    }
    return result;
}
Also used : MetricType(org.gluu.model.metric.MetricType) TimerMetricEntry(org.gluu.model.metric.timer.TimerMetricEntry) MetricEntry(org.gluu.model.metric.ldap.MetricEntry) CounterMetricEntry(org.gluu.model.metric.counter.CounterMetricEntry) CounterMetricEntry(org.gluu.model.metric.counter.CounterMetricEntry) CounterMetricData(org.gluu.model.metric.counter.CounterMetricData)

Example 2 with CounterMetricEntry

use of org.gluu.model.metric.counter.CounterMetricEntry in project oxTrust by GluuFederation.

the class MetricService method dump.

private void dump(List<CounterMetricEntry> metrics) {
    for (CounterMetricEntry metric : metrics) {
        Date date = metric.getCreationDate();
        long count = metric.getMetricData().getCount();
        System.out.println(date + " : " + count);
    }
}
Also used : CounterMetricEntry(org.gluu.model.metric.counter.CounterMetricEntry)

Example 3 with CounterMetricEntry

use of org.gluu.model.metric.counter.CounterMetricEntry in project oxTrust by GluuFederation.

the class MetricService method calculateCounterStatistics.

private Map<String, Long> calculateCounterStatistics(int countDays, List<CounterMetricEntry> metrics) {
    // Prepare map with all dates
    Map<String, Long> stats = new TreeMap<String, Long>();
    Calendar calendar = Calendar.getInstance();
    for (int i = 0; i <= countDays; i++) {
        stats.put(df.format(calendar.getTime()), 0L);
        calendar.add(Calendar.DATE, -1);
    }
    if ((metrics == null) || (metrics.size() == 0)) {
        return stats;
    }
    // Detect servers restart and readjust counts
    // Server restart condition: previous entry
    // CounterMetricEntry.CounterMetricEntry.count > current entry
    // CounterMetricEntry.CounterMetricEntry.count
    CounterMetricEntry prevMetric = null;
    long prevDayCount = 0L;
    long adjust = 0;
    for (CounterMetricEntry metric : metrics) {
        Date date = metric.getCreationDate();
        calendar.setTime(date);
        // Detect server restarts
        if ((prevMetric != null) && (prevMetric.getMetricData().getCount() > metric.getMetricData().getCount() + adjust)) {
            // Last count before server restart
            long count = prevMetric.getMetricData().getCount();
            // Change adjust value
            adjust = count;
        }
        long count = metric.getMetricData().getCount();
        metric.getMetricData().setCount(count + adjust);
        prevMetric = metric;
    }
    // Iterate through ordered by MetricEntry.startDate list and just make value
    // snapshot at the end of the day
    int prevDay = -1;
    prevMetric = null;
    prevDayCount = 0L;
    for (CounterMetricEntry metric : metrics) {
        Date date = metric.getCreationDate();
        calendar.setTime(date);
        int currDay = calendar.get(Calendar.DAY_OF_MONTH);
        if ((prevMetric != null) && (prevDay != currDay)) {
            long count = prevMetric.getMetricData().getCount();
            String dateString = df.format(prevMetric.getCreationDate());
            stats.put(dateString, count - prevDayCount);
            // Show only difference, not total
            prevDayCount = count;
        }
        prevMetric = metric;
        prevDay = currDay;
    }
    // Add last day statistic
    long count = prevMetric.getMetricData().getCount();
    String dateString = df.format(prevMetric.getCreationDate());
    stats.put(dateString, count - prevDayCount);
    return stats;
}
Also used : CounterMetricEntry(org.gluu.model.metric.counter.CounterMetricEntry)

Example 4 with CounterMetricEntry

use of org.gluu.model.metric.counter.CounterMetricEntry 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

CounterMetricEntry (org.gluu.model.metric.counter.CounterMetricEntry)4 MetricType (org.gluu.model.metric.MetricType)2 MetricEntry (org.gluu.model.metric.ldap.MetricEntry)2 CounterMetricData (org.gluu.model.metric.counter.CounterMetricData)1 TimerMetricEntry (org.gluu.model.metric.timer.TimerMetricEntry)1 AuthenticationChartDto (org.gluu.oxtrust.model.AuthenticationChartDto)1