http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java ---------------------------------------------------------------------- diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java index 1b8dab8..6a2f203 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableHistogram.java @@ -20,9 +20,10 @@ package org.apache.hadoop.metrics2.lib; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.metrics.Histogram; import org.apache.hadoop.hbase.metrics.Interns; -import org.apache.hadoop.hbase.util.Counter; -import org.apache.hadoop.hbase.util.FastLongHistogram; +import org.apache.hadoop.hbase.metrics.Snapshot; +import org.apache.hadoop.hbase.metrics.impl.HistogramImpl; import org.apache.hadoop.metrics2.MetricHistogram; import org.apache.hadoop.metrics2.MetricsInfo; import org.apache.hadoop.metrics2.MetricsRecordBuilder; @@ -32,30 +33,10 @@ import org.apache.hadoop.metrics2.MetricsRecordBuilder; */ @InterfaceAudience.Private public class MutableHistogram extends MutableMetric implements MetricHistogram { - // Double buffer the two FastLongHistograms. - // As they are reset they learn how the buckets should be spaced - // So keep two around and use them - protected final FastLongHistogram histogram; - + protected HistogramImpl histogram; protected final String name; protected final String desc; - protected final Counter counter = new Counter(0); - - private boolean metricsInfoStringInited = false; - private String NUM_OPS_METRIC; - private String MIN_METRIC; - private String MAX_METRIC; - private String MEAN_METRIC; - private String MEDIAN_METRIC; - private String TWENTY_FIFTH_PERCENTILE_METRIC; - private String SEVENTY_FIFTH_PERCENTILE_METRIC; - private String NINETIETH_PERCENTILE_METRIC; - private String NINETY_FIFTH_PERCENTILE_METRIC; - private String NINETY_EIGHTH_PERCENTILE_METRIC; - private String NINETY_NINETH_PERCENTILE_METRIC; - private String NINETY_NINE_POINT_NINETH_PERCENTILE_METRIC; - public MutableHistogram(MetricsInfo info) { this(info.name(), info.description()); } @@ -67,13 +48,11 @@ public class MutableHistogram extends MutableMetric implements MetricHistogram { protected MutableHistogram(String name, String description, long maxExpected) { this.name = StringUtils.capitalize(name); this.desc = StringUtils.uncapitalize(description); - - this.histogram = new FastLongHistogram(FastLongHistogram.DEFAULT_NBINS, 1, maxExpected); + this.histogram = new HistogramImpl(); } public void add(final long val) { - counter.increment(); - histogram.add(val, 1); + histogram.update(val); } public long getMax() { @@ -82,56 +61,42 @@ public class MutableHistogram extends MutableMetric implements MetricHistogram { @Override public synchronized void snapshot(MetricsRecordBuilder metricsRecordBuilder, boolean all) { - // Get a reference to the old histogram. - FastLongHistogram histo = histogram.reset(); - if (histo != null) { - updateSnapshotMetrics(metricsRecordBuilder, histo); - } + snapshot(name, desc, histogram, metricsRecordBuilder, all); } - protected void updateSnapshotMetrics(MetricsRecordBuilder metricsRecordBuilder, - FastLongHistogram histo) { - if (!metricsInfoStringInited) { - NUM_OPS_METRIC = name + NUM_OPS_METRIC_NAME; - MIN_METRIC = name + MIN_METRIC_NAME; - MAX_METRIC = name + MAX_METRIC_NAME; - MEAN_METRIC = name + MEAN_METRIC_NAME; - MEDIAN_METRIC = name + MEDIAN_METRIC_NAME; - TWENTY_FIFTH_PERCENTILE_METRIC = name + TWENTY_FIFTH_PERCENTILE_METRIC_NAME; - SEVENTY_FIFTH_PERCENTILE_METRIC = name + SEVENTY_FIFTH_PERCENTILE_METRIC_NAME; - NINETIETH_PERCENTILE_METRIC = name + NINETIETH_PERCENTILE_METRIC_NAME; - NINETY_FIFTH_PERCENTILE_METRIC = name + NINETY_FIFTH_PERCENTILE_METRIC_NAME; - NINETY_EIGHTH_PERCENTILE_METRIC = name + NINETY_EIGHTH_PERCENTILE_METRIC_NAME; - NINETY_NINETH_PERCENTILE_METRIC = name + NINETY_NINETH_PERCENTILE_METRIC_NAME; - NINETY_NINE_POINT_NINETH_PERCENTILE_METRIC = name + - NINETY_NINE_POINT_NINETH_PERCENTILE_METRIC_NAME; - - metricsInfoStringInited = true; + public static void snapshot(String name, String desc, Histogram histogram, + MetricsRecordBuilder metricsRecordBuilder, boolean all) { + // Get a reference to the old histogram. + Snapshot snapshot = histogram.snapshot(); + if (snapshot != null) { + updateSnapshotMetrics(name, desc, histogram, snapshot, metricsRecordBuilder); } + } - metricsRecordBuilder.addCounter(Interns.info(NUM_OPS_METRIC, desc), counter.get()); - metricsRecordBuilder.addGauge(Interns.info(MIN_METRIC, desc), histo.getMin()); - metricsRecordBuilder.addGauge(Interns.info(MAX_METRIC, desc), histo.getMax()); - metricsRecordBuilder.addGauge(Interns.info(MEAN_METRIC, desc), histo.getMean()); - - long[] percentiles = histo.getQuantiles(); - - metricsRecordBuilder.addGauge(Interns.info(TWENTY_FIFTH_PERCENTILE_METRIC, desc), - percentiles[0]); - metricsRecordBuilder.addGauge(Interns.info(MEDIAN_METRIC, desc), - percentiles[1]); - metricsRecordBuilder.addGauge(Interns.info(SEVENTY_FIFTH_PERCENTILE_METRIC, desc), - percentiles[2]); - metricsRecordBuilder.addGauge(Interns.info(NINETIETH_PERCENTILE_METRIC, desc), - percentiles[3]); - metricsRecordBuilder.addGauge(Interns.info(NINETY_FIFTH_PERCENTILE_METRIC, desc), - percentiles[4]); - metricsRecordBuilder.addGauge(Interns.info(NINETY_EIGHTH_PERCENTILE_METRIC, desc), - percentiles[5]); - metricsRecordBuilder.addGauge(Interns.info(NINETY_NINETH_PERCENTILE_METRIC, desc), - percentiles[6]); + protected static void updateSnapshotMetrics(String name, String desc, Histogram histogram, + Snapshot snapshot, MetricsRecordBuilder metricsRecordBuilder) { + metricsRecordBuilder.addCounter(Interns.info(name + NUM_OPS_METRIC_NAME, desc), + histogram.getCount()); + metricsRecordBuilder.addGauge(Interns.info(name + MIN_METRIC_NAME, desc), snapshot.getMin()); + metricsRecordBuilder.addGauge(Interns.info(name + MAX_METRIC_NAME, desc), snapshot.getMax()); + metricsRecordBuilder.addGauge(Interns.info(name + MEAN_METRIC_NAME, desc), snapshot.getMean()); + + metricsRecordBuilder.addGauge(Interns.info(name + TWENTY_FIFTH_PERCENTILE_METRIC_NAME, desc), + snapshot.get25thPercentile()); + metricsRecordBuilder.addGauge(Interns.info(name + MEDIAN_METRIC_NAME, desc), + snapshot.getMedian()); + metricsRecordBuilder.addGauge(Interns.info(name + SEVENTY_FIFTH_PERCENTILE_METRIC_NAME, desc), + snapshot.get75thPercentile()); + metricsRecordBuilder.addGauge(Interns.info(name + NINETIETH_PERCENTILE_METRIC_NAME, desc), + snapshot.get90thPercentile()); + metricsRecordBuilder.addGauge(Interns.info(name + NINETY_FIFTH_PERCENTILE_METRIC_NAME, desc), + snapshot.get95thPercentile()); + metricsRecordBuilder.addGauge(Interns.info(name + NINETY_EIGHTH_PERCENTILE_METRIC_NAME, desc), + snapshot.get98thPercentile()); + metricsRecordBuilder.addGauge(Interns.info(name + NINETY_NINETH_PERCENTILE_METRIC_NAME, desc), + snapshot.get99thPercentile()); metricsRecordBuilder.addGauge( - Interns.info(NINETY_NINE_POINT_NINETH_PERCENTILE_METRIC, desc), - percentiles[7]); + Interns.info(name + NINETY_NINE_POINT_NINETH_PERCENTILE_METRIC_NAME, desc), + snapshot.get999thPercentile()); } }
http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java ---------------------------------------------------------------------- diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java index 94bcdaa..a12dc27 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/metrics2/lib/MutableRangeHistogram.java @@ -20,7 +20,7 @@ package org.apache.hadoop.metrics2.lib; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.metrics.Interns; -import org.apache.hadoop.hbase.util.FastLongHistogram; +import org.apache.hadoop.hbase.metrics.Snapshot; import org.apache.hadoop.metrics2.MetricHistogram; import org.apache.hadoop.metrics2.MetricsInfo; import org.apache.hadoop.metrics2.MetricsRecordBuilder; @@ -56,22 +56,22 @@ public abstract class MutableRangeHistogram extends MutableHistogram implements @Override public synchronized void snapshot(MetricsRecordBuilder metricsRecordBuilder, boolean all) { // Get a reference to the old histogram. - FastLongHistogram histo = histogram.reset(); - if (histo != null) { - updateSnapshotMetrics(metricsRecordBuilder, histo); - updateSnapshotRangeMetrics(metricsRecordBuilder, histo); + Snapshot snapshot = histogram.snapshot(); + if (snapshot != null) { + updateSnapshotMetrics(name, desc, histogram, snapshot, metricsRecordBuilder); + updateSnapshotRangeMetrics(metricsRecordBuilder, snapshot); } } public void updateSnapshotRangeMetrics(MetricsRecordBuilder metricsRecordBuilder, - FastLongHistogram histogram) { + Snapshot snapshot) { long priorRange = 0; long cumNum = 0; final long[] ranges = getRanges(); final String rangeType = getRangeType(); for (int i = 0; i < ranges.length - 1; i++) { - long val = histogram.getNumAtOrBelow(ranges[i]); + long val = snapshot.getCountAtOrBelow(ranges[i]); if (val - cumNum > 0) { metricsRecordBuilder.addCounter( Interns.info(name + "_" + rangeType + "_" + priorRange + "-" + ranges[i], desc), http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/impl/TestGlobalMetricRegistriesAdapter.java ---------------------------------------------------------------------- diff --git a/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/impl/TestGlobalMetricRegistriesAdapter.java b/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/impl/TestGlobalMetricRegistriesAdapter.java new file mode 100644 index 0000000..e20a1f3 --- /dev/null +++ b/hbase-hadoop2-compat/src/test/java/org/apache/hadoop/hbase/metrics/impl/TestGlobalMetricRegistriesAdapter.java @@ -0,0 +1,86 @@ +/** + * 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.hadoop.hbase.metrics.impl; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.apache.hadoop.hbase.metrics.MetricRegistryInfo; +import org.apache.hadoop.hbase.testclassification.MetricsTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.apache.hadoop.metrics2.MetricsSource; +import org.apache.hadoop.metrics2.MetricsSystem; +import org.apache.hadoop.metrics2.annotation.Metric; +import org.apache.hadoop.metrics2.annotation.Metrics; +import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; +import org.apache.hadoop.metrics2.lib.MetricsRegistry; +import org.apache.hadoop.metrics2.lib.MutableCounterLong; +import org.apache.hadoop.metrics2.lib.MutableGaugeLong; +import org.apache.hadoop.metrics2.lib.MutableRate; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.mockito.Mockito; + +@Category({ MetricsTests.class, SmallTests.class }) +public class TestGlobalMetricRegistriesAdapter { + + /** + * Tests that using reflection to unregister the Hadoop metrics source works properly + */ + @Test + public void testUnregisterSource() { + GlobalMetricRegistriesAdapter adapter = GlobalMetricRegistriesAdapter.init(); + // we'll configure the sources manually, so disable the executor + adapter.stop(); + TestSource ts1 = new TestSource("ts1"); + TestSource ts2 = new TestSource("ts2"); + MetricsSystem metricsSystem = DefaultMetricsSystem.instance(); + metricsSystem.register("ts1", "", ts1); + metricsSystem.register("ts2", "", ts2); + MetricsSource s1 = metricsSystem.getSource("ts1"); + assertNotNull(s1); + MetricRegistryInfo mockRegistryInfo = Mockito.mock(MetricRegistryInfo.class); + Mockito.when(mockRegistryInfo.getMetricsJmxContext()).thenReturn("ts1"); + adapter.unregisterSource(mockRegistryInfo); + s1 = metricsSystem.getSource("ts1"); + assertNull(s1); + MetricsSource s2 = metricsSystem.getSource("ts2"); + assertNotNull(s2); + } + + @Metrics(context = "test") + private static class TestSource { + @Metric("C1 desc") + MutableCounterLong c1; + @Metric("XXX desc") + MutableCounterLong xxx; + @Metric("G1 desc") + MutableGaugeLong g1; + @Metric("YYY desc") + MutableGaugeLong yyy; + @Metric + MutableRate s1; + @SuppressWarnings("unused") + final MetricsRegistry registry; + + TestSource(String recName) { + registry = new MetricsRegistry(recName); + } + } + +} http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/README.txt ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/README.txt b/hbase-metrics-api/README.txt new file mode 100644 index 0000000..dfaa29f --- /dev/null +++ b/hbase-metrics-api/README.txt @@ -0,0 +1,78 @@ +Overview +======== +hbase-metrics and hbase-metrics-api are two modules that define and implement the "new" metric +system used internally within HBase. These two modules (and some other code in hbase-hadoop2-compat) +module are referred as "HBase metrics framework". + +HBase-metrics-api Module +======================== +HBase Metrics API (hbase-metrics-api) contains the interface +that HBase exposes internally and to third party code (including coprocessors). It is a thin +abstraction over the actual implementation for backwards compatibility guarantees. The source +/ binary and other compatibility guarantees are for "LimitedPrivate API" (see [1] for an +explanation). + +The metrics API in this hbase-metrics-api module is inspired by the Dropwizard metrics 3.1 API +(See [2]). It is a subset of the API only containing metrics collection. However, the implementation +is HBase-specific and provided in hbase-metrics module. All of the classes in this module is +HBase-internal. See the latest documentation of Dropwizard metrics for examples of defining / using +metrics. + + +HBase-metrics Module +==================== +hbase-metrics module contains implementation of the "HBase Metrics API", including MetricRegistry, +Counter, Histogram, etc. These are highly concurrent implementations of the Metric interfaces. +Metrics in HBase are grouped into different sets (like WAL, RPC, RegionServer, etc). Each group of +metrics should be tracked via a MetricRegistry specific to that group. Metrics can be dynamically +added or removed from the registry with a name. Each Registry is independent of the other +registries and will have it's own JMX context and MetricRecord (when used with Metrics2). + + +MetricRegistry's themselves are tracked via a global registry (of MetricRegistries) called +MetricRegistries. MetricRegistries.global() can be used to obtain the global instance. +MetricRegistry instances can also be dynamically registered and removed. However, unlike the +MetricRegistry, MetricRegistries does reference counting of the MetricRegistry instances. Only +Metrics in the MetricRegistry instances that are in the global MetricRegistry are exported to the +metric sinks or JMX. + + +Coprocessor Metrics +=================== +HBase allows custom coprocessors to track and export metrics using the new framework. +Coprocessors and other third party code should only use the classes and interfaces from +hbase-metrics-api module and only the classes that are marked with InterfaceAudience.LimitedPrivate +annotation. There is no guarantee on the compatibility requirements for other classes. + +Coprocessors can obtain the MetricRegistry to register their custom metrics via corresponding +CoprocessorEnvironment context. See ExampleRegionObserverWithMetrics and +ExampleMasterObserverWithMetrics classes in hbase-examples module for usage. + + +Developer Notes +=============== +Historically, HBase has been using Hadoop's Metrics2 framework [3] for collecting and reporting the +metrics internally. However, due to the difficultly of dealing with the Metrics2 framework, HBase is +moving away from Hadoop's metrics implementation to its custom implementation. The move will happen +incrementally, and during the time, both Hadoop Metrics2-based metrics and hbase-metrics module +based classes will be in the source code. All new implementations for metrics SHOULD use the new +API and framework. + +Examples of the new framework can be found in MetricsCoprocessor and MetricsRegionServerSourceImpl +classes. See HBASE-9774 [4] for more context. + +hbase-metrics module right now only deals with metrics tracking and collection. It does not do JMX +reporting or reporting to console, ganglia, opentsdb, etc. We use Hadoop's Metrics2 for reporting +metrics to different sinks or exporting via JMX. However, this is contained within the +hbase-hadoop2-compat module completely, so that rest of the code does not know anything about the +Metrics2 dependency. HBaseMetrics2HadoopMetricsAdapter is the adapter that can collect metrics +in a MetricRegistry using the metric2 MetricsCollector / MetricRecordBuilder interfaces. +GlobalMetricRegistriesSource is the global Metrics2 Source that collects all of the metrics in all +of the metric registries in the MetricRegistries.global() instance. + + +References +1. https://hbase.apache.org/book.html#hbase.versioning +2. http://metrics.dropwizard.io/ +3. https://hadoop.apache.org/docs/r2.7.2/api/org/apache/hadoop/metrics2/package-summary.html +4. https://issues.apache.org/jira/browse/HBASE-9774 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/pom.xml ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/pom.xml b/hbase-metrics-api/pom.xml new file mode 100644 index 0000000..cf55905 --- /dev/null +++ b/hbase-metrics-api/pom.xml @@ -0,0 +1,112 @@ +<?xml version="1.0"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <!-- + /** + * 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. + */ + --> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>hbase</artifactId> + <groupId>org.apache.hbase</groupId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + + <artifactId>hbase-metrics-api</artifactId> + <name>Apache HBase - Metrics API</name> + <description>HBase Metrics API descriptions</description> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-site-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <!-- Make a jar and put the sources in the jar --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + </plugin> + <plugin> + <!--Make it so assembly:single does nothing in here--> + <artifactId>maven-assembly-plugin</artifactId> + <version>${maven.assembly.version}</version> + <configuration> + <skipAssembly>true</skipAssembly> + </configuration> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <!-- Always skip the second part executions, since we only run simple unit tests in this module --> + <executions> + <execution> + <id>secondPartTestsExecution</id> + <phase>test</phase> + <goals> + <goal>test</goal> + </goals> + <configuration> + <skip>true</skip> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <dependencies> + <!-- Intra-project dependencies --> + <dependency> + <groupId>org.apache.hbase</groupId> + <artifactId>hbase-annotations</artifactId> + </dependency> + <dependency> + <groupId>org.apache.hbase</groupId> + <artifactId>hbase-annotations</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.hbase</groupId> + <artifactId>hbase-common</artifactId> + </dependency> + <!-- General dependencies --> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + </dependencies> + + <profiles> + <!-- Skip the tests in this module --> + <profile> + <id>skip-metrics-api-tests</id> + <activation> + <property> + <name>skip-metrics-api-tests</name> + </property> + </activation> + <properties> + <surefire.skipFirstPart>true</surefire.skipFirstPart> + </properties> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Counter.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Counter.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Counter.java new file mode 100644 index 0000000..2e4147e --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Counter.java @@ -0,0 +1,60 @@ +/** + * 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.hadoop.hbase.metrics; + +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; + +/** + * A mutable number optimized for high concurrency counting. + */ [email protected](HBaseInterfaceAudience.COPROC) [email protected] +public interface Counter extends Metric { + + /** + * Increment {@code this} by 1. + */ + void increment(); + + /** + * Increment {@code this} by {@code n}. + * + * @param n The amount to increment. + */ + void increment(long n); + + /** + * Decrement {@code this} by 1. + */ + void decrement(); + + /** + * Decrement {@code this} by {@code n}. + * + * @param n The amount to decrement. + */ + void decrement(long n); + + /** + * Returns the current value. + * @return the current value. + */ + long getCount(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Gauge.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Gauge.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Gauge.java new file mode 100644 index 0000000..90df8e0 --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Gauge.java @@ -0,0 +1,35 @@ +/** + * 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.hadoop.hbase.metrics; + +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; + +/** + * A metrics which measures a discrete value. + * + * @param <T> The value of the Gauge. + */ [email protected](HBaseInterfaceAudience.COPROC) [email protected] +public interface Gauge<T> extends Metric { + + T getValue(); + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Histogram.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Histogram.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Histogram.java new file mode 100644 index 0000000..b5b54c7 --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Histogram.java @@ -0,0 +1,58 @@ +/** + * 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.hadoop.hbase.metrics; + +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; + +/** + * A metric which measures the distribution of values. + */ [email protected](HBaseInterfaceAudience.COPROC) [email protected] +public interface Histogram extends Metric { + + /** + * Adds a new value to the distribution. + * + * @param value The value to add + */ + void update(int value); + + /** + * Adds a new value to the distribution. + * + * @param value The value to add + */ + void update(long value); + + /** + * Return the total number of values added to the histogram. + * @return the total number of values. + */ + long getCount(); + + /** + * Snapshot the current values in the Histogram + * @return a Snapshot of the distribution. + */ + @InterfaceAudience.Private + Snapshot snapshot(); + +} http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Meter.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Meter.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Meter.java new file mode 100644 index 0000000..fccaa38 --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Meter.java @@ -0,0 +1,90 @@ +/** + * 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.hadoop.hbase.metrics; + +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; + +/** + * A metric which measure the rate at which some operation is invoked. + */ [email protected](HBaseInterfaceAudience.COPROC) [email protected] +public interface Meter extends Metric { + + /** + * Records one occurrence. + */ + void mark(); + + /** + * Records {@code events} occurrences. + * + * @param events Number of occurrences to record. + */ + void mark(long events); + + /** + * Returns the number of events. + * @return the number of events. + */ + long getCount(); + + /** + * Returns the mean rate at which events have occurred since the meter was created. + * @return the mean rate at which events have occurred since the meter was created + */ + double getMeanRate(); + + /** + * Returns the one-minute exponentially-weighted moving average rate at which events have + * occurred since the meter was created. + * <p/> + * This rate has the same exponential decay factor as the one-minute load average in the {@code + * top} Unix command. + * + * @return the one-minute exponentially-weighted moving average rate at which events have + * occurred since the meter was created + */ + double getOneMinuteRate(); + + /** + * Returns the five-minute exponentially-weighted moving average rate at which events have + * occurred since the meter was created. + * <p/> + * This rate has the same exponential decay factor as the five-minute load average in the {@code + * top} Unix command. + * + * @return the five-minute exponentially-weighted moving average rate at which events have + * occurred since the meter was created + */ + double getFiveMinuteRate(); + + /** + * Returns the fifteen-minute exponentially-weighted moving average rate at which events have + * occurred since the meter was created. + * <p/> + * This rate has the same exponential decay factor as the fifteen-minute load average in the + * {@code top} Unix command. + * + * @return the fifteen-minute exponentially-weighted moving average rate at which events have + * occurred since the meter was created + */ + double getFifteenMinuteRate(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Metric.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Metric.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Metric.java new file mode 100644 index 0000000..0a31803 --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Metric.java @@ -0,0 +1,30 @@ +/** + * 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.hadoop.hbase.metrics; + +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; + +/** + * Parent interface for all metrics. + */ [email protected](HBaseInterfaceAudience.COPROC) [email protected] +public interface Metric { +} http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistries.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistries.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistries.java new file mode 100644 index 0000000..f2fb261 --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistries.java @@ -0,0 +1,90 @@ +/** + * + * 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.hadoop.hbase.metrics; + +import java.util.Collection; +import java.util.Set; + +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; + +import com.google.common.base.Optional; + +/** + * MetricRegistries is collection of MetricRegistry's. MetricsRegistries implementations should do + * ref-counting of MetricRegistry's via create() and remove() methods. + */ [email protected](HBaseInterfaceAudience.COPROC) [email protected] +public abstract class MetricRegistries { + + private static final class LazyHolder { + private static final MetricRegistries GLOBAL = MetricRegistriesLoader.load(); + } + + /** + * Return the global singleton instance for the MetricRegistries. + * @return MetricRegistries implementation. + */ + public static MetricRegistries global() { + return LazyHolder.GLOBAL; + } + + /** + * Removes all the MetricRegisties. + */ + public abstract void clear(); + + /** + * Create or return MetricRegistry with the given info. MetricRegistry will only be created + * if current reference count is 0. Otherwise ref counted is incremented, and an existing instance + * will be returned. + * @param info the info object for the MetricRegistrytry. + * @return created or existing MetricRegistry. + */ + public abstract MetricRegistry create(MetricRegistryInfo info); + + /** + * Decrements the ref count of the MetricRegistry, and removes if ref count == 0. + * @param key the info object for the MetricRegistrytry. + * @return true if metric registry is removed. + */ + public abstract boolean remove(MetricRegistryInfo key); + + /** + * Returns the MetricRegistry if found. + * @param info the info for the registry. + * @return a MetricRegistry optional. + */ + public abstract Optional<MetricRegistry> get(MetricRegistryInfo info); + + /** + * Returns MetricRegistryInfo's for the MetricRegistry's created. + * @return MetricRegistryInfo's for the MetricRegistry's created. + */ + public abstract Set<MetricRegistryInfo> getMetricRegistryInfos(); + + /** + * Returns MetricRegistry's created. + * @return MetricRegistry's created. + */ + public abstract Collection<MetricRegistry> getMetricRegistries(); +} http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistriesLoader.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistriesLoader.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistriesLoader.java new file mode 100644 index 0000000..4fef10c --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistriesLoader.java @@ -0,0 +1,96 @@ +/** + * + * 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.hadoop.hbase.metrics; + + +import java.util.ArrayList; +import java.util.List; +import java.util.ServiceLoader; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.util.ReflectionUtils; + +import com.google.common.annotations.VisibleForTesting; + [email protected] +public class MetricRegistriesLoader { + private static final Log LOG = LogFactory.getLog(MetricRegistries.class); + + private static final String defaultClass + = "org.apache.hadoop.hbase.metrics.impl.MetricRegistriesImpl"; + + /** + * Creates a {@link MetricRegistries} instance using the corresponding {@link MetricRegistries} + * available to {@link ServiceLoader} on the classpath. If no instance is found, then default + * implementation will be loaded. + * @return A {@link MetricRegistries} implementation. + */ + public static MetricRegistries load() { + List<MetricRegistries> availableImplementations = getDefinedImplemantations(); + return load(availableImplementations); + } + + /** + * Creates a {@link MetricRegistries} instance using the corresponding {@link MetricRegistries} + * available to {@link ServiceLoader} on the classpath. If no instance is found, then default + * implementation will be loaded. + * @return A {@link MetricRegistries} implementation. + */ + @VisibleForTesting + static MetricRegistries load(List<MetricRegistries> availableImplementations) { + + if (availableImplementations.size() == 1) { + // One and only one instance -- what we want/expect + MetricRegistries impl = availableImplementations.get(0); + LOG.info("Loaded MetricRegistries " + impl.getClass()); + return impl; + } else if (availableImplementations.isEmpty()) { + try { + return ReflectionUtils.newInstance((Class<MetricRegistries>)Class.forName(defaultClass)); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } else { + // Tell the user they're doing something wrong, and choose the first impl. + StringBuilder sb = new StringBuilder(); + for (MetricRegistries factory : availableImplementations) { + if (sb.length() > 0) { + sb.append(", "); + } + sb.append(factory.getClass()); + } + LOG.warn("Found multiple MetricRegistries implementations: " + sb + + ". Using first found implementation: " + availableImplementations.get(0)); + return availableImplementations.get(0); + } + } + + private static List<MetricRegistries> getDefinedImplemantations() { + ServiceLoader<MetricRegistries> loader = ServiceLoader.load(MetricRegistries.class); + List<MetricRegistries> availableFactories = new ArrayList<>(); + for (MetricRegistries impl : loader) { + availableFactories.add(impl); + } + return availableFactories; + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistry.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistry.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistry.java new file mode 100644 index 0000000..8404b43 --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistry.java @@ -0,0 +1,112 @@ +/** + * 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.hadoop.hbase.metrics; + + +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; + +import com.google.common.base.Optional; + +/** + * General purpose factory for creating various metrics. + */ [email protected](HBaseInterfaceAudience.COPROC) [email protected] +public interface MetricRegistry extends MetricSet { + + /** + * Get or construct a {@link Timer} used to measure durations and report rates. + * + * @param name the name of the timer. + * @return An instance of {@link Timer}. + */ + Timer timer(String name); + + /** + * Get or construct a {@link Histogram} used to measure a distribution of values. + * + * @param name The name of the Histogram. + * @return An instance of {@link Histogram}. + */ + Histogram histogram(String name); + + /** + * Get or construct a {@link Meter} used to measure durations and report distributions (a + * combination of a {@link Timer} and a {@link Histogram}. + * + * @param name The name of the Meter. + * @return An instance of {@link Meter}. + */ + Meter meter(String name); + + /** + * Get or construct a {@link Counter} used to track a mutable number. + * + * @param name The name of the Counter + * @return An instance of {@link Counter}. + */ + Counter counter(String name); + + /** + * Register a {@link Gauge}. The Gauge will be invoked at a period defined by the implementation + * of {@link MetricRegistry}. + * @param name The name of the Gauge. + * @param gauge A callback to compute the current value. + * @return the registered gauge, or the existing gauge + */ + <T> Gauge<T> register(String name, Gauge<T> gauge); + + /** + * Registers the {@link Metric} with the given name if there does not exist one with the same + * name. Returns the newly registered or existing Metric. + * @param name The name of the Metric. + * @param metric the metric to register + * @return the registered metric, or the existing metrid + */ + Metric register(String name, Metric metric); + + /** + * Registers the {@link Metric}s in the given MetricSet. + * @param metricSet set of metrics to register. + */ + void registerAll(MetricSet metricSet); + + /** + * Returns previously registered metric with the name if any. + * @param name the name of the metric + * @return previously registered metric + */ + Optional<Metric> get(String name); + + /** + * Removes the metric with the given name. + * + * @param name the name of the metric + * @return true if the metric is removed. + */ + boolean remove(String name); + + /** + * Return the MetricRegistryInfo object for this registry. + * @return MetricRegistryInfo describing the registry. + */ + @InterfaceAudience.Private + MetricRegistryInfo getMetricRegistryInfo(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistryFactory.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistryFactory.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistryFactory.java new file mode 100644 index 0000000..b161d20 --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistryFactory.java @@ -0,0 +1,36 @@ +/** + * + * 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.hadoop.hbase.metrics; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; + +/** + * A Factory for creating MetricRegistries. This is the main plugin point for metrics implementation + */ [email protected] +public interface MetricRegistryFactory { + /** + * Create a MetricRegistry from the given MetricRegistryInfo + * @param info the descriptor for MetricRegistry + * @return a MetricRegistry implementation + */ + MetricRegistry create(MetricRegistryInfo info); +} http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistryInfo.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistryInfo.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistryInfo.java new file mode 100644 index 0000000..58fcba7 --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricRegistryInfo.java @@ -0,0 +1,112 @@ +/** + * 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.hadoop.hbase.metrics; + + +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.hadoop.hbase.classification.InterfaceAudience; + +/** + * HBase Metrics are grouped in different MetricRegistry'ies. All metrics that correspond to a + * subcomponent (like RPC, GC, WAL) are managed in a single MetricRegistry. + * This class holds the name and description and JMX related context names for such group of + * metrics. + */ [email protected] +public class MetricRegistryInfo { + + protected final String metricsName; + protected final String metricsDescription; + protected final String metricsContext; + protected final String metricsJmxContext; + protected final boolean existingSource; + + public MetricRegistryInfo( + String metricsName, + String metricsDescription, + String metricsJmxContext, + String metricsContext, + boolean existingSource) { + this.metricsName = metricsName; + this.metricsDescription = metricsDescription; + this.metricsContext = metricsContext; + this.metricsJmxContext = metricsJmxContext; + this.existingSource = existingSource; + } + + /** + * Get the metrics context. For hadoop metrics2 system this is usually an all lowercased string. + * eg. regionserver, master, thriftserver + * + * @return The string context used to register this source to hadoop's metrics2 system. + */ + public String getMetricsContext() { + return metricsContext; + } + + /** + * Get the description of what this source exposes. + */ + public String getMetricsDescription() { + return metricsDescription; + } + + /** + * Get the name of the context in JMX that this source will be exposed through. + * This is in ObjectName format. With the default context being Hadoop -> HBase + */ + public String getMetricsJmxContext() { + return metricsJmxContext; + } + + /** + * Get the name of the metrics that are being exported by this source. + * Eg. IPC, GC, WAL + */ + public String getMetricsName() { + return metricsName; + } + + /** + * Returns whether or not this MetricRegistry is for an existing BaseSource + * @return true if this MetricRegistry is for an existing BaseSource. + */ + public boolean isExistingSource() { + return existingSource; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof MetricRegistryInfo) { + return this.hashCode() == obj.hashCode(); + } else { + return false; + } + } + + @Override + public int hashCode() { + return new HashCodeBuilder() + .append(metricsName) + .append(metricsDescription) + .append(metricsContext) + .append(metricsJmxContext) + .hashCode(); + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricSet.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricSet.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricSet.java new file mode 100644 index 0000000..9cf2378 --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/MetricSet.java @@ -0,0 +1,41 @@ +/** + * 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.hadoop.hbase.metrics; + +import java.util.Map; + +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; + +/** + * A set of named metrics. + * + * @see MetricRegistry#registerAll(MetricSet) + */ [email protected](HBaseInterfaceAudience.COPROC) [email protected] +public interface MetricSet extends Metric { + /** + * A map of metric names to metrics. + * + * @return the metrics + */ + Map<String, Metric> getMetrics(); +} http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/PackageMarker.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/PackageMarker.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/PackageMarker.java new file mode 100644 index 0000000..a5f6f60 --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/PackageMarker.java @@ -0,0 +1,38 @@ +/** + * 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.hadoop.hbase.metrics; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import org.apache.hadoop.hbase.classification.InterfaceAudience; + +/** + * This is a dummy annotation that forces javac to produce output for + * otherwise empty package-info.java. + * + * <p>The result is maven-compiler-plugin can properly identify the scope of + * changed files + * + * <p>See more details in + * <a href="https://jira.codehaus.org/browse/MCOMPILER-205"> + * maven-compiler-plugin: incremental compilation broken</a> + */ [email protected] +@Retention(RetentionPolicy.SOURCE) +public @interface PackageMarker { +} http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Snapshot.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Snapshot.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Snapshot.java new file mode 100644 index 0000000..56ee8ae --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Snapshot.java @@ -0,0 +1,136 @@ +/** + * + * 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.hadoop.hbase.metrics; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; + +/** + * A statictical sample of histogram values. + */ [email protected] +public interface Snapshot { + + /** + * Return the values with the given quantiles. + * @param quantiles the requested quantiles. + * @return the value for the quantiles. + */ + long[] getQuantiles(double[] quantiles); + + /** + * Return the values with the default quantiles. + * @return the value for default the quantiles. + */ + long[] getQuantiles(); + + /** + * Returns the number of values in the snapshot. + * + * @return the number of values + */ + long getCount(); + + /** + * Returns the total count below the given value + * @param val the value + * @return the total count below the given value + */ + long getCountAtOrBelow(long val); + + /** + * Returns the value at the 25th percentile in the distribution. + * + * @return the value at the 25th percentile + */ + long get25thPercentile(); + + /** + * Returns the value at the 75th percentile in the distribution. + * + * @return the value at the 75th percentile + */ + long get75thPercentile(); + + /** + * Returns the value at the 90th percentile in the distribution. + * + * @return the value at the 90th percentile + */ + long get90thPercentile(); + + /** + * Returns the value at the 95th percentile in the distribution. + * + * @return the value at the 95th percentile + */ + long get95thPercentile(); + + /** + * Returns the value at the 98th percentile in the distribution. + * + * @return the value at the 98th percentile + */ + long get98thPercentile(); + + /** + * Returns the value at the 99th percentile in the distribution. + * + * @return the value at the 99th percentile + */ + long get99thPercentile(); + + /** + * Returns the value at the 99.9th percentile in the distribution. + * + * @return the value at the 99.9th percentile + */ + long get999thPercentile(); + + /** + * Returns the median value in the distribution. + * + * @return the median value + */ + long getMedian(); + + /** + * Returns the highest value in the snapshot. + * + * @return the highest value + */ + long getMax(); + + /** + * Returns the arithmetic mean of the values in the snapshot. + * + * @return the arithmetic mean + */ + long getMean(); + + /** + * Returns the lowest value in the snapshot. + * + * @return the lowest value + */ + long getMin(); + + // TODO: Dropwizard histograms also track stddev +} http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Timer.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Timer.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Timer.java new file mode 100644 index 0000000..4fcb636 --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/Timer.java @@ -0,0 +1,62 @@ +/** + * 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.hadoop.hbase.metrics; + +import java.util.concurrent.TimeUnit; + +import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; + +/** + * A metric which encompasses a {@link Histogram} and {@link Meter}. + */ [email protected](HBaseInterfaceAudience.COPROC) [email protected] +public interface Timer extends Metric { + /** + * Update the timer with the given duration in given time unit. + * @param duration the duration of the event + * @param unit the time unit for the duration + */ + void update(long duration, TimeUnit unit); + + /** + * Update the timer with the given duration in milliseconds + * @param durationMillis the duration of the event in ms + */ + void updateMillis(long durationMillis); + + /** + * Update the timer with the given duration in microseconds + * @param durationMicros the duration of the event in microseconds + */ + void updateMicros(long durationMicros); + + /** + * Update the timer with the given duration in nanoseconds + * @param durationNanos the duration of the event in ns + */ + void updateNanos(long durationNanos); + + @InterfaceAudience.Private + Histogram getHistogram(); + + @InterfaceAudience.Private + Meter getMeter(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/package-info.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/package-info.java b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/package-info.java new file mode 100644 index 0000000..e79451f --- /dev/null +++ b/hbase-metrics-api/src/main/java/org/apache/hadoop/hbase/metrics/package-info.java @@ -0,0 +1,25 @@ +/** + * 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. + */ + +/** + * Metrics API for HBase. + */ +@PackageMarker +package org.apache.hadoop.hbase.metrics; + +// End package-info.java http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics-api/src/test/java/org/apache/hadoop/hbase/metrics/TestMetricRegistriesLoader.java ---------------------------------------------------------------------- diff --git a/hbase-metrics-api/src/test/java/org/apache/hadoop/hbase/metrics/TestMetricRegistriesLoader.java b/hbase-metrics-api/src/test/java/org/apache/hadoop/hbase/metrics/TestMetricRegistriesLoader.java new file mode 100644 index 0000000..8746146 --- /dev/null +++ b/hbase-metrics-api/src/test/java/org/apache/hadoop/hbase/metrics/TestMetricRegistriesLoader.java @@ -0,0 +1,56 @@ +/** + * 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.hadoop.hbase.metrics; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.mockito.Mockito.mock; + +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import com.google.common.collect.Lists; + +/** + * Test class for {@link MetricRegistriesLoader}. + */ +@Category(SmallTests.class) +public class TestMetricRegistriesLoader { + + @Test + public void testLoadSinleInstance() { + MetricRegistries loader = mock(MetricRegistries.class); + MetricRegistries instance = MetricRegistriesLoader.load(Lists.newArrayList(loader)); + assertEquals(loader, instance); + } + + @Test + public void testLoadMultipleInstances() { + MetricRegistries loader1 = mock(MetricRegistries.class); + MetricRegistries loader2 = mock(MetricRegistries.class); + MetricRegistries loader3 = mock(MetricRegistries.class); + MetricRegistries instance = MetricRegistriesLoader.load(Lists.newArrayList(loader1, loader2, + loader3)); + + // the load() returns the first instance + assertEquals(loader1, instance); + assertNotEquals(loader2, instance); + assertNotEquals(loader3, instance); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics/README.txt ---------------------------------------------------------------------- diff --git a/hbase-metrics/README.txt b/hbase-metrics/README.txt new file mode 100644 index 0000000..d80064c --- /dev/null +++ b/hbase-metrics/README.txt @@ -0,0 +1 @@ +See the documentation at hbase-metrics-api/README. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics/pom.xml ---------------------------------------------------------------------- diff --git a/hbase-metrics/pom.xml b/hbase-metrics/pom.xml new file mode 100644 index 0000000..e32db77 --- /dev/null +++ b/hbase-metrics/pom.xml @@ -0,0 +1,136 @@ +<?xml version="1.0"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <!-- + /** + * 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. + */ + --> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>hbase</artifactId> + <groupId>org.apache.hbase</groupId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + + <artifactId>hbase-metrics</artifactId> + <name>Apache HBase - Metrics Implementation</name> + <description>HBase Metrics Implementation</description> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-site-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <!-- Make a jar and put the sources in the jar --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + </plugin> + <plugin> + <!--Make it so assembly:single does nothing in here--> + <artifactId>maven-assembly-plugin</artifactId> + <version>${maven.assembly.version}</version> + <configuration> + <skipAssembly>true</skipAssembly> + </configuration> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <!-- Always skip the second part executions, since we only run simple unit tests in this module --> + <executions> + <execution> + <id>secondPartTestsExecution</id> + <phase>test</phase> + <goals> + <goal>test</goal> + </goals> + <configuration> + <skip>true</skip> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <dependencies> + <!-- Intra-project dependencies --> + <dependency> + <groupId>org.apache.hbase</groupId> + <artifactId>hbase-annotations</artifactId> + </dependency> + <dependency> + <groupId>org.apache.hbase</groupId> + <artifactId>hbase-annotations</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.hbase</groupId> + <artifactId>hbase-common</artifactId> + </dependency> + <dependency> + <groupId>org.apache.hbase</groupId> + <artifactId>hbase-metrics-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.hbase</groupId> + <artifactId>hbase-metrics-api</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <!-- General dependencies --> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + <dependency> + <groupId>io.dropwizard.metrics</groupId> + <artifactId>metrics-core</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <profiles> + <!-- Skip the tests in this module --> + <profile> + <id>skip-metrics-tests</id> + <activation> + <property> + <name>skip-metrics-tests</name> + </property> + </activation> + <properties> + <surefire.skipFirstPart>true</surefire.skipFirstPart> + </properties> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/CounterImpl.java ---------------------------------------------------------------------- diff --git a/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/CounterImpl.java b/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/CounterImpl.java new file mode 100644 index 0000000..28ac08b --- /dev/null +++ b/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/CounterImpl.java @@ -0,0 +1,60 @@ +/** + * 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.hadoop.hbase.metrics.impl; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.metrics.Counter; +import org.apache.hadoop.hbase.util.LongAdder; + +/** + * Custom implementation of {@link org.apache.hadoop.hbase.metrics.Counter} using LongAdder. + */ [email protected] +public class CounterImpl implements Counter { + + private final LongAdder counter; + + public CounterImpl() { + this.counter = new LongAdder(); + } + + @Override + public void increment() { + this.counter.increment(); + } + + @Override + public void increment(long n) { + this.counter.add(n); + } + + @Override + public void decrement() { + this.counter.decrement(); + } + + @Override + public void decrement(long n) { + this.counter.add(-n); + } + + @Override + public long getCount() { + return this.counter.sum(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hbase/blob/a3c3f101/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/DropwizardMeter.java ---------------------------------------------------------------------- diff --git a/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/DropwizardMeter.java b/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/DropwizardMeter.java new file mode 100644 index 0000000..fc92483 --- /dev/null +++ b/hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/DropwizardMeter.java @@ -0,0 +1,74 @@ +/** + * 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.hadoop.hbase.metrics.impl; + +import java.util.Objects; + +import org.apache.hadoop.hbase.classification.InterfaceAudience; + +import com.codahale.metrics.Meter; + +/** + * Dropwizard metrics implementation of {@link org.apache.hadoop.hbase.metrics.Meter}. + */ [email protected] +public class DropwizardMeter implements org.apache.hadoop.hbase.metrics.Meter { + + private final Meter meter; + + public DropwizardMeter() { + this.meter = new Meter(); + } + + public DropwizardMeter(Meter meter) { + this.meter = Objects.requireNonNull(meter); + } + + @Override public void mark() { + this.meter.mark(); + } + + @Override public void mark(long count) { + this.meter.mark(count); + } + + @Override + public long getCount() { + return meter.getCount(); + } + + @Override + public double getMeanRate() { + return meter.getMeanRate(); + } + + @Override + public double getOneMinuteRate() { + return meter.getOneMinuteRate(); + } + + @Override + public double getFiveMinuteRate() { + return meter.getFiveMinuteRate(); + } + + @Override + public double getFifteenMinuteRate() { + return meter.getFifteenMinuteRate(); + } +} \ No newline at end of file
