Skip to content

Commit

Permalink
Automatically register the default Netty allocator metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhoon committed Nov 21, 2024
1 parent 5b3a182 commit 4441e69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

import com.google.common.collect.ImmutableList;

import com.linecorp.armeria.common.Flags;
import com.linecorp.armeria.common.annotation.UnstableApi;
import com.linecorp.armeria.internal.common.util.CertificateUtil;

import io.micrometer.core.instrument.binder.MeterBinder;
import io.micrometer.core.instrument.binder.netty4.NettyAllocatorMetrics;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.EventLoopGroup;

Expand All @@ -37,6 +39,12 @@
*/
public final class MoreMeterBinders {

static {
// Bind the default Netty allocator metrics to the default MeterRegistry.
new NettyAllocatorMetrics(PooledByteBufAllocator.DEFAULT)
.bindTo(Flags.meterRegistry());
}

/**
* Returns a new {@link MeterBinder} to observe Netty's {@link EventLoopGroup}s. The following stats are
* currently exported per registered {@link MeterIdPrefix}.
Expand Down Expand Up @@ -69,29 +77,6 @@ public static CloseableMeterBinder eventLoopMetrics(EventLoopGroup eventLoopGrou
return new EventLoopMetrics(eventLoopGroup, meterIdPrefix);
}

/**
* Returns a new {@link MeterBinder} to observe Netty's default {@link PooledByteBufAllocator}.
* The following stats are currently exported per registered {@link MeterIdPrefix}.
*
*
* <ul>
* <li>"pooled.byte.buf.allocator.numHeapArenas" (gauge) - the number of heap arenas</li>
* <li>"pooled.byte.buf.allocator.numDirectArenas" (gauge) - the number of direct arenas</li>
* <li>"pooled.byte.buf.allocator.numThreadLocalCaches" (gauge) - the number of thread local caches</li>
* <li>"pooled.byte.buf.allocator.tinyCacheSize" (gauge) - the size of tiny cache</li>
* <li>"pooled.byte.buf.allocator.smallCacheSize" (gauge) - the size of small cache</li>
* <li>"pooled.byte.buf.allocator.normalCacheSize" (gauge) - the size of normal cache</li>
* <li>"pooled.byte.buf.allocator.chunkSize" (gauge) - the chunk size used by the allocator</li>
* </ul>
*
* @param meterIdPrefix the prefix to use for all metrics
* @return a new {@link PooledByteBufAllocatorMetrics} instance for the default allocator
*/
public static PooledByteBufAllocatorMetrics pooledByteBufAllocatorMetrics(
MeterIdPrefix meterIdPrefix) {
return new PooledByteBufAllocatorMetrics(PooledByteBufAllocator.DEFAULT, meterIdPrefix);
}

/**
* Returns a new {@link MeterBinder} to observe the specified {@link X509Certificate}'s validity.
* The following stats are currently exported per registered {@link MeterIdPrefix}.
Expand Down

This file was deleted.

0 comments on commit 4441e69

Please sign in to comment.