This version is still in development and is not considered stable yet. For the latest stable version, please use Micrometer 1.15.5!

Netty Instrumentation

Micrometer supports binding metrics to Netty.

You can collect metrics from ByteBuf allocators and from EventLoopGroup instances. If you already know the resources, you can create instrumentation only once at startup:

// Create or get an existing resources
MultithreadEventLoopGroup eventExecutors = new MultiThreadIoEventLoopGroup(LocalIoHandler.newFactory());
UnpooledByteBufAllocator unpooledByteBufAllocator = new UnpooledByteBufAllocator(false);
// Use binders to instrument them
new NettyEventExecutorMetrics(eventExecutors).bindTo(this.registry);
new NettyAllocatorMetrics(unpooledByteBufAllocator).bindTo(this.registry);

Netty infrastructure can be configured in many ways, so you can also instrument lazily at runtime, as resources are used. The following example shows how to lazily create instrumentation:

@Override
protected void initChannel(SocketChannel channel) {
    EventLoop eventLoop = channel.eventLoop();
    if (!isEventLoopInstrumented(eventLoop)) {
        new NettyEventExecutorMetrics(eventLoop).bindTo(this.meterRegistry);
    }
    ByteBufAllocator allocator = channel.alloc();
    if (!isAllocatorInstrumented(allocator)
            && allocator instanceof ByteBufAllocatorMetricProvider allocatorMetric) {
        new NettyAllocatorMetrics(allocatorMetric).bindTo(this.meterRegistry);
    }
}
If you use lazy instrumentation, you must ensure that you do not bind metrics for the same resource multiple times, as this can have runtime drawbacks.

EventExecutor Metrics

The NettyEventExecutorMetrics binder collects metrics from Netty’s EventExecutor instances:

Table 1. EventExecutor metrics
Metric Type Description

eventexecutor.workers

Gauge

The number of event executor workers

eventexecutor.tasks.pending

Gauge

The number of pending tasks in individual event executors