private void updateBufferPoolMetrics() {
    for (BufferPoolMXBean bufferPoolMXBean : bufferPoolMXBeanList) {
      String normalizedKeyName = bufferPoolMXBean.getName().replaceAll("[^\\w]", "-");

      final ByteAmount memoryUsed = ByteAmount.fromBytes(bufferPoolMXBean.getMemoryUsed());
      final ByteAmount totalCapacity = ByteAmount.fromBytes(bufferPoolMXBean.getTotalCapacity());
      final ByteAmount count = ByteAmount.fromBytes(bufferPoolMXBean.getCount());

      // The estimated memory the JVM is using for this buffer pool
      jvmBufferPoolMemoryUsage.safeScope(normalizedKeyName + "-memory-used")
          .setValue(memoryUsed.asMegabytes());

      // The estimated total capacity of the buffers in this pool
      jvmBufferPoolMemoryUsage.safeScope(normalizedKeyName + "-total-capacity")
          .setValue(totalCapacity.asMegabytes());

      // THe estimated number of buffers in this pool
      jvmBufferPoolMemoryUsage.safeScope(normalizedKeyName + "-count")
          .setValue(count.asMegabytes());
    }
  }
private void updateBufferPoolMetrics ( ) { for ( BufferPoolMXBean bufferPoolMXBean : bufferPoolMXBeanList ) { String normalizedKeyName = bufferPoolMXBean . getName ( ) . replaceAll ( "[^\\w]" , "-" ) ; final ByteAmount memoryUsed = ByteAmount . fromBytes ( bufferPoolMXBean . getMemoryUsed ( ) ) ; final ByteAmount totalCapacity = ByteAmount . fromBytes ( bufferPoolMXBean . getTotalCapacity ( ) ) ; final ByteAmount count = ByteAmount . fromBytes ( bufferPoolMXBean . getCount ( ) ) ; jvmBufferPoolMemoryUsage . safeScope ( normalizedKeyName + "-memory-used" ) . setValue ( memoryUsed . asMegabytes ( ) ) ; jvmBufferPoolMemoryUsage . safeScope ( normalizedKeyName + "-total-capacity" ) . setValue ( totalCapacity . asMegabytes ( ) ) ; jvmBufferPoolMemoryUsage . safeScope ( normalizedKeyName + "-count" ) . setValue ( count . asMegabytes ( ) ) ; } }
These metrics can be useful for diagnosing native memory usage.