You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ac...@apache.org on 2011/05/06 09:28:46 UTC
svn commit: r1100113 [1/5] - in /hadoop/common/trunk: ./ conf/ ivy/
src/java/org/apache/hadoop/metrics/file/ src/java/org/apache/hadoop/metrics2/
src/java/org/apache/hadoop/metrics2/annotation/
src/java/org/apache/hadoop/metrics2/filter/ src/java/org/a...
Author: acmurthy
Date: Fri May 6 07:28:43 2011
New Revision: 1100113
URL: http://svn.apache.org/viewvc?rev=1100113&view=rev
Log:
HADOOP-6919. New metrics2 framework. Contributed by Luke Lu.
Added:
hadoop/common/trunk/conf/hadoop-metrics2.properties
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/AbstractMetric.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricType.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsCollector.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsException.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsFilter.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsInfo.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsPlugin.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsRecord.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsRecordBuilder.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSink.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSource.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSystem.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSystemMXBean.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsTag.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsVisitor.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/Metric.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/Metrics.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/package-info.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/AbstractPatternFilter.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/GlobFilter.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/RegexFilter.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/package-info.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/AbstractMetricsRecord.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MBeanInfoBuilder.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricCounterInt.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricCounterLong.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeDouble.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeFloat.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeInt.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeLong.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsBuffer.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsBufferBuilder.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsCollectorImpl.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsConfigException.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsRecordBuilderImpl.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsRecordFiltered.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsRecordImpl.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsSinkAdapter.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsSourceAdapter.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MsInfo.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/SinkQueue.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/package-info.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/DefaultMetricsFactory.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/DefaultMetricsSystem.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/Interns.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MethodMetric.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MetricsAnnotations.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MetricsInfoImpl.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MetricsRegistry.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MetricsSourceBuilder.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MutableCounter.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MutableCounterInt.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MutableCounterLong.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MutableGauge.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MutableGaugeInt.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MutableGaugeLong.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MutableMetric.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MutableMetricsFactory.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MutableRate.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MutableRates.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/MutableStat.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/UniqueNames.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/lib/package-info.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/package-info.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/sink/
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/sink/FileSink.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/sink/package-info.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/source/
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/source/JvmMetrics.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/util/
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/util/Contracts.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/util/MBeans.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/util/MetricsCache.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/util/SampleStat.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/util/Servers.java
hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/util/package-info.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/filter/
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/filter/TestPatternFilter.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/ConfigBuilder.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/ConfigUtil.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/MetricsLists.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsCollectorImpl.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsConfig.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/TestMetricsVisitor.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/impl/TestSinkQueue.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/lib/
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/lib/TestInterns.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/lib/TestMetricsAnnotations.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/lib/TestMetricsRegistry.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/lib/TestMutableMetrics.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/lib/TestUniqNames.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/util/
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/util/TestMetricsCache.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/metrics2/util/TestSampleStat.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/test/MetricsAsserts.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/test/MoreAsserts.java
Modified:
hadoop/common/trunk/CHANGES.txt
hadoop/common/trunk/build.xml
hadoop/common/trunk/ivy.xml
hadoop/common/trunk/ivy/hadoop-common-template.xml
hadoop/common/trunk/ivy/hadoop-common-test-template.xml
hadoop/common/trunk/ivy/libraries.properties
hadoop/common/trunk/src/java/org/apache/hadoop/metrics/file/FileContext.java
Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=1100113&r1=1100112&r2=1100113&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Fri May 6 07:28:43 2011
@@ -24,6 +24,8 @@ Trunk (unreleased changes)
HADOOP-7257 Client side mount tables (sanjay)
+ HADOOP-6919. New metrics2 framework. (Luke Lu via acmurthy)
+
IMPROVEMENTS
HADOOP-7042. Updates to test-patch.sh to include failed test names and
Modified: hadoop/common/trunk/build.xml
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/build.xml?rev=1100113&r1=1100112&r2=1100113&view=diff
==============================================================================
--- hadoop/common/trunk/build.xml (original)
+++ hadoop/common/trunk/build.xml Fri May 6 07:28:43 2011
@@ -519,6 +519,13 @@
</jar>
</target>
+ <target name="metrics2.jar" depends="compile-core" description="Make the Hadoop metrics2 framework jar (for use plugin development)">
+ <jar jarfile="${build.dir}/hadoop-metrics2-${version}.jar"
+ basedir="${build.classes}">
+ <include name="**/metrics2/**" />
+ </jar>
+ </target>
+
<target name="generate-test-records" depends="compile-rcc-compiler">
<recordcc destdir="${test.generated.dir}">
<fileset dir="${test.src.dir}"
Added: hadoop/common/trunk/conf/hadoop-metrics2.properties
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/conf/hadoop-metrics2.properties?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/conf/hadoop-metrics2.properties (added)
+++ hadoop/common/trunk/conf/hadoop-metrics2.properties Fri May 6 07:28:43 2011
@@ -0,0 +1,16 @@
+# syntax: [prefix].[source|sink].[instance].[options]
+# See javadoc of package-info.java for org.apache.hadoop.metrics2 for details
+
+*.sink.file.class=org.apache.hadoop.metrics2.sink.FileSink
+
+#namenode.sink.file.filename=namenode-metrics.out
+
+#datanode.sink.file.filename=datanode-metrics.out
+
+#jobtracker.sink.file.filename=jobtracker-metrics.out
+
+#tasktracker.sink.file.filename=tasktracker-metrics.out
+
+#maptask.sink.file.filename=maptask-metrics.out
+
+#reducetask.sink.file.filename=reducetask-metrics.out
Modified: hadoop/common/trunk/ivy.xml
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/ivy.xml?rev=1100113&r1=1100112&r2=1100113&view=diff
==============================================================================
--- hadoop/common/trunk/ivy.xml (original)
+++ hadoop/common/trunk/ivy.xml Fri May 6 07:28:43 2011
@@ -301,5 +301,17 @@
rev="${jsch.version}"
conf="common->default">
</dependency>
- </dependencies>
+ <dependency org="commons-configuration"
+ name="commons-configuration"
+ rev="${commons-configuration.version}"
+ conf="common->default"/>
+ <dependency org="org.apache.commons"
+ name="commons-math"
+ rev="${commons-math.version}"
+ conf="common->default"/>
+ <dependency org="com.google.guava"
+ name="guava"
+ rev="${guava.version}"
+ conf="common->default"/>
+ </dependencies>
</ivy-module>
Modified: hadoop/common/trunk/ivy/hadoop-common-template.xml
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/ivy/hadoop-common-template.xml?rev=1100113&r1=1100112&r2=1100113&view=diff
==============================================================================
--- hadoop/common/trunk/ivy/hadoop-common-template.xml (original)
+++ hadoop/common/trunk/ivy/hadoop-common-template.xml Fri May 6 07:28:43 2011
@@ -135,5 +135,20 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math</artifactId>
+ <version>2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>r07</version>
+ </dependency>
</dependencies>
</project>
Modified: hadoop/common/trunk/ivy/hadoop-common-test-template.xml
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/ivy/hadoop-common-test-template.xml?rev=1100113&r1=1100112&r2=1100113&view=diff
==============================================================================
--- hadoop/common/trunk/ivy/hadoop-common-test-template.xml (original)
+++ hadoop/common/trunk/ivy/hadoop-common-test-template.xml Fri May 6 07:28:43 2011
@@ -49,5 +49,10 @@
<artifactId>ftpserver-deprecated</artifactId>
<version>1.0.0-M2</version>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.8.5</version>
+ </dependency>
</dependencies>
</project>
Modified: hadoop/common/trunk/ivy/libraries.properties
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/ivy/libraries.properties?rev=1100113&r1=1100112&r2=1100113&view=diff
==============================================================================
--- hadoop/common/trunk/ivy/libraries.properties (original)
+++ hadoop/common/trunk/ivy/libraries.properties Fri May 6 07:28:43 2011
@@ -24,6 +24,7 @@ commons-cli.version=1.2
commons-cli2.version=2.0-mahout
commons-codec.version=1.4
commons-collections.version=3.1
+commons-configuration.version=1.6
commons-httpclient.version=3.1
commons-lang.version=2.5
commons-logging.version=1.1.1
@@ -31,6 +32,7 @@ commons-logging-api.version=1.1
commons-el.version=1.0
commons-fileupload.version=1.2
commons-io.version=1.4
+commons-math.version=2.1
commons-net.version=1.4.1
core.version=3.1.1
coreplugin.version=1.3.2
@@ -39,6 +41,8 @@ ftplet-api.version=1.0.0
ftpserver-core.version=1.0.0
ftpserver-deprecated.version=1.0.0-M2
+guava.version=r09
+
hsqldb.version=1.8.0.10
ivy.version=2.1.0
@@ -77,7 +81,7 @@ xerces.version=1.4.4
aspectj.version=1.6.5
-mockito-all.version=1.8.2
+mockito-all.version=1.8.5
jsch.version=0.1.42
Modified: hadoop/common/trunk/src/java/org/apache/hadoop/metrics/file/FileContext.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics/file/FileContext.java?rev=1100113&r1=1100112&r2=1100113&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics/file/FileContext.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics/file/FileContext.java Fri May 6 07:28:43 2011
@@ -42,9 +42,11 @@ import org.apache.hadoop.metrics.spi.Out
* myContextName.fileName=/tmp/metrics.log
* myContextName.period=5
* </pre>
+ * @deprecated use {@link org.apache.hadoop.metrics2.sink.FileSink} instead.
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
+@Deprecated
public class FileContext extends AbstractMetricsContext {
/* Configuration attribute names */
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/AbstractMetric.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/AbstractMetric.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/AbstractMetric.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/AbstractMetric.java Fri May 6 07:28:43 2011
@@ -0,0 +1,92 @@
+/**
+ * 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.metrics2;
+
+import com.google.common.base.Objects;
+import static com.google.common.base.Preconditions.*;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * The immutable metric
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public abstract class AbstractMetric implements MetricsInfo {
+ private final MetricsInfo info;
+
+ /**
+ * Construct the metric
+ * @param info about the metric
+ */
+ protected AbstractMetric(MetricsInfo info) {
+ this.info = checkNotNull(info, "metric info");
+ }
+
+ @Override public String name() {
+ return info.name();
+ }
+
+ @Override public String description() {
+ return info.description();
+ }
+
+ protected MetricsInfo info() {
+ return info;
+ }
+
+ /**
+ * Get the value of the metric
+ * @return the value of the metric
+ */
+ public abstract Number value();
+
+ /**
+ * Get the type of the metric
+ * @return the type of the metric
+ */
+ public abstract MetricType type();
+
+ /**
+ * Accept a visitor interface
+ * @param visitor of the metric
+ */
+ public abstract void visit(MetricsVisitor visitor);
+
+ @Override public boolean equals(Object obj) {
+ if (obj instanceof AbstractMetric) {
+ final AbstractMetric other = (AbstractMetric) obj;
+ return Objects.equal(info, other.info()) &&
+ Objects.equal(value(), other.value());
+ }
+ return false;
+ }
+
+ @Override public int hashCode() {
+ return Objects.hashCode(info, value());
+ }
+
+ @Override public String toString() {
+ return Objects.toStringHelper(this)
+ .add("info", info)
+ .add("value", value())
+ .toString();
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricType.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricType.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricType.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricType.java Fri May 6 07:28:43 2011
@@ -0,0 +1,31 @@
+/*
+ * 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.metrics2;
+
+public enum MetricType {
+ /**
+ * A monotonically increasing metric that can be used
+ * to calculate throughput
+ */
+ COUNTER,
+
+ /**
+ * An arbitrary varying metric
+ */
+ GAUGE
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsCollector.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsCollector.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsCollector.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsCollector.java Fri May 6 07:28:43 2011
@@ -0,0 +1,43 @@
+/**
+ * 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.metrics2;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * The metrics collector interface
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public interface MetricsCollector {
+ /**
+ * Add a metrics record
+ * @param name of the record
+ * @return a metrics record builder for the record
+ */
+ public MetricsRecordBuilder addRecord(String name);
+
+ /**
+ * Add a metrics record
+ * @param info of the record
+ * @return a metrics record builder for the record
+ */
+ public MetricsRecordBuilder addRecord(MetricsInfo info);
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsException.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsException.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsException.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsException.java Fri May 6 07:28:43 2011
@@ -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.metrics2;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * A general metrics exception wrapper
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public class MetricsException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct the exception with a message
+ * @param message for the exception
+ */
+ public MetricsException(String message) {
+ super(message);
+ }
+
+ /**
+ * Construct the exception with a message and a cause
+ * @param message for the exception
+ * @param cause of the exception
+ */
+ public MetricsException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Construct the exception with a cause
+ * @param cause of the exception
+ */
+ public MetricsException(Throwable cause) {
+ super(cause);
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsFilter.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsFilter.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsFilter.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsFilter.java Fri May 6 07:28:43 2011
@@ -0,0 +1,61 @@
+/**
+ * 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.metrics2;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * The metrics filter interface
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public abstract class MetricsFilter implements MetricsPlugin {
+
+ /**
+ * Whether to accept the name
+ * @param name to filter on
+ * @return true to accept; false otherwise.
+ */
+ public abstract boolean accepts(String name);
+
+ /**
+ * Whether to accept the tag
+ * @param tag to filter on
+ * @return true to accept; false otherwise
+ */
+ public abstract boolean accepts(MetricsTag tag);
+
+ /**
+ * Whether to accept the tags
+ * @param tags to filter on
+ * @return true to accept; false otherwise
+ */
+ public abstract boolean accepts(Iterable<MetricsTag> tags);
+
+ /**
+ * Whether to accept the record
+ * @param record to filter on
+ * @return true to accept; false otherwise.
+ */
+ public boolean accepts(MetricsRecord record) {
+ return accepts(record.tags());
+ }
+
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsInfo.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsInfo.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsInfo.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsInfo.java Fri May 6 07:28:43 2011
@@ -0,0 +1,39 @@
+/**
+ * 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.metrics2;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * Interface to provide immutable meta info for metrics
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public interface MetricsInfo {
+ /**
+ * @return the name of the metric/tag
+ */
+ String name();
+
+ /**
+ * @return the description of the metric/tag
+ */
+ String description();
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsPlugin.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsPlugin.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsPlugin.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsPlugin.java Fri May 6 07:28:43 2011
@@ -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.metrics2;
+
+import org.apache.commons.configuration.SubsetConfiguration;
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * The plugin interface for the metrics framework
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public interface MetricsPlugin {
+ /**
+ * Initialize the plugin
+ * @param conf the configuration object for the plugin
+ */
+ void init(SubsetConfiguration conf);
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsRecord.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsRecord.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsRecord.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsRecord.java Fri May 6 07:28:43 2011
@@ -0,0 +1,66 @@
+/**
+ * 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.metrics2;
+
+import java.util.Collection;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * An immutable snapshot of metrics with a timestamp
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public interface MetricsRecord {
+ /**
+ * Get the timestamp of the metrics
+ * @return the timestamp
+ */
+ long timestamp();
+
+ /**
+ * @return the record name
+ */
+ String name();
+
+ /**
+ * @return the description of the record
+ */
+ String description();
+
+ /**
+ * @return the context name of the record
+ */
+ String context();
+
+ /**
+ * Get the tags of the record
+ * Note: returning a collection instead of iterable as we
+ * need to use tags as keys (hence Collection#hashCode etc.) in maps
+ * @return an unmodifiable collection of tags
+ */
+ Collection<MetricsTag> tags();
+
+ /**
+ * Get the metrics of the record
+ * @return an immutable iterable interface for metrics
+ */
+ Iterable<AbstractMetric> metrics();
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsRecordBuilder.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsRecordBuilder.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsRecordBuilder.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsRecordBuilder.java Fri May 6 07:28:43 2011
@@ -0,0 +1,117 @@
+/**
+ * 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.metrics2;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * The metrics record builder interface
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public abstract class MetricsRecordBuilder {
+ /**
+ * Add a metrics tag
+ * @param info metadata of the tag
+ * @param value of the tag
+ * @return self
+ */
+ public abstract MetricsRecordBuilder tag(MetricsInfo info, String value);
+
+ /**
+ * Add an immutable metrics tag object
+ * @param tag a pre-made tag object (potentially save an object construction)
+ * @return self
+ */
+ public abstract MetricsRecordBuilder add(MetricsTag tag);
+
+ /**
+ * Add a pre-made immutable metric object
+ * @param metric the pre-made metric to save an object construction
+ * @return self
+ */
+ public abstract MetricsRecordBuilder add(AbstractMetric metric);
+
+ /**
+ * Set the context tag
+ * @param value of the context
+ * @return self
+ */
+ public abstract MetricsRecordBuilder setContext(String value);
+
+ /**
+ * Add an integer metric
+ * @param info metadata of the metric
+ * @param value of the metric
+ * @return self
+ */
+ public abstract MetricsRecordBuilder addCounter(MetricsInfo info, int value);
+
+ /**
+ * Add an long metric
+ * @param info metadata of the metric
+ * @param value of the metric
+ * @return self
+ */
+ public abstract MetricsRecordBuilder addCounter(MetricsInfo info, long value);
+
+ /**
+ * Add a integer gauge metric
+ * @param info metadata of the metric
+ * @param value of the metric
+ * @return self
+ */
+ public abstract MetricsRecordBuilder addGauge(MetricsInfo info, int value);
+
+ /**
+ * Add a long gauge metric
+ * @param info metadata of the metric
+ * @param value of the metric
+ * @return self
+ */
+ public abstract MetricsRecordBuilder addGauge(MetricsInfo info, long value);
+
+ /**
+ * Add a float gauge metric
+ * @param info metadata of the metric
+ * @param value of the metric
+ * @return self
+ */
+ public abstract MetricsRecordBuilder addGauge(MetricsInfo info, float value);
+
+ /**
+ * Add a double gauge metric
+ * @param info metadata of the metric
+ * @param value of the metric
+ * @return self
+ */
+ public abstract MetricsRecordBuilder addGauge(MetricsInfo info, double value);
+
+ /**
+ * @return the parent metrics collector object
+ */
+ public abstract MetricsCollector parent();
+
+ /**
+ * Syntactic sugar to add multiple records in a collector in a one liner.
+ * @return the parent metrics collector object
+ */
+ public MetricsCollector endRecord() { return parent(); }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSink.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSink.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSink.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSink.java Fri May 6 07:28:43 2011
@@ -0,0 +1,40 @@
+/**
+ * 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.metrics2;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * The metrics sink interface
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public interface MetricsSink extends MetricsPlugin {
+ /**
+ * Put a metrics record in the sink
+ * @param record the record to put
+ */
+ void putMetrics(MetricsRecord record);
+
+ /**
+ * Flush any buffered metrics
+ */
+ void flush();
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSource.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSource.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSource.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSource.java Fri May 6 07:28:43 2011
@@ -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.metrics2;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * The metrics source interface
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public interface MetricsSource {
+ /**
+ * Get metrics from the source
+ * @param collector to contain the resulting metrics snapshot
+ * @param all if true, return all metrics even if unchanged.
+ */
+ void getMetrics(MetricsCollector collector, boolean all);
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSystem.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSystem.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSystem.java Fri May 6 07:28:43 2011
@@ -0,0 +1,123 @@
+/**
+ * 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.metrics2;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * The metrics system interface
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public abstract class MetricsSystem implements MetricsSystemMXBean {
+
+ @InterfaceAudience.Private
+ public abstract MetricsSystem init(String prefix);
+
+ /**
+ * Register a metrics source
+ * @param <T> the actual type of the source object
+ * @param source object to register
+ * @param name of the source. Must be unique or null (then extracted from
+ * the annotations of the source object.)
+ * @param desc the description of the source (or null. See above.)
+ * @return the source object
+ * @exception MetricsException
+ */
+ public abstract <T> T register(String name, String desc, T source);
+
+ /**
+ * Register a metrics source (deriving name and description from the object)
+ * @param <T> the actual type of the source object
+ * @param source object to register
+ * @return the source object
+ * @exception MetricsException
+ */
+ public <T> T register(T source) {
+ return register(null, null, source);
+ }
+
+ /**
+ * @param name of the metrics source
+ * @return the metrics source (potentially wrapped) object
+ */
+ @InterfaceAudience.Private
+ public abstract MetricsSource getSource(String name);
+
+ /**
+ * Register a metrics sink
+ * @param <T> the type of the sink
+ * @param sink to register
+ * @param name of the sink. Must be unique.
+ * @param desc the description of the sink
+ * @return the sink
+ * @exception MetricsException
+ */
+ public abstract <T extends MetricsSink>
+ T register(String name, String desc, T sink);
+
+ /**
+ * Register a callback interface for JMX events
+ * @param callback the callback object implementing the MBean interface.
+ */
+ public abstract void register(Callback callback);
+
+ /**
+ * Shutdown the metrics system completely (usually during server shutdown.)
+ * The MetricsSystemMXBean will be unregistered.
+ * @return true if shutdown completed
+ */
+ public abstract boolean shutdown();
+
+ /**
+ * The metrics system callback interface (needed for proxies.)
+ */
+ public interface Callback {
+ /**
+ * Called before start()
+ */
+ void preStart();
+
+ /**
+ * Called after start()
+ */
+ void postStart();
+
+ /**
+ * Called before stop()
+ */
+ void preStop();
+
+ /**
+ * Called after stop()
+ */
+ void postStop();
+ }
+
+ /**
+ * Convenient abstract class for implementing callback interface
+ */
+ public static abstract class AbstractCallback implements Callback {
+ @Override public void preStart() {}
+ @Override public void postStart() {}
+ @Override public void preStop() {}
+ @Override public void postStop() {}
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSystemMXBean.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSystemMXBean.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSystemMXBean.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsSystemMXBean.java Fri May 6 07:28:43 2011
@@ -0,0 +1,63 @@
+/**
+ * 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.metrics2;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * The JMX interface to the metrics system
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public interface MetricsSystemMXBean {
+ /**
+ * Start the metrics system
+ * @throws MetricsException
+ */
+ public void start();
+
+ /**
+ * Stop the metrics system
+ * @throws MetricsException
+ */
+ public void stop();
+
+ /**
+ * Start metrics MBeans
+ * @throws MetricsException
+ */
+ public void startMetricsMBeans();
+
+ /**
+ * Stop metrics MBeans.
+ * Note, it doesn't stop the metrics system control MBean,
+ * i.e this interface.
+ * @throws MetricsException
+ */
+ public void stopMetricsMBeans();
+
+ /**
+ * @return the current config
+ * Avoided getConfig, as it'll turn into a "Config" attribute,
+ * which doesn't support multiple line values in jconsole.
+ * @throws MetricsException
+ */
+ public String currentConfig();
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsTag.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsTag.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsTag.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsTag.java Fri May 6 07:28:43 2011
@@ -0,0 +1,88 @@
+/**
+ * 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.metrics2;
+
+import com.google.common.base.Objects;
+import static com.google.common.base.Preconditions.*;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * Immutable tag for metrics (for grouping on host/queue/username etc.)
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public class MetricsTag implements MetricsInfo {
+ private final MetricsInfo info;
+ private final String value;
+
+ /**
+ * Construct the tag with name, description and value
+ * @param info of the tag
+ * @param value of the tag
+ */
+ public MetricsTag(MetricsInfo info, String value) {
+ this.info = checkNotNull(info, "tag info");
+ this.value = value;
+ }
+
+ @Override public String name() {
+ return info.name();
+ }
+
+ @Override public String description() {
+ return info.description();
+ }
+
+ /**
+ * @return the info object of the tag
+ */
+ public MetricsInfo info() {
+ return info;
+ }
+
+ /**
+ * Get the value of the tag
+ * @return the value
+ */
+ public String value() {
+ return value;
+ }
+
+ @Override public boolean equals(Object obj) {
+ if (obj instanceof MetricsTag) {
+ final MetricsTag other = (MetricsTag) obj;
+ return Objects.equal(info, other.info()) &&
+ Objects.equal(value, other.value());
+ }
+ return false;
+ }
+
+ @Override public int hashCode() {
+ return Objects.hashCode(info, value);
+ }
+
+ @Override public String toString() {
+ return Objects.toStringHelper(this)
+ .add("info", info)
+ .add("value", value())
+ .toString();
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsVisitor.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsVisitor.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsVisitor.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/MetricsVisitor.java Fri May 6 07:28:43 2011
@@ -0,0 +1,71 @@
+/**
+ * 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.metrics2;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * A visitor interface for metrics
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public interface MetricsVisitor {
+ /**
+ * Callback for integer value gauges
+ * @param info the metric info
+ * @param value of the metric
+ */
+ public void gauge(MetricsInfo info, int value);
+
+ /**
+ * Callback for long value gauges
+ * @param info the metric info
+ * @param value of the metric
+ */
+ public void gauge(MetricsInfo info, long value);
+
+ /**
+ * Callback for float value gauges
+ * @param info the metric info
+ * @param value of the metric
+ */
+ public void gauge(MetricsInfo info, float value);
+
+ /**
+ * Callback for double value gauges
+ * @param info the metric info
+ * @param value of the metric
+ */
+ public void gauge(MetricsInfo info, double value);
+
+ /**
+ * Callback for integer value counters
+ * @param info the metric info
+ * @param value of the metric
+ */
+ public void counter(MetricsInfo info, int value);
+
+ /**
+ * Callback for long value counters
+ * @param info the metric info
+ * @param value of the metric
+ */
+ public void counter(MetricsInfo info, long value);
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/Metric.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/Metric.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/Metric.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/Metric.java Fri May 6 07:28:43 2011
@@ -0,0 +1,70 @@
+/**
+ * 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.metrics2.annotation;
+
+import java.lang.annotation.*;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * Annotation interface for a single metric
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+@Documented
+@Target({ElementType.FIELD, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Metric {
+
+ public enum Type {
+ DEFAULT, COUNTER, GAUGE, TAG
+ }
+
+ /**
+ * Shorthand for optional name and description
+ * @return {description} or {name, description}
+ */
+ String[] value() default {};
+
+ /**
+ * @return optional description of the metric
+ */
+ String about() default "";
+
+ /**
+ * @return optional sample name for MutableStat/Rate/Rates
+ */
+ String sampleName() default "Ops";
+
+ /**
+ * @return optional value name for MutableStat/Rate/Rates
+ */
+ String valueName() default "Time";
+
+ /**
+ * @return true to create a metric snapshot even if unchanged.
+ */
+ boolean always() default false;
+
+ /**
+ * @return optional type (counter|gauge) of the metric
+ */
+ Type type() default Type.DEFAULT;
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/Metrics.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/Metrics.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/Metrics.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/Metrics.java Fri May 6 07:28:43 2011
@@ -0,0 +1,50 @@
+/**
+ * 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.metrics2.annotation;
+
+import java.lang.annotation.*;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * Annotation interface for a group of metrics
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+@Documented
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Metrics {
+
+ /**
+ * @return the (record) name of the metrics
+ */
+ String name() default "";
+
+ /**
+ * @return the optional description of metrics
+ */
+ String about() default "";
+
+ /**
+ * @return the context name for a group of metrics
+ */
+ String context();
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/package-info.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/package-info.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/package-info.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/annotation/package-info.java Fri May 6 07:28:43 2011
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+/**
+ * Annotation interfaces for metrics instrumentation
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+package org.apache.hadoop.metrics2.annotation;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/AbstractPatternFilter.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/AbstractPatternFilter.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/AbstractPatternFilter.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/AbstractPatternFilter.java Fri May 6 07:28:43 2011
@@ -0,0 +1,167 @@
+/**
+ * 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.metrics2.filter;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.google.common.collect.Maps;
+import org.apache.commons.configuration.SubsetConfiguration;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.metrics2.MetricsException;
+import org.apache.hadoop.metrics2.MetricsFilter;
+import org.apache.hadoop.metrics2.MetricsTag;
+
+/**
+ * Base class for pattern based filters
+ */
+@InterfaceAudience.Private
+public abstract class AbstractPatternFilter extends MetricsFilter {
+ protected static final String INCLUDE_KEY = "include";
+ protected static final String EXCLUDE_KEY = "exclude";
+ protected static final String INCLUDE_TAGS_KEY = "include.tags";
+ protected static final String EXCLUDE_TAGS_KEY = "exclude.tags";
+
+ private Pattern includePattern;
+ private Pattern excludePattern;
+ private final Map<String, Pattern> includeTagPatterns;
+ private final Map<String, Pattern> excludeTagPatterns;
+ private final Pattern tagPattern = Pattern.compile("^(\\w+):(.*)");
+
+ AbstractPatternFilter() {
+ includeTagPatterns = Maps.newHashMap();
+ excludeTagPatterns = Maps.newHashMap();
+ }
+
+ @Override
+ public void init(SubsetConfiguration conf) {
+ String patternString = conf.getString(INCLUDE_KEY);
+ if (patternString != null && !patternString.isEmpty()) {
+ setIncludePattern(compile(patternString));
+ }
+ patternString = conf.getString(EXCLUDE_KEY);
+ if (patternString != null && !patternString.isEmpty()) {
+ setExcludePattern(compile(patternString));
+ }
+ String[] patternStrings = conf.getStringArray(INCLUDE_TAGS_KEY);
+ if (patternStrings != null && patternStrings.length != 0) {
+ for (String pstr : patternStrings) {
+ Matcher matcher = tagPattern.matcher(pstr);
+ if (!matcher.matches()) {
+ throw new MetricsException("Illegal tag pattern: "+ pstr);
+ }
+ setIncludeTagPattern(matcher.group(1), compile(matcher.group(2)));
+ }
+ }
+ patternStrings = conf.getStringArray(EXCLUDE_TAGS_KEY);
+ if (patternStrings != null && patternStrings.length != 0) {
+ for (String pstr : patternStrings) {
+ Matcher matcher = tagPattern.matcher(pstr);
+ if (!matcher.matches()) {
+ throw new MetricsException("Illegal tag pattern: "+ pstr);
+ }
+ setExcludeTagPattern(matcher.group(1), compile(matcher.group(2)));
+ }
+ }
+ }
+
+ void setIncludePattern(Pattern includePattern) {
+ this.includePattern = includePattern;
+ }
+
+ void setExcludePattern(Pattern excludePattern) {
+ this.excludePattern = excludePattern;
+ }
+
+ void setIncludeTagPattern(String name, Pattern pattern) {
+ includeTagPatterns.put(name, pattern);
+ }
+
+ void setExcludeTagPattern(String name, Pattern pattern) {
+ excludeTagPatterns.put(name, pattern);
+ }
+
+ @Override
+ public boolean accepts(MetricsTag tag) {
+ // Accept if whitelisted
+ Pattern ipat = includeTagPatterns.get(tag.name());
+ if (ipat != null && ipat.matcher(tag.value()).matches()) {
+ return true;
+ }
+ // Reject if blacklisted
+ Pattern epat = excludeTagPatterns.get(tag.name());
+ if (epat != null && epat.matcher(tag.value()).matches()) {
+ return false;
+ }
+ // Reject if no match in whitelist only mode
+ if (ipat != null && epat == null) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean accepts(Iterable<MetricsTag> tags) {
+ // Accept if any include tag pattern matches
+ for (MetricsTag t : tags) {
+ Pattern pat = includeTagPatterns.get(t.name());
+ if (pat != null && pat.matcher(t.value()).matches()) {
+ return true;
+ }
+ }
+ // Reject if any exclude tag pattern matches
+ for (MetricsTag t : tags) {
+ Pattern pat = excludeTagPatterns.get(t.name());
+ if (pat != null && pat.matcher(t.value()).matches()) {
+ return false;
+ }
+ }
+ // Reject if no match in whitelist only mode
+ if (!includeTagPatterns.isEmpty() && excludeTagPatterns.isEmpty()) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean accepts(String name) {
+ // Accept if whitelisted
+ if (includePattern != null && includePattern.matcher(name).matches()) {
+ return true;
+ }
+ // Reject if blacklisted
+ if ((excludePattern != null && excludePattern.matcher(name).matches())) {
+ return false;
+ }
+ // Reject if no match in whitelist only mode
+ if (includePattern != null && excludePattern == null) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Compile a string pattern in to a pattern object
+ * @param s the string pattern to compile
+ * @return the compiled pattern object
+ */
+ protected abstract Pattern compile(String s);
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/GlobFilter.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/GlobFilter.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/GlobFilter.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/GlobFilter.java Fri May 6 07:28:43 2011
@@ -0,0 +1,40 @@
+/**
+ * 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.metrics2.filter;
+
+import java.util.regex.Pattern;
+import org.apache.hadoop.fs.GlobPattern;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * A glob pattern filter for metrics.
+ *
+ * The class name is used in metrics config files
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public class GlobFilter extends AbstractPatternFilter {
+
+ @Override
+ protected Pattern compile(String s) {
+ return GlobPattern.compile(s);
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/RegexFilter.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/RegexFilter.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/RegexFilter.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/RegexFilter.java Fri May 6 07:28:43 2011
@@ -0,0 +1,37 @@
+/**
+ * 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.metrics2.filter;
+
+import java.util.regex.Pattern;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
+
+/**
+ * A regex pattern filter for metrics
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+public class RegexFilter extends AbstractPatternFilter {
+
+ @Override
+ protected Pattern compile(String s) {
+ return Pattern.compile(s);
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/package-info.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/package-info.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/package-info.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/filter/package-info.java Fri May 6 07:28:43 2011
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+/**
+ * Builtin metrics filters (to be used in metrics config files)
+ */
+@InterfaceAudience.Public
+@InterfaceStability.Evolving
+package org.apache.hadoop.metrics2.filter;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
\ No newline at end of file
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/AbstractMetricsRecord.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/AbstractMetricsRecord.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/AbstractMetricsRecord.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/AbstractMetricsRecord.java Fri May 6 07:28:43 2011
@@ -0,0 +1,54 @@
+/*
+ * 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.metrics2.impl;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+
+import org.apache.hadoop.metrics2.MetricsRecord;
+
+abstract class AbstractMetricsRecord implements MetricsRecord {
+
+ @Override public boolean equals(Object obj) {
+ if (obj instanceof MetricsRecord) {
+ final MetricsRecord other = (MetricsRecord) obj;
+ return Objects.equal(timestamp(), other.timestamp()) &&
+ Objects.equal(name(), other.name()) &&
+ Objects.equal(description(), other.description()) &&
+ Objects.equal(tags(), other.tags()) &&
+ Iterables.elementsEqual(metrics(), other.metrics());
+ }
+ return false;
+ }
+
+ // Should make sense most of the time when the record is used as a key
+ @Override public int hashCode() {
+ return Objects.hashCode(name(), description(), tags());
+ }
+
+ @Override public String toString() {
+ return Objects.toStringHelper(this)
+ .add("timestamp", timestamp())
+ .add("name", name())
+ .add("description", description())
+ .add("tags", tags())
+ .add("metrics", Iterables.toString(metrics()))
+ .toString();
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MBeanInfoBuilder.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MBeanInfoBuilder.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MBeanInfoBuilder.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MBeanInfoBuilder.java Fri May 6 07:28:43 2011
@@ -0,0 +1,114 @@
+/**
+ * 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.metrics2.impl;
+
+import java.util.List;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
+
+import com.google.common.collect.Lists;
+
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricsInfo;
+import org.apache.hadoop.metrics2.MetricsTag;
+import org.apache.hadoop.metrics2.MetricsVisitor;
+
+/**
+ * Helper class to build MBeanInfo from metrics records
+ */
+class MBeanInfoBuilder implements MetricsVisitor {
+
+ private final String name, description;
+ private List<MBeanAttributeInfo> attrs;
+ private Iterable<MetricsRecordImpl> recs;
+ private int curRecNo;
+
+ MBeanInfoBuilder(String name, String desc) {
+ this.name = name;
+ description = desc;
+ attrs = Lists.newArrayList();
+ }
+
+ MBeanInfoBuilder reset(Iterable<MetricsRecordImpl> recs) {
+ this.recs = recs;
+ attrs.clear();
+ return this;
+ }
+
+ MBeanAttributeInfo newAttrInfo(String name, String desc, String type) {
+ return new MBeanAttributeInfo(getAttrName(name), type, desc,
+ true, false, false); // read-only, non-is
+ }
+
+ MBeanAttributeInfo newAttrInfo(MetricsInfo info, String type) {
+ return newAttrInfo(info.name(), info.description(), type);
+ }
+
+ @Override
+ public void gauge(MetricsInfo info, int value) {
+ attrs.add(newAttrInfo(info, "java.lang.Integer"));
+ }
+
+ @Override
+ public void gauge(MetricsInfo info, long value) {
+ attrs.add(newAttrInfo(info, "java.lang.Long"));
+ }
+
+ @Override
+ public void gauge(MetricsInfo info, float value) {
+ attrs.add(newAttrInfo(info, "java.lang.Float"));
+ }
+
+ @Override
+ public void gauge(MetricsInfo info, double value) {
+ attrs.add(newAttrInfo(info, "java.lang.Double"));
+ }
+
+ @Override
+ public void counter(MetricsInfo info, int value) {
+ attrs.add(newAttrInfo(info, "java.lang.Integer"));
+ }
+
+ @Override
+ public void counter(MetricsInfo info, long value) {
+ attrs.add(newAttrInfo(info, "java.lang.Long"));
+ }
+
+ String getAttrName(String name) {
+ return curRecNo > 0 ? name +"."+ curRecNo : name;
+ }
+
+ MBeanInfo get() {
+ curRecNo = 0;
+ for (MetricsRecordImpl rec : recs) {
+ for (MetricsTag t : rec.tags()) {
+ attrs.add(newAttrInfo("tag."+ t.name(), t.description(),
+ "java.lang.String"));
+ }
+ for (AbstractMetric m : rec.metrics()) {
+ m.visit(this);
+ }
+ ++curRecNo;
+ }
+ MetricsSystemImpl.LOG.debug(attrs);
+ MBeanAttributeInfo[] attrsArray = new MBeanAttributeInfo[attrs.size()];
+ return new MBeanInfo(name, description, attrs.toArray(attrsArray),
+ null, null, null); // no ops/ctors/notifications
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricCounterInt.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricCounterInt.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricCounterInt.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricCounterInt.java Fri May 6 07:28:43 2011
@@ -0,0 +1,48 @@
+/**
+ * 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.metrics2.impl;
+
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.MetricsInfo;
+import org.apache.hadoop.metrics2.MetricsVisitor;
+
+class MetricCounterInt extends AbstractMetric {
+ final int value;
+
+ MetricCounterInt(MetricsInfo info, int value) {
+ super(info);
+ this.value = value;
+ }
+
+ @Override
+ public Integer value() {
+ return value;
+ }
+
+ @Override
+ public MetricType type() {
+ return MetricType.COUNTER;
+ }
+
+ @Override
+ public void visit(MetricsVisitor visitor) {
+ visitor.counter(this, value);
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricCounterLong.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricCounterLong.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricCounterLong.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricCounterLong.java Fri May 6 07:28:43 2011
@@ -0,0 +1,48 @@
+/**
+ * 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.metrics2.impl;
+
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.MetricsInfo;
+import org.apache.hadoop.metrics2.MetricsVisitor;
+
+class MetricCounterLong extends AbstractMetric {
+ final long value;
+
+ MetricCounterLong(MetricsInfo info, long value) {
+ super(info);
+ this.value = value;
+ }
+
+ @Override
+ public Long value() {
+ return value;
+ }
+
+ @Override
+ public MetricType type() {
+ return MetricType.COUNTER;
+ }
+
+ @Override
+ public void visit(MetricsVisitor visitor) {
+ visitor.counter(this, value);
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeDouble.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeDouble.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeDouble.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeDouble.java Fri May 6 07:28:43 2011
@@ -0,0 +1,48 @@
+/**
+ * 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.metrics2.impl;
+
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.MetricsInfo;
+import org.apache.hadoop.metrics2.MetricsVisitor;
+
+class MetricGaugeDouble extends AbstractMetric {
+ final double value;
+
+ MetricGaugeDouble(MetricsInfo info, double value) {
+ super(info);
+ this.value = value;
+ }
+
+ @Override
+ public Double value() {
+ return value;
+ }
+
+ @Override
+ public MetricType type() {
+ return MetricType.GAUGE;
+ }
+
+ @Override
+ public void visit(MetricsVisitor visitor) {
+ visitor.gauge(this, value);
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeFloat.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeFloat.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeFloat.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeFloat.java Fri May 6 07:28:43 2011
@@ -0,0 +1,48 @@
+/**
+ * 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.metrics2.impl;
+
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.MetricsInfo;
+import org.apache.hadoop.metrics2.MetricsVisitor;
+
+class MetricGaugeFloat extends AbstractMetric {
+ final float value;
+
+ MetricGaugeFloat(MetricsInfo info, float value) {
+ super(info);
+ this.value = value;
+ }
+
+ @Override
+ public Float value() {
+ return value;
+ }
+
+ @Override
+ public MetricType type() {
+ return MetricType.GAUGE;
+ }
+
+ @Override
+ public void visit(MetricsVisitor visitor) {
+ visitor.gauge(this, value);
+ }
+}
Added: hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeInt.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeInt.java?rev=1100113&view=auto
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeInt.java (added)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/metrics2/impl/MetricGaugeInt.java Fri May 6 07:28:43 2011
@@ -0,0 +1,48 @@
+/**
+ * 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.metrics2.impl;
+
+import org.apache.hadoop.metrics2.AbstractMetric;
+import org.apache.hadoop.metrics2.MetricType;
+import org.apache.hadoop.metrics2.MetricsInfo;
+import org.apache.hadoop.metrics2.MetricsVisitor;
+
+class MetricGaugeInt extends AbstractMetric {
+ final int value;
+
+ MetricGaugeInt(MetricsInfo info, int value) {
+ super(info);
+ this.value = value;
+ }
+
+ @Override
+ public Integer value() {
+ return value;
+ }
+
+ @Override
+ public MetricType type() {
+ return MetricType.GAUGE;
+ }
+
+ @Override
+ public void visit(MetricsVisitor visitor) {
+ visitor.gauge(this, value);
+ }
+}