From c533b79c328a3b0a28028761d8a50942b9758636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Elek?= Date: Thu, 20 Jun 2019 10:28:42 +0200 Subject: [PATCH] HDDS-1710. Publish JVM metrics via Hadoop metrics Signed-off-by: Anu Engineer --- .../java/org/apache/hadoop/hdds/HddsUtils.java | 18 ++++++++++++++++++ .../hadoop/ozone/HddsDatanodeService.java | 2 +- .../scm/server/StorageContainerManager.java | 5 ++++- .../apache/hadoop/ozone/om/OzoneManager.java | 4 +++- .../org/apache/hadoop/ozone/freon/Freon.java | 2 ++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java index a284caaf66..8b239a4962 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java @@ -42,9 +42,13 @@ import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.SCMSecurityProtocol; import org.apache.hadoop.hdds.scm.protocolPB.ScmBlockLocationProtocolPB; +import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.ipc.Client; import org.apache.hadoop.ipc.ProtobufRpcEngine; import org.apache.hadoop.ipc.RPC; +import org.apache.hadoop.metrics2.MetricsSystem; +import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; +import org.apache.hadoop.metrics2.source.JvmMetrics; import org.apache.hadoop.metrics2.util.MBeans; import org.apache.hadoop.net.DNS; import org.apache.hadoop.net.NetUtils; @@ -475,4 +479,18 @@ public static InetSocketAddress getScmAddressForSecurityProtocol( .orElse(ScmConfigKeys.OZONE_SCM_SECURITY_SERVICE_PORT_DEFAULT)); } + /** + * Initialize hadoop metrics systen for Ozone servers. + * @param configuration OzoneConfiguration to use. + * @param serverName The logical name of the server components. (eg. + * @return + */ + public static MetricsSystem initializeMetrics(OzoneConfiguration configuration, + String serverName) { + MetricsSystem metricsSystem = DefaultMetricsSystem.initialize(serverName); + JvmMetrics.create(serverName, + configuration.get(DFSConfigKeys.DFS_METRICS_SESSION_ID_KEY), + DefaultMetricsSystem.instance()); + return metricsSystem; + } } diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/HddsDatanodeService.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/HddsDatanodeService.java index 93e9490837..4c2bf1a612 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/HddsDatanodeService.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/HddsDatanodeService.java @@ -170,8 +170,8 @@ public void start(OzoneConfiguration configuration) { } public void start() { - DefaultMetricsSystem.initialize("HddsDatanode"); OzoneConfiguration.activate(); + HddsUtils.initializeMetrics(conf, "HddsDatanode"); if (HddsUtils.isHddsEnabled(conf)) { try { String hostname = HddsUtils.getHostName(conf); diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java index 6296df85c0..ffe1b819fe 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java @@ -81,11 +81,13 @@ import org.apache.hadoop.hdds.server.ServiceRuntimeInfoImpl; import org.apache.hadoop.hdds.server.events.EventPublisher; import org.apache.hadoop.hdds.server.events.EventQueue; +import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSUtil; import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.ipc.RPC; import org.apache.hadoop.metrics2.MetricsSystem; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; +import org.apache.hadoop.metrics2.source.JvmMetrics; import org.apache.hadoop.metrics2.util.MBeans; import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.OzoneSecurityUtil; @@ -760,7 +762,8 @@ public void start() throws IOException { buildRpcServerStartMessage( "StorageContainerLocationProtocol RPC server", getClientRpcAddress())); - ms = DefaultMetricsSystem.initialize("StorageContainerManager"); + + ms = HddsUtils.initializeMetrics(configuration, "StorageContainerManager"); commandWatcherLeaseManager.start(); getClientProtocolServer().start(); diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java index 0267350a9e..f582c7e798 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java @@ -65,6 +65,7 @@ import org.apache.hadoop.hdds.security.x509.certificates.utils.CertificateSignRequest; import org.apache.hadoop.hdds.server.ServiceRuntimeInfoImpl; import org.apache.hadoop.hdds.tracing.TracingUtil; +import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSUtil; import org.apache.hadoop.hdfs.util.PersistentLongFile; import org.apache.hadoop.io.Text; @@ -73,6 +74,7 @@ import org.apache.hadoop.ipc.ProtobufRpcEngine; import org.apache.hadoop.ipc.RPC; import org.apache.hadoop.ipc.Server; +import org.apache.hadoop.metrics2.source.JvmMetrics; import org.apache.hadoop.ozone.OzoneAcl; import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.OzoneIllegalArgumentException; @@ -1307,7 +1309,7 @@ public void restart() throws IOException { LOG.info(buildRpcServerStartMessage("OzoneManager RPC server", omRpcAddress)); - DefaultMetricsSystem.initialize("OzoneManager"); + HddsUtils.initializeMetrics(configuration, "OzoneManager"); metadataManager.start(configuration); startSecretManagerIfNecessary(); diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/Freon.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/Freon.java index 88ca098c8f..daf266bb70 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/Freon.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/Freon.java @@ -18,6 +18,7 @@ import java.io.IOException; +import org.apache.hadoop.hdds.HddsUtils; import org.apache.hadoop.hdds.cli.GenericCli; import org.apache.hadoop.hdds.cli.HddsVersionProvider; import org.apache.hadoop.hdds.tracing.TracingUtil; @@ -49,6 +50,7 @@ public class Freon extends GenericCli { @Override public void execute(String[] argv) { + HddsUtils.initializeMetrics(createOzoneConfiguration(), "ozone-freon"); TracingUtil.initTracing("freon"); super.execute(argv); }