/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.drill.exec.metrics;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.HashMap;
import java.util.Map;

import com.codahale.metrics.Gauge;
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricSet;
import com.sun.management.OperatingSystemMXBean;

/**
 * Creates a Cpu GaugeSet
 */
@SuppressWarnings("restriction")
public class CpuGaugeSet implements MetricSet {

  private OperatingSystemMXBean osMXBean;
  private RuntimeMXBean rtMXBean;

  public CpuGaugeSet() {
    this.osMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    this.rtMXBean = ManagementFactory.getRuntimeMXBean();
  }

  @Override
  public Map<String, Metric> getMetrics() {
    final Map<String, Metric> metric = new HashMap<>(1);
    metric.put("os.load.avg", new OperatingSystemLoad(osMXBean));
    metric.put("drillbit.load.avg", new DrillbitProcessLoad(osMXBean));
    metric.put("drillbit.uptime", new DrillbitUptime(rtMXBean));
    return metric;
  }
}

/**
 * Creating an AverageSystemLoad Gauge
 */
@SuppressWarnings("restriction")
final class OperatingSystemLoad implements Gauge<Double> {
  private OperatingSystemMXBean osMXBean;
  public OperatingSystemLoad(OperatingSystemMXBean osBean) {
    this.osMXBean = osBean;
  }

  @Override
  public Double getValue() {
    return osMXBean.getSystemLoadAverage();
  }

}

/**
 * Creating an AverageDrillbitLoad Gauge
 */
@SuppressWarnings("restriction")
final class DrillbitProcessLoad implements Gauge<Double> {
  private OperatingSystemMXBean osMXBean;
  public DrillbitProcessLoad(OperatingSystemMXBean osBean) {
    this.osMXBean = osBean;
  }

  @Override
  public Double getValue() {
    return osMXBean.getProcessCpuLoad();
  }

}
/**
 * Creating an DrillbitUptime Gauge
 */
final class DrillbitUptime implements Gauge<Long> {
  private RuntimeMXBean rtMXBean;
  public DrillbitUptime(RuntimeMXBean osBean) {
    this.rtMXBean = osBean;
  }

  @Override
  public Long getValue() {
    return rtMXBean.getUptime();
  }

}

@@ -1248,16 +1248,119 @@
 ricSet %7B
+%0A  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(CpuGaugeSet.class);
 %0A%0A  priv
@@ -1355,32 +1355,38 @@
 ss);%0A%0A  private 
+final 
 OperatingSystemM
@@ -1403,32 +1403,38 @@
 Bean;%0A  private 
+final 
 RuntimeMXBean rt
@@ -1468,34 +1468,34 @@
 et() %7B%0A    this.
-os
+rt
 MXBean = (Operat
@@ -1491,132 +1491,220 @@
 n = 
-(OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();%0A    this.rtMXBean = ManagementFactory.getRuntimeMXBean
+ManagementFactory.getRuntimeMXBean();%0A    //DRILL-6702: Instead of worrying about compiling with IBM JDK, for now, we shall provide no CPU metrics for non-HotSpot JVMs%0A    this.osMXBean = getOSMXBeanForCpuMetrics
 ();%0A
@@ -2046,16 +2046,403 @@
 ric;%0A  %7D
+%0A%0A  private static OperatingSystemMXBean getOSMXBeanForCpuMetrics() %7B%0A    try %7B%0A      return (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();%0A    %7D catch (ClassCastException ex) %7B%0A      logger.warn(%22%7B%7D. Detected non-Supported JVM %5B%7B%7D%5D. CPU Metrics in the WebUI will not be available!%22, ex.getMessage(), System.getProperty(%22java.vm.name%22));%0A    %7D%0A    return null;%0A  %7D
 %0A%7D%0A%0A/**%0A
@@ -2755,32 +2755,53 @@
 e() %7B%0A    return
+ (osMXBean != null) ?
  osMXBean.getSys
@@ -2816,16 +2816,23 @@
 verage()
+ : null
 ;%0A  %7D%0A%0A%7D
@@ -3161,16 +3161,37 @@
   return
+ (osMXBean != null) ?
  osMXBea
@@ -3211,16 +3211,23 @@
 puLoad()
+ : null
 ;%0A  %7D%0A%0A%7D

Disable CPU Reporting for non-HotSpot JDKs