public static long directUsed() {
        List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
        return pools.stream()
            .filter(p -> "direct".equals(p.getName()))
            .mapToLong(BufferPoolMXBean::getMemoryUsed)
            .sum();
    }
Returns the amount of direct memory used by the JVM in bytes.
tools/src/main/java/org/apache/kafka/tools/automq/perf/MemoryMonitor.java