Search in sources :

Example 1 with MetricEntry

use of io.jans.model.metric.ldap.MetricEntry in project jans by JanssenProject.

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(io.jans.orm.model.base.SimpleBranch) MetricEntry(io.jans.model.metric.ldap.MetricEntry) DefaultBatchOperation(io.jans.orm.model.DefaultBatchOperation)

Example 2 with MetricEntry

use of io.jans.model.metric.ldap.MetricEntry in project jans by JanssenProject.

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("jansAppTyp", applicationType.getValue());
            Filter eventTypeTypeFilter = Filter.createEqualityFilter("jansMetricTyp", metricType.getValue());
            Filter startDateFilter = Filter.createGreaterOrEqualFilter("jansStartDate", getEntryManager().encodeTime(metricDn, (startDate)));
            Filter endDateFilter = Filter.createLessOrEqualFilter("jansEndDate", 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(io.jans.model.metric.MetricType) MetricEntry(io.jans.model.metric.ldap.MetricEntry) Filter(io.jans.orm.search.filter.Filter)

Example 3 with MetricEntry

use of io.jans.model.metric.ldap.MetricEntry in project jans by JanssenProject.

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(io.jans.model.metric.MetricType) CounterMetricEntry(io.jans.model.metric.counter.CounterMetricEntry) TimerMetricEntry(io.jans.model.metric.timer.TimerMetricEntry) MetricEntry(io.jans.model.metric.ldap.MetricEntry) TimerMetricData(io.jans.model.metric.timer.TimerMetricData) TimerMetricEntry(io.jans.model.metric.timer.TimerMetricEntry)

Example 4 with MetricEntry

use of io.jans.model.metric.ldap.MetricEntry in project jans by JanssenProject.

the class LdapEntryReporter method addMandatoryAttributes.

private void addMandatoryAttributes(MetricService metricService, Date startTime, Date endTime, List<MetricEntry> metricEntries, Date creationTime) {
    String nodeIndetifier = metricService.getNodeIndetifier();
    ApplicationType applicationType = metricService.getApplicationType();
    for (MetricEntry metricEntry : metricEntries) {
        String id = metricService.getUiqueIdentifier();
        String dn = metricService.buildDn(id, creationTime, applicationType);
        metricEntry.setId(id);
        metricEntry.setDn(dn);
        metricEntry.setApplicationType(applicationType);
        metricEntry.setNodeIndetifier(nodeIndetifier);
        metricEntry.setStartDate(startTime);
        metricEntry.setEndDate(endTime);
        metricEntry.setCreationDate(creationTime);
        metricEntry.setExpirationDate(DateUtils.addDays(creationTime, metricService.getEntryLifetimeInDays()));
        int ttl = (int) ((metricEntry.getExpirationDate().getTime() - creationTime.getTime()) / 1000L);
        metricEntry.setTtl(ttl);
    }
}
Also used : ApplicationType(io.jans.model.ApplicationType) CounterMetricEntry(io.jans.model.metric.counter.CounterMetricEntry) TimerMetricEntry(io.jans.model.metric.timer.TimerMetricEntry) MetricEntry(io.jans.model.metric.ldap.MetricEntry)

Example 5 with MetricEntry

use of io.jans.model.metric.ldap.MetricEntry in project jans by JanssenProject.

the class MetricService method getExpiredMetricEntries.

public List<MetricEntry> getExpiredMetricEntries(DefaultBatchOperation<MetricEntry> batchOperation, ApplicationType applicationType, String baseDnForPeriod, Date expirationDate, int count, int chunkSize) {
    Filter expiratioStartDateFilter = Filter.createLessOrEqualFilter("oxStartDate", getEntryManager().encodeTime(baseDnForPeriod, expirationDate));
    Filter expiratioFilter = expiratioStartDateFilter;
    if (applicationType != null) {
        Filter applicationTypeFilter = Filter.createEqualityFilter("oxMetricType", applicationType.getValue());
        expiratioFilter = Filter.createANDFilter(expiratioStartDateFilter, applicationTypeFilter);
    }
    List<MetricEntry> metricEntries = getEntryManager().findEntries(baseDnForPeriod, MetricEntry.class, expiratioFilter, SearchScope.SUB, new String[] { "uniqueIdentifier" }, batchOperation, 0, count, chunkSize);
    return metricEntries;
}
Also used : Filter(io.jans.orm.search.filter.Filter) MetricEntry(io.jans.model.metric.ldap.MetricEntry)

Aggregations

MetricEntry (io.jans.model.metric.ldap.MetricEntry)6 MetricType (io.jans.model.metric.MetricType)3 CounterMetricEntry (io.jans.model.metric.counter.CounterMetricEntry)3 TimerMetricEntry (io.jans.model.metric.timer.TimerMetricEntry)3 Filter (io.jans.orm.search.filter.Filter)2 Timer (com.codahale.metrics.Timer)1 ApplicationType (io.jans.model.ApplicationType)1 CounterMetricData (io.jans.model.metric.counter.CounterMetricData)1 TimerMetricData (io.jans.model.metric.timer.TimerMetricData)1 DefaultBatchOperation (io.jans.orm.model.DefaultBatchOperation)1 SimpleBranch (io.jans.orm.model.base.SimpleBranch)1