Skip to content

Commit

Permalink
Improves telemetry bean exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
scottopell committed Oct 19, 2023
1 parent 195c704 commit 87fe920
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,29 +279,33 @@ 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());
} catch (MalformedObjectNameException e) {
log.warn("Could not construct bean name for jmxfetch_telemetry_domain '{}' and name '{}'", appConfig.getJmxfetchTelemetryDomain(), this.getName());
return bean;
}

try {
mbs.registerMBean(bean,instanceTelemetryBeanName);
log.debug("Succesfully registered jmx bean for instance: " + this.getCheckName()
+ " with ObjectName = " + instanceTelemetryBeanName);

} catch (MalformedObjectNameException | InstanceAlreadyExistsException
| MBeanRegistrationException | NotCompliantMBeanException e) {
log.warn("Could not register bean for instance: " + this.getCheckName(),e);
} 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 87fe920

Please sign in to comment.