[
https://issues.apache.org/jira/browse/FLINK-4087?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15344192#comment-15344192
]
ASF GitHub Bot commented on FLINK-4087:
---------------------------------------
Github user tillrohrmann commented on a diff in the pull request:
https://github.com/apache/flink/pull/2145#discussion_r68041287
--- Diff:
flink-core/src/main/java/org/apache/flink/metrics/reporter/JMXReporter.java ---
@@ -73,10 +86,61 @@ public JMXReporter() {
//
------------------------------------------------------------------------
@Override
- public void open(Configuration config) {}
+ public void open(Configuration config) {
+ this.jmxServer = startJmxServer(config);
+ }
+
+ private static JMXServer startJmxServer(Configuration config) {
+ JMXServer jmxServer;
+
+ String portRange = config.getString(KEY_METRICS_JMX_PORT,
"9010-9025");
+ String[] ports = portRange.split("-");
+
+ if (ports.length == 0 || ports.length > 2) {
+ throw new IllegalArgumentException("JMX port range was
configured incorrectly. " +
+ "Expected: <startPort>[-<endPort>] Configured:
" + portRange);
+ }
+
+ if (ports.length == 1) { //single port was configured
+ int port = Integer.parseInt(ports[0]);
+ jmxServer = new JMXServer(port);
+ try {
+ jmxServer.start();
+ } catch (IOException e) {
+ throw new RuntimeException("Could not start JMX
server on port " + port + ".");
+ }
+ return jmxServer;
+ } else { //port range was configured
+ int start = Integer.parseInt(ports[0]);
+ int end = Integer.parseInt(ports[1]);
+ while (true) {
+ try {
+ jmxServer = new JMXServer(start);
+ jmxServer.start();
+ LOG.info("Starting JMX on port " +
start + ".");
--- End diff --
The log statement should appear before the `start` call.
> JMXReporter can't handle port conflicts
> ---------------------------------------
>
> Key: FLINK-4087
> URL: https://issues.apache.org/jira/browse/FLINK-4087
> Project: Flink
> Issue Type: Improvement
> Components: Metrics
> Affects Versions: 1.1.0
> Reporter: Chesnay Schepler
> Assignee: Chesnay Schepler
> Priority: Blocker
> Fix For: 1.1.0
>
>
> The JMXReporter is currently configured to use a single port that is set as a
> JVM argument.
> This approach has a few disadvantages:
> If multiple TaskManagers run on the same machine only 1 can expose metrics.
> This issue is compounded by the upcoming JobManager metrics, which would then
> prevent TM metrics from being exposed in local setups.
> Currently, we prevent other TM's from exposing metrics by checking the the
> start-daemon-sh whether a TM is already running, and if so clear the
> arguments. This isn't a particular safe way to do it, and this script is not
> used when deploying on yarn, leading to TM failures since the JVM can't
> allocate the JMX port.
> We should find a way to specifiy port-ranges for JMX and log the final port
> used.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)