Skip to content

Commit

Permalink
Only query the JMX value for alias if $value is configured (#213)
Browse files Browse the repository at this point in the history
Querying the value potentially has to query the remote JMX, so only do
it when necessary.
  • Loading branch information
olivielpeau authored and arbll committed Mar 1, 2019
1 parent 152a1f3 commit 9eb04b4
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main/java/org/datadog/jmxfetch/JmxAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public int getMetricsCount() {
}
}

/** Gets the JMX Attribute info value. Makes a call through the connection */
Object getJmxValue()
throws AttributeNotFoundException, InstanceNotFoundException, MBeanException,
ReflectionException, IOException {
Expand Down Expand Up @@ -545,14 +546,18 @@ private String getUserAlias(
// Attribute & domain
alias = alias.replace("$attribute", fullAttributeName);
alias = alias.replace("$domain", domain);
try {
alias = alias.replace("$value", getJmxValue().toString());
} catch (JMException e) {
// If we haven't been able to get the value, it wasn't replaced.
LOGGER.warn("Unable to replace $value for attribute " + fullAttributeName, e);
} catch (IOException e) {
// Same as above
LOGGER.warn("Unable to replace $value for attribute " + fullAttributeName, e);
if (alias.contains("$value")) {
// getJmxValue() hits the JMX target (potentially through remote network connection),
// so only call it if needed.
try {
alias = alias.replace("$value", getJmxValue().toString());
} catch (JMException e) {
// If we haven't been able to get the value, it wasn't replaced.
LOGGER.warn("Unable to replace $value for attribute " + fullAttributeName, e);
} catch (IOException e) {
// Same as above
LOGGER.warn("Unable to replace $value for attribute " + fullAttributeName, e);
}
}

return alias;
Expand Down

0 comments on commit 9eb04b4

Please sign in to comment.