Search in sources :

Example 1 with MetricEntry

use of org.gluu.model.metric.ldap.MetricEntry 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 MetricEntry

use of org.gluu.model.metric.ldap.MetricEntry in project oxCore by GluuFederation.

the class MetricService method findMetricEntry.

public Map<MetricType, List<? extends MetricEntry>> findMetricEntry(ApplicationType applicationType, List<MetricType> metricTypes, Date startDate, Date endDate, String... returnAttributes) {
    prepareBranch(null, applicationType);
    Map<MetricType, List<? extends MetricEntry>> result = new HashMap<MetricType, List<? extends MetricEntry>>();
    if ((metricTypes == null) || (metricTypes.size() == 0)) {
        return result;
    }
    // Prepare list of DNs
    Set<String> metricDns = getBaseDnForPeriod(applicationType, startDate, endDate);
    if (metricDns.size() == 0) {
        return result;
    }
    for (MetricType metricType : metricTypes) {
        List<MetricEntry> metricTypeResult = new LinkedList<MetricEntry>();
        for (String metricDn : metricDns) {
            List<Filter> metricTypeFilters = new ArrayList<Filter>();
            Filter applicationTypeFilter = Filter.createEqualityFilter("oxApplicationType", applicationType.getValue());
            Filter eventTypeTypeFilter = Filter.createEqualityFilter("oxMetricType", metricType.getValue());
            Filter startDateFilter = Filter.createGreaterOrEqualFilter("oxStartDate", getEntryManager().encodeTime(metricDn, (startDate)));
            Filter endDateFilter = Filter.createLessOrEqualFilter("oxEndDate", getEntryManager().encodeTime(metricDn, endDate));
            metricTypeFilters.add(applicationTypeFilter);
            metricTypeFilters.add(eventTypeTypeFilter);
            metricTypeFilters.add(startDateFilter);
            metricTypeFilters.add(endDateFilter);
            Filter filter = Filter.createANDFilter(metricTypeFilters);
            List<? extends MetricEntry> metricTypeMonthResult = (List<? extends MetricEntry>) getEntryManager().findEntries(metricDn, metricType.getMetricEntryType(), filter, returnAttributes);
            metricTypeResult.addAll(metricTypeMonthResult);
        }
        // Sort entries to avoid calculation errors
        getEntryManager().sortListByProperties(MetricEntry.class, metricTypeResult, false, "creationDate");
        result.put(metricType, metricTypeResult);
    }
    return result;
}
Also used : MetricType(org.gluu.model.metric.MetricType) MetricEntry(org.gluu.model.metric.ldap.MetricEntry) Filter(org.gluu.search.filter.Filter)

Example 3 with MetricEntry

use of org.gluu.model.metric.ldap.MetricEntry in project oxCore by GluuFederation.

the class MetricService method removeExpiredMetricEntries.

public void removeExpiredMetricEntries(final Date expirationDate, final ApplicationType applicationType, int count, int chunkSize) {
    createApplicationBaseBranch(applicationType);
    final Set<String> keepBaseDnForPeriod = getBaseDnForPeriod(applicationType, expirationDate, new Date());
    // Remove expired entries
    for (final String baseDnForPeriod : keepBaseDnForPeriod) {
        DefaultBatchOperation<MetricEntry> metricEntryBatchOperation = new DefaultBatchOperation<MetricEntry>() {

            @Override
            public boolean collectSearchResult(int size) {
                return false;
            }

            @Override
            public void performAction(List<MetricEntry> entries) {
                for (MetricEntry metricEntry : entries) {
                    remove(metricEntry);
                }
            }
        };
        getExpiredMetricEntries(metricEntryBatchOperation, applicationType, baseDnForPeriod, expirationDate, count, chunkSize);
    }
    if (!getEntryManager().hasBranchesSupport(buildDn(null, null, applicationType))) {
        DefaultBatchOperation<SimpleBranch> batchOperation = new DefaultBatchOperation<SimpleBranch>() {

            @Override
            public boolean collectSearchResult(int size) {
                return false;
            }

            @Override
            public void performAction(List<SimpleBranch> objects) {
                String baseDn = buildDn(null, null, applicationType);
                Set<String> periodBranchesStrings = new HashSet<String>();
                for (SimpleBranch periodBranch : objects) {
                    if (!StringHelper.equalsIgnoreCase(baseDn, periodBranch.getDn())) {
                        periodBranchesStrings.add(periodBranch.getDn());
                    }
                }
                periodBranchesStrings.removeAll(keepBaseDnForPeriod);
                // Remove expired months
                for (String baseDnForPeriod : periodBranchesStrings) {
                    removeBranch(baseDnForPeriod);
                }
            }
        };
        findAllPeriodBranches(batchOperation, applicationType, count, chunkSize);
    }
}
Also used : SimpleBranch(org.gluu.persist.model.base.SimpleBranch) MetricEntry(org.gluu.model.metric.ldap.MetricEntry) DefaultBatchOperation(org.gluu.persist.model.DefaultBatchOperation)

