diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/metrics/MetricsMBeanBase.java hbase-server/src/main/java/org/apache/hadoop/hbase/metrics/MetricsMBeanBase.java index d23f378..c5a17ce 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/metrics/MetricsMBeanBase.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/metrics/MetricsMBeanBase.java @@ -30,9 +30,11 @@ import javax.management.MBeanException; import javax.management.MBeanInfo; import javax.management.ReflectionException; +import com.yammer.metrics.stats.Snapshot; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.hbase.metrics.histogram.MetricsHistogram; import org.apache.hadoop.metrics.util.MetricsBase; import org.apache.hadoop.metrics.util.MetricsDynamicMBeanBase; import org.apache.hadoop.metrics.util.MetricsRegistry; @@ -106,6 +108,51 @@ public class MetricsMBeanBase extends MetricsDynamicMBeanBase { "java.lang.String", metric.getDescription(), true, false, false) ); extendedAttributes.put(metric.getName(), metric); LOG.info("MetricsString added: " + metric.getName()); + } else if (metric instanceof MetricsHistogram) { + String metricName = metric.getName()+"_num_ops"; + attributes.add( new MBeanAttributeInfo(metricName, + "java.lang.Long", metric.getDescription(), true, false, false) ); + extendedAttributes.put(metricName, metric); + + metricName = metric.getName()+"_min"; + attributes.add( new MBeanAttributeInfo(metricName, + "java.lang.Long", metric.getDescription(), true, false, false) ); + extendedAttributes.put(metricName, metric); + + metricName = metric.getName()+"_max"; + attributes.add( new MBeanAttributeInfo(metricName, + "java.lang.Long", metric.getDescription(), true, false, false) ); + extendedAttributes.put(metricName, metric); + + metricName = metric.getName()+"_mean"; + attributes.add( new MBeanAttributeInfo(metricName, + "java.lang.Float", metric.getDescription(), true, false, false) ); + extendedAttributes.put(metricName, metric); + + metricName = metric.getName()+"_std_dev"; + attributes.add( new MBeanAttributeInfo(metricName, + "java.lang.Float", metric.getDescription(), true, false, false) ); + extendedAttributes.put(metricName, metric); + + metricName = metric.getName()+"_median"; + attributes.add( new MBeanAttributeInfo(metricName, + "java.lang.Float", metric.getDescription(), true, false, false) ); + extendedAttributes.put(metricName, metric); + + metricName = metric.getName()+"_75th_percentile"; + attributes.add( new MBeanAttributeInfo(metricName, + "java.lang.Float", metric.getDescription(), true, false, false) ); + extendedAttributes.put(metricName, metric); + + metricName = metric.getName()+"_95th_percentile"; + attributes.add( new MBeanAttributeInfo(metricName, + "java.lang.Float", metric.getDescription(), true, false, false) ); + extendedAttributes.put(metricName, metric); + + metricName = metric.getName()+"_99th_percentile"; + attributes.add( new MBeanAttributeInfo(metricName, + "java.lang.Float", metric.getDescription(), true, false, false) ); + extendedAttributes.put(metricName, metric); } // else, its probably a hadoop metric already registered. Skip it. } @@ -150,6 +197,32 @@ public class MetricsMBeanBase extends MetricsDynamicMBeanBase { return ((MetricsRate) metric).getPreviousIntervalValue(); } else if (metric instanceof MetricsString) { return ((MetricsString)metric).getValue(); + } else if (metric instanceof MetricsHistogram) { + MetricsHistogram hist = (MetricsHistogram) metric; + if (name.endsWith("_num_ops")) { + return hist.getCount(); + } else if (name.endsWith("_min")) { + return hist.getMin(); + } else if (name.endsWith("_max")) { + return hist.getMax(); + } else if (name.endsWith("_mean")) { + return (float) hist.getMean(); + } else if (name.endsWith("_std_dev")) { + return (float) hist.getStdDev(); + } else if (name.endsWith("_median")) { + Snapshot s = hist.getSnapshot(); + return (float) s.getMedian(); + } else if (name.endsWith("_75th_percentile")) { + Snapshot s = hist.getSnapshot(); + return (float) s.get75thPercentile(); + } else if (name.endsWith("_95th_percentile")) { + Snapshot s = hist.getSnapshot(); + return (float) s.get95thPercentile(); + } else if (name.endsWith("_99th_percentile")) { + Snapshot s = hist.getSnapshot(); + return (float) s.get99thPercentile(); + } + } else { LOG.warn( String.format("unknown metrics type %s for attribute %s", metric.getClass().getName(), name) );