There is no way to get Lettuce Redis Connection pool metrics
We wanted to get metrics from the Lettuce Redis connection pool. But I don't see any meter binder for redis connection pools unlike JDBC Datasource. Is there any other way we can get the metrics from the Redis Connection pools?
In case of enabling the JMX, there is no way to set the JMX base name and prefixes on the commons-pool2. Can anyone help on this?
LettucePoolingConnectionProvider manages multiple connection pools for various purposes and there's no hook to customize individual pool instances. We're currently working to introduce better observability means to our Spring Data modules so I'm labeling this ticket as observability enhancement.
Is there any progress on this is issue?
This ticket requires further investigation. Maybe one or more pool customizer functions in the client configuration would be useful so you can capture the pools as side-effect of such a function.
@veera-chenna We used reflection to capture Pool Metrics. Please find sample code below -
@Component
@Slf4j
public class RedisMetrics {
private Map<Class<?>, GenericObjectPool<StatefulConnection<?, ?>>> pools;
public RedisMetrics(@Qualifier("lettuceClusterConnectionFactory") LettuceConnectionFactory factory) throws IllegalAccessException {
LettuceConnectionProvider lettuceConnectionProvider = (LettuceConnectionProvider) FieldUtils.readField(factory, "connectionProvider", true);
pools = (Map<Class<?>, GenericObjectPool<StatefulConnection<?, ?>>>) FieldUtils.readField(lettuceConnectionProvider, "pools", true);
}
@Scheduled(fixedRate = 1000)
public void publishRedisMetrics() {
pools.forEach((key, value) -> {
Metrics.summary("lettuce_cluster_pool_metrics", "label", ACTIVE_CONNECTIONS).record(value.getNumActive());
Metrics.summary("lettuce_cluster_pool_metrics", "label", IDLE_CONNECTIONS).record(value.getNumIdle());
Metrics.summary("lettuce_cluster_pool_metrics", "label", WAITERS_COUNT).record(value.getNumWaiters());
Metrics.summary("lettuce_cluster_pool_metrics", "label", MEAN_WAITING_TIME).record(value.getMeanBorrowWaitTimeMillis());
Metrics.summary("lettuce_cluster_pool_metrics", "label", MAX_WAITING_TIME).record(value.getMaxBorrowWaitTimeMillis());
});
}
}