Example 4 with MetricEntry

use of org.gluu.model.metric.ldap.MetricEntry 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)

Example 5 with MetricEntry

use of org.gluu.model.metric.ldap.MetricEntry in project oxCore by GluuFederation.

the class LdapEntryReporter method builTimerEntries.

private List<MetricEntry> builTimerEntries(SortedMap<String, Timer> timers, Set<MetricType> registeredMetricTypes) {
    List<MetricEntry> result = new ArrayList<MetricEntry>();
    for (MetricType metricType : registeredMetricTypes) {
        Timer timer = timers.get(metricType.getValue());
        if (timer != null) {
            Snapshot snapshot = timer.getSnapshot();
            TimerMetricData timerMetricData = new TimerMetricData(timer.getCount(), convertRate(timer.getMeanRate()), convertRate(timer.getOneMinuteRate()), convertRate(timer.getFiveMinuteRate()), convertRate(timer.getFifteenMinuteRate()), getRateUnit(), convertDuration(snapshot.getMin()), convertDuration(snapshot.getMax()), convertDuration(snapshot.getMean()), convertDuration(snapshot.getStdDev()), convertDuration(snapshot.getMedian()), convertDuration(snapshot.get75thPercentile()), convertDuration(snapshot.get95thPercentile()), convertDuration(snapshot.get98thPercentile()), convertDuration(snapshot.get99thPercentile()), convertDuration(snapshot.get999thPercentile()), getDurationUnit());
            TimerMetricEntry timerMetricEntry = new TimerMetricEntry();
            timerMetricEntry.setMetricData(timerMetricData);
            timerMetricEntry.setMetricType(metricType);
            result.add(timerMetricEntry);
        }
    }
    return result;
}
Also used : Timer(com.codahale.metrics.Timer) 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) TimerMetricData(org.gluu.model.metric.timer.TimerMetricData) TimerMetricEntry(org.gluu.model.metric.timer.TimerMetricEntry)

Aggregations

MetricEntry (org.gluu.model.metric.ldap.MetricEntry)7 MetricType (org.gluu.model.metric.MetricType)4 CounterMetricEntry (org.gluu.model.metric.counter.CounterMetricEntry)4 TimerMetricEntry (org.gluu.model.metric.timer.TimerMetricEntry)3 Filter (org.gluu.search.filter.Filter)2 Timer (com.codahale.metrics.Timer)1 ApplicationType (org.gluu.model.ApplicationType)1 CounterMetricData (org.gluu.model.metric.counter.CounterMetricData)1 TimerMetricData (org.gluu.model.metric.timer.TimerMetricData)1 AuthenticationChartDto (org.gluu.oxtrust.model.AuthenticationChartDto)1 DefaultBatchOperation (org.gluu.persist.model.DefaultBatchOperation)1 SimpleBranch (org.gluu.persist.model.base.SimpleBranch)1