001package com.nimbusds.common.ldap; 002 003 004import java.util.HashMap; 005import java.util.Map; 006 007import com.codahale.metrics.Gauge; 008import com.codahale.metrics.Metric; 009import com.codahale.metrics.MetricSet; 010 011import com.unboundid.ldap.sdk.LDAPConnectionPool; 012 013 014/** 015 * LDAP connection metrics. 016 */ 017public class LDAPConnectionPoolMetrics implements MetricSet { 018 019 020 /** 021 * The metrics map. 022 */ 023 private final Map<String,Metric> metricMap = new HashMap<>(); 024 025 026 /** 027 * Creates a new LDAP connection metrics. 028 * 029 * @param pool The LDAP connection pool. Must not be {@code null}. 030 * @param prefix The metrics name prefix. Must not be {@code null}. 031 */ 032 public LDAPConnectionPoolMetrics(final LDAPConnectionPool pool, 033 final String prefix) { 034 035 metricMap.put(prefix + ".maxAvailableConnections", (Gauge<Integer>) () -> pool.getConnectionPoolStatistics().getMaximumAvailableConnections()); 036 037 metricMap.put(prefix + ".numAvailableConnections", (Gauge<Integer>) () -> pool.getConnectionPoolStatistics().getNumAvailableConnections()); 038 039 metricMap.put(prefix + ".numConnectionsClosedDefunct", (Gauge<Long>) () -> pool.getConnectionPoolStatistics().getNumConnectionsClosedDefunct()); 040 041 metricMap.put(prefix + ".numConnectionsClosedExpired", (Gauge<Long>) () -> pool.getConnectionPoolStatistics().getNumConnectionsClosedExpired()); 042 043 metricMap.put(prefix + ".numConnectionsClosedUnneeded", (Gauge<Long>) () -> pool.getConnectionPoolStatistics().getNumConnectionsClosedUnneeded()); 044 045 metricMap.put(prefix + ".numFailedCheckouts", (Gauge<Long>) () -> pool.getConnectionPoolStatistics().getNumFailedCheckouts()); 046 047 metricMap.put(prefix + ".numFailedConnectionAttempts", (Gauge<Long>) () -> pool.getConnectionPoolStatistics().getNumFailedConnectionAttempts()); 048 049 metricMap.put(prefix + ".numReleasedValid", (Gauge<Long>) () -> pool.getConnectionPoolStatistics().getNumReleasedValid()); 050 051 metricMap.put(prefix + ".numSuccessfulCheckouts", (Gauge<Long>) () -> pool.getConnectionPoolStatistics().getNumSuccessfulCheckouts()); 052 053 metricMap.put(prefix + ".numSuccessfulCheckoutsNewConnection", (Gauge<Long>) () -> pool.getConnectionPoolStatistics().getNumSuccessfulCheckoutsNewConnection()); 054 055 metricMap.put(prefix + ".numSuccessfulCheckoutsWithoutWaiting", (Gauge<Long>) () -> pool.getConnectionPoolStatistics().getNumSuccessfulCheckoutsWithoutWaiting()); 056 057 metricMap.put(prefix + ".numSuccessfulCheckoutsAfterWaiting", (Gauge<Long>) () -> pool.getConnectionPoolStatistics().getNumSuccessfulCheckoutsAfterWaiting()); 058 059 metricMap.put(prefix + ".numSuccessfulConnectionAttempts", (Gauge<Long>) () -> pool.getConnectionPoolStatistics().getNumSuccessfulConnectionAttempts()); 060 } 061 062 063 @Override 064 public Map<String,Metric> getMetrics() { 065 066 return metricMap; 067 } 068}