From 87fe92027c667c454d4be92c67008886c28798c0 Mon Sep 17 00:00:00 2001 From: Scott Opell Date: Thu, 19 Oct 2023 18:13:38 +0000 Subject: [PATCH] Improves telemetry bean exception handling --- src/main/java/org/datadog/jmxfetch/Instance.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/datadog/jmxfetch/Instance.java b/src/main/java/org/datadog/jmxfetch/Instance.java index 54b1274f0..1a37439eb 100644 --- a/src/main/java/org/datadog/jmxfetch/Instance.java +++ b/src/main/java/org/datadog/jmxfetch/Instance.java @@ -279,7 +279,7 @@ 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) @@ -287,7 +287,7 @@ private ObjectName getObjName(String domain,String instance) 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()); @@ -295,13 +295,17 @@ private InstanceTelemetry createJmxBean() { 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;