open-telemetry / open-telemetry/opentelemetry-java-instrumentation

Netty - Add Gauges for Direct Memory Usage & Max

Open
#19,880 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement needs triage
Dominant language
Java
Stars
2.6k
Forks
1.2k
Avg merge
2d 18h
Merged PRs (30d)
228

Description

Is your feature request related to a problem? Please describe.

Once I moved my apps to Java 25, and Netty (4.2.16) stopped using Direct Buffers, I stopped seeing the off-heap usage via the jvm.buffer.memory.usage & jvm.buffer.memory.used metrics.

It seems like if available, Netty links against malloc and free for performance reasons.

Describe the solution you'd like

Updated or new metrics for tracking the usage and maximum for Netty's direct memory usage.

Describe alternatives you've considered
  • Not having these metrics
  • Performing manual instrumentation in every Java application I run
Additional context

I was able to get around this temporarily in 1 app with the below custom gauges.

private val usedDirectMemory = meter.gaugeBuilder("netty.native.used.direct.memory")
    .setDescription("Used direct memory in bytes")
    .setUnit("bytes")
    .buildWithCallback { result ->
        val usedMemory = io.netty.util.internal.PlatformDependent.usedDirectMemory()
        result.record(usedMemory.toDouble())
    }

private val maxDirectMemory = meter.gaugeBuilder("netty.native.max.direct.memory")
    .setDescription("Max direct memory in bytes")
    .setUnit("bytes")
    .buildWithCallback { result ->
        val maxMemory = io.netty.util.internal.PlatformDependent.maxDirectMemory()
        result.record(maxMemory.toDouble())
    }
Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing instrumentation around Netty's PlatformDependent.usedDirectMemory() and maxDirectMemory() entry points, using the Kotlin custom gauges as the requested behavior. Add metrics for current and maximum direct memory usage, with byte units and descriptions matching the example, and verify that both values are exposed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
observability
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.