Skip to content

Commit c90a4d0

Browse files
committed
Changes based on code review by brian-brazil
1 parent 840b859 commit c90a4d0

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ rules:
3838
```
3939
Name | Description
4040
---------|------------
41-
jmxUrl | A full JMX URL to connect to. Should not be specified if hostPort is.
4241
hostPort | The host and port to connect to via remote JMX. If neither this nor jmxUrl is specified, will talk to the local JVM.
42+
jmxUrl | A full JMX URL to connect to. Should not be specified if hostPort is.
4343
lowercaseOutputName | Lowercase the output metric name. Applies to default format and `name`. Defaults to false.
4444
lowercaseOutputLabelNames | Lowercase the output metric label names. Applies to default format and `labels`. Defaults to false.
4545
whitelistObjectNames | A list of [ObjectNames](http://docs.oracle.com/javase/6/docs/api/javax/management/ObjectName.html) to query. Defaults to all mBeans.

collector/src/main/java/io/prometheus/jmx/JmxCollector.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
public class JmxCollector extends Collector {
2828
private static final Logger LOGGER = Logger.getLogger(JmxCollector.class.getName());
29-
public static final String JMX_URL_KEY = "jmxUrl";
30-
public static final String HOST_PORT_KEY = "hostPort";
3129

3230
private static class Rule {
3331
Pattern pattern;
@@ -39,7 +37,7 @@ private static class Rule {
3937
ArrayList<String> labelValues;
4038
}
4139

42-
String jmxUrl = "";
40+
String jmxUrl;
4341
String username;
4442
String password;
4543

@@ -62,20 +60,23 @@ private JmxCollector(Map<String, Object> config) throws MalformedObjectNameExcep
6260
config = new HashMap<String, Object>();
6361
}
6462

65-
if (config.containsKey(HOST_PORT_KEY)) {
66-
if (config.containsKey(JMX_URL_KEY)) {
63+
if (config.containsKey("hostPort")) {
64+
if (config.containsKey("jmxUrl")) {
6765
throw new IllegalArgumentException("At most one of hostPort and jmxUrl must be provided");
6866
}
69-
jmxUrl ="service:jmx:rmi:///jndi/rmi://" + (String)config.get(HOST_PORT_KEY) + "/jmxrmi";
70-
} else if (config.containsKey(JMX_URL_KEY)) {
71-
jmxUrl = (String)config.get(JMX_URL_KEY);
67+
jmxUrl ="service:jmx:rmi:///jndi/rmi://" + (String)config.get("hostPort") + "/jmxrmi";
68+
} else if (config.containsKey("jmxUrl")) {
69+
jmxUrl = (String)config.get("jmxUrl");
70+
} else {
71+
// Default to local JVM
72+
jmxUrl = "";
7273
}
7374

7475
if (config.containsKey("username")) {
75-
this.username = (String)config.get("username");
76+
username = (String)config.get("username");
7677
} else {
7778
// Any username.
78-
this.username = "";
79+
username = "";
7980
}
8081

8182
if (config.containsKey("password")) {

0 commit comments

Comments
 (0)