Skip to content

Commit

Permalink
Merge pull request #1084 from jfernandez/jfernandez/fix-allocator-met…
Browse files Browse the repository at this point in the history
…rics

Register the allocator memory metric polled gauge only once
  • Loading branch information
jfernandez committed Aug 9, 2021
2 parents c295aa9 + c43fbbd commit e266f19
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions zuul-core/src/main/java/com/netflix/zuul/netty/server/Server.java
Expand Up @@ -203,6 +203,19 @@ public void start()
addressesToChannels.put(requestedNamedAddr.withNewSocket(chan.localAddress()), chan);
allBindFutures.add(nettyServerFuture);
}

// All channels should share a single ByteBufAllocator instance.
// Add metrics to monitor that allocator's memory usage.
if (!allBindFutures.isEmpty()) {
ByteBufAllocator alloc = allBindFutures.get(0).channel().alloc();
if (alloc instanceof ByteBufAllocatorMetricProvider) {
ByteBufAllocatorMetric metrics = ((ByteBufAllocatorMetricProvider) alloc).metric();
PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "heap"))
.monitorValue(metrics, ByteBufAllocatorMetric::usedHeapMemory);
PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "direct"))
.monitorValue(metrics, ByteBufAllocatorMetric::usedDirectMemory);
}
}
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
Expand Down Expand Up @@ -277,15 +290,6 @@ private ChannelFuture setupServerBootstrap(
// Bind and start to accept incoming connections.
ChannelFuture bindFuture = serverBootstrap.bind(listenAddress.unwrap());

ByteBufAllocator alloc = bindFuture.channel().alloc();
if (alloc instanceof ByteBufAllocatorMetricProvider) {
ByteBufAllocatorMetric metrics = ((ByteBufAllocatorMetricProvider) alloc).metric();
PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "heap"))
.monitorValue(metrics, ByteBufAllocatorMetric::usedHeapMemory);
PolledMeter.using(registry).withId(registry.createId("zuul.nettybuffermem.live", "type", "direct"))
.monitorValue(metrics, ByteBufAllocatorMetric::usedDirectMemory);
}

try {
return bindFuture.sync();
} catch (Exception e) {
Expand Down

0 comments on commit e266f19

Please sign in to comment.