vinothchandar commented on a change in pull request #1106: [HUDI-209] Implement
JMX metrics reporter
URL: https://github.com/apache/incubator-hudi/pull/1106#discussion_r361340214
##########
File path:
hudi-client/src/main/java/org/apache/hudi/metrics/JmxMetricsReporter.java
##########
@@ -18,47 +18,73 @@
package org.apache.hudi.metrics;
+import org.apache.hudi.client.utils.NetUtils;
import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.exception.HoodieException;
-import com.google.common.base.Preconditions;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.jmx.JmxReporter;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
+import javax.management.MBeanServer;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import java.io.Closeable;
+import java.io.IOException;
import java.lang.management.ManagementFactory;
+import java.net.MalformedURLException;
+import java.rmi.NoSuchObjectException;
import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.Iterator;
/**
* Implementation of Jmx reporter, which used to report jmx metric.
*/
public class JmxMetricsReporter extends MetricsReporter {
private static final Logger LOG =
LogManager.getLogger(JmxMetricsReporter.class);
- private final JMXConnectorServer connector;
- private String host;
- private int port;
+ private final JmxServer jmxServer;
- public JmxMetricsReporter(HoodieWriteConfig config) {
+ public JmxMetricsReporter(HoodieWriteConfig config, MetricRegistry registry)
{
try {
// Check the host and port here
- this.host = config.getJmxHost();
- this.port = config.getJmxPort();
- if (host == null || port == 0) {
- throw new RuntimeException(
+ String host = config.getJmxHost();
+ String portsConfig = config.getJmxPorts();
+ if (host == null || portsConfig == null) {
+ throw new HoodieException(
String.format("Jmx cannot be initialized with host[%s] and
port[%s].",
- host, port));
+ host, portsConfig));
}
- LocateRegistry.createRegistry(port);
- String serviceUrl =
- "service:jmx:rmi://" + host + ":" + port + "/jndi/rmi://" + host +
":" + port + "/jmxrmi";
- JMXServiceURL url = new JMXServiceURL(serviceUrl);
- this.connector = JMXConnectorServerFactory
- .newJMXConnectorServer(url, null,
ManagementFactory.getPlatformMBeanServer());
+
+ Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig);
+ JmxServer successfullyStartedServer = null;
Review comment:
why do we need two separate `JmxServer` variables.. just to denote success
or failure.. Can we use a boolean for that and just use `JmxServer server`
declaration.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services