Search in sources :

Example 1 with CounterMetricEntry

use of org.xdi.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 : Counter(com.codahale.metrics.Counter) MetricType(org.xdi.model.metric.MetricType) ArrayList(java.util.ArrayList) CounterMetricEntry(org.xdi.model.metric.counter.CounterMetricEntry) TimerMetricEntry(org.xdi.model.metric.timer.TimerMetricEntry) MetricEntry(org.xdi.model.metric.ldap.MetricEntry) CounterMetricEntry(org.xdi.model.metric.counter.CounterMetricEntry) CounterMetricData(org.xdi.model.metric.counter.CounterMetricData) HashSet(java.util.HashSet)

Example 2 with CounterMetricEntry

use of org.xdi.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.xdi.model.metric.counter.CounterMetricEntry) Date(java.util.Date)

Example 3 with CounterMetricEntry

use of org.xdi.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(-countDays);
    String[] labels = new String[countDays];
    Map<String, Long> successStats = calculateCounterStatistics(countDays, (List<CounterMetricEntry>) entries.get(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS));
    labels = successStats.keySet().toArray(labels);
    Long[] values = new Long[countDays];
    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];
    values = failureStats.values().toArray(values);
    authenticationChartDto.setFailure(values);
    cacheService.put(OxTrustConstants.CACHE_METRICS_NAME, key, authenticationChartDto);
    return authenticationChartDto;
}
Also used : AuthenticationChartDto(org.gluu.oxtrust.model.AuthenticationChartDto) MetricType(org.xdi.model.metric.MetricType) ArrayList(java.util.ArrayList) List(java.util.List) CounterMetricEntry(org.xdi.model.metric.counter.CounterMetricEntry) MetricEntry(org.xdi.model.metric.ldap.MetricEntry) CounterMetricEntry(org.xdi.model.metric.counter.CounterMetricEntry)

Example 4 with CounterMetricEntry

use of org.xdi.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++) {
        String dateString = df.format(calendar.getTime());
        stats.put(dateString, 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 : Calendar(java.util.Calendar) CounterMetricEntry(org.xdi.model.metric.counter.CounterMetricEntry) TreeMap(java.util.TreeMap) Date(java.util.Date)

Aggregations

CounterMetricEntry (org.xdi.model.metric.counter.CounterMetricEntry)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 MetricType (org.xdi.model.metric.MetricType)2 MetricEntry (org.xdi.model.metric.ldap.MetricEntry)2 Counter (com.codahale.metrics.Counter)1 Calendar (java.util.Calendar)1 HashSet (java.util.HashSet)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 AuthenticationChartDto (org.gluu.oxtrust.model.AuthenticationChartDto)1 CounterMetricData (org.xdi.model.metric.counter.CounterMetricData)1 TimerMetricEntry (org.xdi.model.metric.timer.TimerMetricEntry)1