Search in sources :

Example 6 with MetricEntry

use of org.xdi.model.metric.ldap.MetricEntry in project oxTrust by GluuFederation.

the class MetricService method findAuthenticationMetrics.

private Map<MetricType, List<? extends MetricEntry>> findAuthenticationMetrics(int countDays) {
    List<MetricType> metricTypes = new ArrayList<MetricType>();
    metricTypes.add(MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES);
    metricTypes.add(MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS);
    Date endDate = new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, countDays);
    Date startDate = calendar.getTime();
    Map<MetricType, List<? extends MetricEntry>> entries = findMetricEntry(ApplicationType.OX_AUTH, appConfiguration.getApplianceInum(), metricTypes, startDate, endDate);
    return entries;
}
Also used : MetricType(org.xdi.model.metric.MetricType) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CounterMetricEntry(org.xdi.model.metric.counter.CounterMetricEntry) MetricEntry(org.xdi.model.metric.ldap.MetricEntry) Date(java.util.Date)

Example 7 with MetricEntry

use of org.xdi.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 : Snapshot(com.codahale.metrics.Snapshot) Timer(com.codahale.metrics.Timer) 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) TimerMetricData(org.xdi.model.metric.timer.TimerMetricData) TimerMetricEntry(org.xdi.model.metric.timer.TimerMetricEntry)

Example 8 with MetricEntry

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

the class MetricService method removeExpiredMetricEntries.

public void removeExpiredMetricEntries(int batchSize, final Date expirationDate, final ApplicationType applicationType, final String applianceInum) {
    final Set<String> keepBaseDnForPeriod = getBaseDnForPeriod(applicationType, applianceInum, expirationDate, new Date());
    // Remove expired entries
    for (final String baseDnForPeriod : keepBaseDnForPeriod) {
        BatchOperation<MetricEntry> metricEntryBatchOperation = new BatchOperation<MetricEntry>(ldapEntryManager) {

            @Override
            protected List<MetricEntry> getChunkOrNull(int batchSize) {
                return getExpiredMetricEntries(this, batchSize, baseDnForPeriod, expirationDate);
            }

            @Override
            protected void performAction(List<MetricEntry> objects) {
                for (MetricEntry metricEntry : objects) {
                    remove(metricEntry);
                }
            }
        };
        metricEntryBatchOperation.iterateAllByChunks(batchSize);
    }
    BatchOperation<SimpleBranch> batchOperation = new BatchOperation<SimpleBranch>(ldapEntryManager) {

        @Override
        protected List<SimpleBranch> getChunkOrNull(int batchSize) {
            return findAllPeriodBranches(this, batchSize, applicationType, applianceInum);
        }

        @Override
        protected void performAction(List<SimpleBranch> objects) {
            String baseDn = buildDn(null, null, applicationType, applianceInum);
            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);
            }
        }
    };
    batchOperation.iterateAllByChunks(batchSize);
}
Also used : SimpleBranch(org.xdi.ldap.model.SimpleBranch) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) BatchOperation(org.gluu.site.ldap.persistence.BatchOperation) MetricEntry(org.xdi.model.metric.ldap.MetricEntry) Date(java.util.Date) HashSet(java.util.HashSet)

Example 9 with MetricEntry

use of org.xdi.model.metric.ldap.MetricEntry in project oxTrust by GluuFederation.

the class MetricService method genereateAuthenticationChartDto.

public AuthenticationChartDto genereateAuthenticationChartDto(int countDays) {
    String key = OxConstants.CACHE_METRICS_KEY + "#home";
    AuthenticationChartDto authenticationChartDto = (AuthenticationChartDto) cacheService.get(OxConstants.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(OxConstants.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 10 with MetricEntry

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

the class MetricService method removeExpiredMetricEntries.

public void removeExpiredMetricEntries(final Date expirationDate, final ApplicationType applicationType, final String applianceInum, int sizeLimit, int chunkSize) {
    final Set<String> keepBaseDnForPeriod = getBaseDnForPeriod(applicationType, applianceInum, 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, baseDnForPeriod, expirationDate, sizeLimit, chunkSize);
    }
    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, applianceInum);
            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, applianceInum, sizeLimit, chunkSize);
}
Also used : SimpleBranch(org.gluu.persist.model.base.SimpleBranch) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MetricEntry(org.xdi.model.metric.ldap.MetricEntry) DefaultBatchOperation(org.gluu.persist.model.DefaultBatchOperation) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

MetricEntry (org.xdi.model.metric.ldap.MetricEntry)11 ArrayList (java.util.ArrayList)8 CounterMetricEntry (org.xdi.model.metric.counter.CounterMetricEntry)6 List (java.util.List)5 MetricType (org.xdi.model.metric.MetricType)5 Date (java.util.Date)4 TimerMetricEntry (org.xdi.model.metric.timer.TimerMetricEntry)4 HashSet (java.util.HashSet)3 LinkedList (java.util.LinkedList)3 Calendar (java.util.Calendar)2 Filter (org.gluu.search.filter.Filter)2 Counter (com.codahale.metrics.Counter)1 Snapshot (com.codahale.metrics.Snapshot)1 Timer (com.codahale.metrics.Timer)1 Filter (com.unboundid.ldap.sdk.Filter)1 HashMap (java.util.HashMap)1 AuthenticationChartDto (org.gluu.oxtrust.model.AuthenticationChartDto)1 DefaultBatchOperation (org.gluu.persist.model.DefaultBatchOperation)1 SimpleBranch (org.gluu.persist.model.base.SimpleBranch)1 BatchOperation (org.gluu.site.ldap.persistence.BatchOperation)1