Search in sources :

Example 1 with MetricType

use of org.xdi.model.metric.MetricType 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 MetricType

use of org.xdi.model.metric.MetricType in project oxAuth by GluuFederation.

the class AuthenticationService method authenticate.

public boolean authenticate(String keyValue, String password, String primaryKey, String localPrimaryKey) {
    if (this.ldapAuthConfigs == null) {
        return authenticate(null, ldapEntryManager, keyValue, password, primaryKey, localPrimaryKey);
    }
    boolean authenticated = false;
    com.codahale.metrics.Timer.Context timerContext = metricService.getTimer(MetricType.OXAUTH_USER_AUTHENTICATION_RATE).time();
    try {
        for (int i = 0; i < this.ldapAuthConfigs.size(); i++) {
            GluuLdapConfiguration ldapAuthConfig = this.ldapAuthConfigs.get(i);
            LdapEntryManager ldapAuthEntryManager = this.ldapAuthEntryManagers.get(i);
            authenticated = authenticate(ldapAuthConfig, ldapAuthEntryManager, keyValue, password, primaryKey, localPrimaryKey);
            if (authenticated) {
                break;
            }
        }
    } finally {
        timerContext.stop();
    }
    MetricType metricType;
    if (authenticated) {
        metricType = MetricType.OXAUTH_USER_AUTHENTICATION_SUCCESS;
    } else {
        metricType = MetricType.OXAUTH_USER_AUTHENTICATION_FAILURES;
    }
    metricService.incCounter(metricType);
    return authenticated;
}
Also used : LdapEntryManager(org.gluu.site.ldap.persistence.LdapEntryManager) MetricType(org.xdi.model.metric.MetricType) GluuLdapConfiguration(org.xdi.model.ldap.GluuLdapConfiguration)

Example 3 with MetricType

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

the class MetricService method initTimer.

public void initTimer(int metricInterval) {
    this.metricRegistry = new MetricRegistry();
    this.registeredMetricTypes = new HashSet<MetricType>();
    LdapEntryReporter ldapEntryReporter = LdapEntryReporter.forRegistry(this.metricRegistry, getMetricServiceInstance()).build();
    int metricReporterInterval = metricInterval;
    if (metricReporterInterval <= 0) {
        metricReporterInterval = DEFAULT_METRIC_REPORTER_INTERVAL;
    }
    ldapEntryReporter.start(metricReporterInterval, TimeUnit.SECONDS);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) MetricType(org.xdi.model.metric.MetricType)

Example 4 with MetricType

use of org.xdi.model.metric.MetricType 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 5 with MetricType

use of org.xdi.model.metric.MetricType 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

MetricType (org.xdi.model.metric.MetricType)7 ArrayList (java.util.ArrayList)5 MetricEntry (org.xdi.model.metric.ldap.MetricEntry)5 CounterMetricEntry (org.xdi.model.metric.counter.CounterMetricEntry)4 List (java.util.List)3 TimerMetricEntry (org.xdi.model.metric.timer.TimerMetricEntry)2 Counter (com.codahale.metrics.Counter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Snapshot (com.codahale.metrics.Snapshot)1 Timer (com.codahale.metrics.Timer)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 AuthenticationChartDto (org.gluu.oxtrust.model.AuthenticationChartDto)1 Filter (org.gluu.search.filter.Filter)1 LdapEntryManager (org.gluu.site.ldap.persistence.LdapEntryManager)1 GluuLdapConfiguration (org.xdi.model.ldap.GluuLdapConfiguration)1 CounterMetricData (org.xdi.model.metric.counter.CounterMetricData)1