You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2022/12/07 02:52:22 UTC

[GitHub] [bookkeeper] zymap commented on a diff in pull request #3677: Make `jvm_memory_direct_bytes_used` metrics compatible with jdk8.

zymap commented on code in PR #3677:
URL: https://github.com/apache/bookkeeper/pull/3677#discussion_r1041691108


##########
stats/bookkeeper-stats-providers/prometheus-metrics-provider/src/main/java/org/apache/bookkeeper/stats/prometheus/PrometheusMetricsProvider.java:
##########
@@ -214,14 +217,34 @@ private void registerMetrics(Collector collector) {
         }
     }
 
-
     private static final Logger log = LoggerFactory.getLogger(PrometheusMetricsProvider.class);
 
+    /*
+     * Try to get Netty counter of used direct memory. This will be correct, unlike the JVM values.
+     */
+    private static final AtomicLong directMemoryUsage;
     private static final Optional<BufferPoolMXBean> poolMxBeanOp;
+    private static final Supplier<Double> getDirectMemoryUsage;
 
     static {
-        List<BufferPoolMXBean> platformMXBeans = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
-        poolMxBeanOp = platformMXBeans.stream()
-                .filter(bufferPoolMXBean -> bufferPoolMXBean.getName().equals("direct")).findAny();
+        if (PlatformDependent.useDirectBufferNoCleaner()) {
+            poolMxBeanOp = Optional.empty();
+            AtomicLong tmpDirectMemoryUsage = null;
+            try {
+                Field field = PlatformDependent.class.getDeclaredField("DIRECT_MEMORY_COUNTER");

Review Comment:
   Looks like they have the` usedDirectMemory()` method to access that field. Why don't we use that?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org