private void getJvmMetrics(final MetricsRecordBuilder rb) {
    List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
    long directBufferCount = 0;
    long directBufferTotalCapacity = 0;
    long directBufferMemoryUsed = 0;
    long mappedBufferCount = 0;
    long mappedBufferTotalCapacity = 0;
    long mappedBufferMemoryUsed = 0;
    for (BufferPoolMXBean pool : pools) {
      if (pool.getName().equals("direct")) {
        directBufferCount = pool.getCount();
        directBufferTotalCapacity = pool.getTotalCapacity();
        directBufferMemoryUsed = pool.getMemoryUsed();
      } else if (pool.getName().equals("mapped")) {
        mappedBufferCount = pool.getCount();
        mappedBufferTotalCapacity = pool.getTotalCapacity();
        mappedBufferMemoryUsed = pool.getMemoryUsed();
      }
    }

    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    long openFileHandles = 0;
    long maxFileHandles = 0;
    if(os instanceof UnixOperatingSystemMXBean){
      openFileHandles = ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount();
      maxFileHandles = ((UnixOperatingSystemMXBean) os).getMaxFileDescriptorCount();
      maxOpenFdCountSoFar = openFileHandles > maxOpenFdCountSoFar ? openFileHandles : maxOpenFdCountSoFar;
    }
    long rss = 0;
    long vmem = 0;
    if (processTree != null) {
      rss = processTree.getRssMemorySize();
      vmem = processTree.getVirtualMemorySize();
    }
    rb.addGauge(LlapDaemonDirectBufferCount, directBufferCount)
      .addGauge(LlapDaemonDirectBufferTotalCapacity, directBufferTotalCapacity)
      .addGauge(LlapDaemonDirectBufferMemoryUsed, directBufferMemoryUsed)
      .addGauge(LlapDaemonMappedBufferCount, mappedBufferCount)
      .addGauge(LlapDaemonMappedBufferTotalCapacity, mappedBufferTotalCapacity)
      .addGauge(LlapDaemonMappedBufferMemoryUsed, mappedBufferMemoryUsed)
      .addGauge(LlapDaemonOpenFileDescriptorCount, openFileHandles)
      .addGauge(LlapDaemonMaxFileDescriptorCount, maxOpenFdCountSoFar)
      .addGauge(LlapDaemonLimitFileDescriptorCount, maxFileHandles)
      .addGauge(LlapDaemonResidentSetSize, rss)
      .addGauge(LlapDaemonVirtualMemorySize, vmem);
  }
Class to report LLAP Daemon's JVM metrics to the hadoop metrics2 API.
llap-server/src/java/org/apache/hadoop/hive/llap/metrics/LlapDaemonJvmMetrics.java