I ended up doing using reflection to get connection metrics as well netty transport level metrics (both should be same) to expose as a JMX metric.
Probably, @Mark could confirm if this is a safe way or if there is an alternative way to get the numbers.
public int getRequestQueueSize() {
ChannelGroup channels = null;
try {
channels = (ChannelGroup) FieldUtils.readField(redisClient, "channels", true);
} catch (IllegalAccessException e) {
// e.printStackTrace();
}
int requestQueueSize = 0;
for(Channel channel : channels) {
CommandHandler commandHandler = null;
if (channel != null) {
commandHandler = channel.pipeline().get(CommandHandler.class);
DefaultEndpoint endpoint = null;
try {
endpoint = (DefaultEndpoint) FieldUtils.readField(commandHandler, "endpoint", true);
requestQueueSize += (Integer) FieldUtils.readField(endpoint, "queueSize", true);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return requestQueueSize;
}
public int getPendingTasks() {
Map<?, EventLoopGroup> eventLoopGroups = null;
int result = 0;
try {
eventLoopGroups = (Map) FieldUtils.readField(redisClient, "eventLoopGroups", true);
} catch (IllegalAccessException e) {
return -1;
}
int pendingTasks = 0;
for (EventLoopGroup eventExecutors : eventLoopGroups.values()) {
NioEventLoopGroup eventLoopGroup = (NioEventLoopGroup) eventExecutors;
Iterator<EventExecutor> iterator = eventLoopGroup.iterator();
while (iterator.hasNext()) {
SingleThreadEventExecutor eventLoop = (SingleThreadEventExecutor) iterator.next();
pendingTasks += eventLoop.pendingTasks();
}
}
return pendingTasks;
}