From 848c457bbe333f83915b2e8963bbeb1d7f86ae27 Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Tue, 19 May 2026 15:47:13 -0500 Subject: [PATCH] Use micrometer's netty metrics --- .../textsecuregcm/grpc/net/ManagedEventLoopGroup.java | 7 +++++++ .../textsecuregcm/grpc/net/OmnibusH2Server.java | 9 --------- .../textsecuregcm/metrics/MetricsUtil.java | 7 +++++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/net/ManagedEventLoopGroup.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/net/ManagedEventLoopGroup.java index 5c77b5df3..89b70b079 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/net/ManagedEventLoopGroup.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/net/ManagedEventLoopGroup.java @@ -5,6 +5,8 @@ package org.whispersystems.textsecuregcm.grpc.net; import io.dropwizard.lifecycle.Managed; +import io.micrometer.core.instrument.Metrics; +import io.micrometer.core.instrument.binder.netty4.NettyEventExecutorMetrics; import io.netty.channel.EventLoopGroup; /** @@ -19,6 +21,11 @@ public class ManagedEventLoopGroup implements Managed this.eventLoopGroup = eventLoopGroup; } + @Override + public void start() { + new NettyEventExecutorMetrics(eventLoopGroup).bindTo(Metrics.globalRegistry); + } + @Override public void stop() throws Exception { this.eventLoopGroup.shutdownGracefully().await(); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/net/OmnibusH2Server.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/net/OmnibusH2Server.java index 7bfa7ef95..0d5ed686f 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/net/OmnibusH2Server.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/net/OmnibusH2Server.java @@ -95,15 +95,6 @@ public class OmnibusH2Server implements Managed { logger.warn("No SSL configuration provided for OmnibusH2Server, serving h2c"); } - if (ByteBufAllocator.DEFAULT instanceof ByteBufAllocatorMetricProvider alloc) { - Metrics.gauge(MetricsUtil.name(OmnibusH2Server.class, "nettyUsedDirectMemory"), - alloc, - allocator -> allocator.metric().usedDirectMemory()); - Metrics.gauge(MetricsUtil.name(OmnibusH2Server.class, "nettyUsedHeapMemory"), - alloc, - allocator -> allocator.metric().usedHeapMemory()); - } - final ServerBootstrap bootstrap = new ServerBootstrap() .group(nioEventLoopGroup) .channel(NioServerSocketChannel.class) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/metrics/MetricsUtil.java b/service/src/main/java/org/whispersystems/textsecuregcm/metrics/MetricsUtil.java index 6afc5d0a7..4b2967855 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/metrics/MetricsUtil.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/metrics/MetricsUtil.java @@ -14,11 +14,14 @@ import io.micrometer.core.instrument.Metrics; import io.micrometer.core.instrument.binder.jetty.JettySslHandshakeMetrics; import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics; +import io.micrometer.core.instrument.binder.netty4.NettyAllocatorMetrics; import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics; import io.micrometer.core.instrument.binder.system.ProcessorMetrics; import io.micrometer.core.instrument.config.MeterFilter; import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; import io.micrometer.registry.otlp.OtlpMeterRegistry; +import io.netty.buffer.ByteBufAllocator; +import io.netty.buffer.ByteBufAllocatorMetricProvider; import io.opentelemetry.exporter.otlp.http.logs.OtlpHttpLogRecordExporter; import io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender; import io.opentelemetry.sdk.OpenTelemetrySdk; @@ -171,6 +174,10 @@ public class MetricsUtil { new JvmMemoryMetrics().bindTo(Metrics.globalRegistry); new JvmThreadMetrics().bindTo(Metrics.globalRegistry); + if (ByteBufAllocator.DEFAULT instanceof ByteBufAllocatorMetricProvider alloc) { + new NettyAllocatorMetrics(alloc).bindTo(Metrics.globalRegistry); + } + GarbageCollectionGauges.registerMetrics(); }