Skip to content

Commit bac90ea

Browse files
committed
add method to generate generic jmx args
1 parent 4192794 commit bac90ea

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import java.util.ArrayList;
2323
import java.util.Arrays;
2424
import java.util.Collection;
25+
import java.util.HashMap;
2526
import java.util.List;
27+
import java.util.Map;
2628
import java.util.concurrent.BlockingQueue;
2729
import java.util.concurrent.ExecutionException;
2830
import java.util.concurrent.LinkedBlockingDeque;
@@ -196,4 +198,27 @@ public void export(
196198
sb.http(0);
197199
}
198200
}
201+
202+
protected static String genericJmxJvmArguments(int port) {
203+
Map<String, Object> args = new HashMap<>();
204+
args.put("com.sun.management.jmxremote.local.only", "false");
205+
args.put("com.sun.management.jmxremote.authenticate", "false");
206+
args.put("com.sun.management.jmxremote.ssl", "false");
207+
args.put("com.sun.management.jmxremote.port", port);
208+
args.put("com.sun.management.jmxremote.rmi.port", port);
209+
List<String> list =
210+
args.entrySet().stream()
211+
.map((e) -> toJvmArg(e.getKey(), e.getValue()))
212+
.collect(Collectors.toList());
213+
return String.join(" ", list);
214+
}
215+
216+
private static String toJvmArg(String key, Object value) {
217+
StringBuilder sb = new StringBuilder();
218+
sb.append("-D").append(key);
219+
if (value != null) {
220+
sb.append("=").append(value);
221+
}
222+
return sb.toString();
223+
}
199224
}

jmx-scraper/src/integrationTest/java/io/opentelemetry/contrib/jmxscraper/target_systems/TomcatIntegrationTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,7 @@ protected GenericContainer<?> createTargetContainer(int jmxPort) {
3131
"/usr/local/tomcat/webapps/ROOT.war")
3232
.build()))
3333
.withEnv("LOCAL_JMX", "no")
34-
.withEnv(
35-
"CATALINA_OPTS",
36-
"-Dcom.sun.management.jmxremote.local.only=false"
37-
+ " -Dcom.sun.management.jmxremote.authenticate=false"
38-
+ " -Dcom.sun.management.jmxremote.ssl=false"
39-
+ " -Dcom.sun.management.jmxremote.port="
40-
+ jmxPort
41-
+ " -Dcom.sun.management.jmxremote.rmi.port="
42-
+ jmxPort)
34+
.withEnv("CATALINA_OPTS", genericJmxJvmArguments(jmxPort))
4335
.withStartupTimeout(Duration.ofMinutes(2))
4436
.waitingFor(Wait.forListeningPort());
4537
}

0 commit comments

Comments
 (0)