Search in sources :

Example 1 with MetricEntry

use of org.xdi.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 : 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 MetricEntry

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

the class LdapEntryReporter method addMandatoryAttributes.

private void addMandatoryAttributes(MetricService metricService, Date startTime, Date endTime, List<MetricEntry> metricEntries, Date creationTime) {
    for (MetricEntry metricEntry : metricEntries) {
        String id = metricService.getuUiqueIdentifier();
        String dn = metricService.buildDn(id, creationTime, ApplicationType.OX_AUTH);
        metricEntry.setId(id);
        metricEntry.setDn(dn);
        metricEntry.setApplicationType(ApplicationType.OX_AUTH);
        metricEntry.setStartDate(startTime);
        metricEntry.setEndDate(endTime);
        metricEntry.setCreationDate(creationTime);
    }
}
Also used : CounterMetricEntry(org.xdi.model.metric.counter.CounterMetricEntry) TimerMetricEntry(org.xdi.model.metric.timer.TimerMetricEntry) MetricEntry(org.xdi.model.metric.ldap.MetricEntry)

Example 3 with MetricEntry

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

the class LdapEntryReporter method reportImpl.

private void reportImpl(SortedMap<String, Counter> counters, SortedMap<String, Timer> timers) {
    final Date currentRunTime = new Date(clock.getTime());
    List<MetricEntry> metricEntries = new ArrayList<MetricEntry>();
    if (counters != null && !counters.isEmpty()) {
        List<MetricEntry> result = builCounterEntries(counters, metricService.getRegisteredMetricTypes());
        metricEntries.addAll(result);
    }
    if (timers != null && !timers.isEmpty()) {
        List<MetricEntry> result = builTimerEntries(timers, metricService.getRegisteredMetricTypes());
        metricEntries.addAll(result);
    }
    // Remove 1 millisecond to avoid overlapping periods 
    final Calendar cal = Calendar.getInstance();
    cal.setTime(currentRunTime);
    cal.add(Calendar.MILLISECOND, -1);
    final Date endTime = cal.getTime();
    Date creationTime = new Date();
    if (metricEntries.size() > 0) {
        addMandatoryAttributes(metricService, startTime, endTime, metricEntries, creationTime);
    }
    startTime = currentRunTime;
    metricService.add(metricEntries, creationTime);
}
Also used : Calendar(java.util.Calendar) 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) Date(java.util.Date)

Example 4 with MetricEntry

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

the class MetricService method getExpiredMetricEntries.

public List<MetricEntry> getExpiredMetricEntries(BatchOperation<MetricEntry> batchOperation, int batchSize, String baseDnForPeriod, Date expirationDate) {
    Filter expiratioFilter = Filter.createLessOrEqualFilter("oxStartDate", ldapEntryManager.encodeGeneralizedTime(expirationDate));
    List<MetricEntry> metricEntries = ldapEntryManager.findEntries(baseDnForPeriod, MetricEntry.class, expiratioFilter, SearchScope.SUB, new String[] { "uniqueIdentifier" }, batchOperation, 0, batchSize, batchSize);
    return metricEntries;
}
Also used : Filter(com.unboundid.ldap.sdk.Filter) MetricEntry(org.xdi.model.metric.ldap.MetricEntry)

Example 5 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)

Aggregations

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