Skip to content

Commit

Permalink
Improves telemetry bean exception handling (#488)
Browse files Browse the repository at this point in the history
* Improves telemetry bean exception handling

* Updates log lines for lint length and clarity
  • Loading branch information
scottopell authored Oct 19, 2023
1 parent 195c704 commit 43c6494
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,29 +279,38 @@ public Instance(
log.info("collect_default_jvm_metrics is false - not collecting default JVM metrics");
}

instanceTelemetryBean = createJmxBean();
instanceTelemetryBean = createInstanceTelemetryBean();
}

private ObjectName getObjName(String domain,String instance)
throws MalformedObjectNameException {
return new ObjectName(domain + ":target_instance=" + ObjectName.quote(instance));
}

private InstanceTelemetry createJmxBean() {
private InstanceTelemetry createInstanceTelemetryBean() {
mbs = ManagementFactory.getPlatformMBeanServer();
InstanceTelemetry bean = new InstanceTelemetry();
log.debug("Created jmx bean for instance: " + this.getCheckName());

try {
instanceTelemetryBeanName = getObjName(appConfig.getJmxfetchTelemetryDomain(),
this.getName());
mbs.registerMBean(bean,instanceTelemetryBeanName);
log.debug("Succesfully registered jmx bean for instance: " + this.getCheckName()
+ " with ObjectName = " + instanceTelemetryBeanName);
} catch (MalformedObjectNameException e) {
log.warn(
"Could not construct bean name for jmxfetch_telemetry_domain '{}' and name '{}'",
appConfig.getJmxfetchTelemetryDomain(), this.getName());
return bean;
}

} catch (MalformedObjectNameException | InstanceAlreadyExistsException
| MBeanRegistrationException | NotCompliantMBeanException e) {
log.warn("Could not register bean for instance: " + this.getCheckName(),e);
try {
mbs.registerMBean(bean,instanceTelemetryBeanName);
log.debug("Succesfully registered jmx bean for instance {} with ObjectName = {}",
this.getName(), instanceTelemetryBeanName);
} catch (InstanceAlreadyExistsException
| MBeanRegistrationException
| NotCompliantMBeanException e) {
log.warn("Could not register bean named '{}' for instance: ",
instanceTelemetryBeanName.toString(), e);
}

return bean;
Expand Down

0 comments on commit 43c6494

Please sign in to comment.