|
46 | 46 | import javax.management.ObjectInstance; |
47 | 47 | import javax.management.ObjectName; |
48 | 48 | import javax.management.RuntimeMBeanException; |
| 49 | +import javax.management.MBeanException; |
| 50 | +import javax.management.ReflectionException; |
49 | 51 | import javax.management.openmbean.CompositeData; |
50 | 52 | import javax.management.relation.MBeanServerNotificationFilter; |
51 | 53 | import java.lang.management.ManagementFactory; |
@@ -367,31 +369,39 @@ private void addJmxMetricRegistration(final JmxMetric jmxMetric, List<JmxMetricR |
367 | 369 | MBeanInfo info = server.getMBeanInfo(objectName); |
368 | 370 | MBeanAttributeInfo[] attrInfo = info.getAttributes(); |
369 | 371 | for (MBeanAttributeInfo attr : attrInfo) { |
370 | | - try { |
371 | | - final Object value = server.getAttribute(objectName, attr.getName()); |
372 | | - addJmxMetricRegistration(jmxMetric, registrations, objectName, value, attribute, attr.getName(), metricPrepend); |
373 | | - } catch (AttributeNotFoundException e) { |
374 | | - logger.warn("Can't create metric '{}' because attribute '{}' could not be found", jmxMetric, attribute.getJmxAttributeName()); |
375 | | - } catch (RuntimeMBeanException e) { |
376 | | - if (e.getCause() instanceof UnsupportedOperationException) { |
377 | | - //ignore this attribute |
378 | | - } else { |
379 | | - throw e; |
380 | | - } |
381 | | - } |
| 372 | + String attributeName = attr.getName(); |
| 373 | + tryAddJmxMetric(jmxMetric, registrations, server, attribute, objectName, attributeName, metricPrepend); |
382 | 374 | } |
383 | 375 | } else { |
384 | | - final Object value = server.getAttribute(objectName, attribute.getJmxAttributeName()); |
385 | | - try { |
386 | | - addJmxMetricRegistration(jmxMetric, registrations, objectName, value, attribute, attribute.getJmxAttributeName(), null); |
387 | | - } catch (AttributeNotFoundException e) { |
388 | | - logger.warn("Can't create metric '{}' because attribute '{}' could not be found", jmxMetric, attribute.getJmxAttributeName()); |
389 | | - } |
| 376 | + String attributeName = attribute.getJmxAttributeName(); |
| 377 | + tryAddJmxMetric(jmxMetric, registrations, server, attribute, objectName, attributeName, null); |
390 | 378 | } |
391 | 379 | } |
392 | 380 | } |
393 | 381 | } |
394 | 382 |
|
| 383 | + private void tryAddJmxMetric(JmxMetric jmxMetric, |
| 384 | + List<JmxMetricRegistration> registrations, |
| 385 | + MBeanServer server, |
| 386 | + JmxMetric.Attribute attribute, |
| 387 | + ObjectName objectName, |
| 388 | + String attributeName, |
| 389 | + @Nullable String metricPrepend) throws MBeanException, InstanceNotFoundException, ReflectionException { |
| 390 | + |
| 391 | + try { |
| 392 | + Object value = server.getAttribute(objectName, attributeName); |
| 393 | + addJmxMetricRegistration(jmxMetric, registrations, objectName, value, attribute, attributeName, metricPrepend); |
| 394 | + } catch (AttributeNotFoundException e) { |
| 395 | + logger.warn("Can't create metric '{}' because attribute '{}' could not be found", jmxMetric, attributeName); |
| 396 | + } catch (RuntimeMBeanException e) { |
| 397 | + if (e.getCause() instanceof UnsupportedOperationException) { |
| 398 | + // silently ignore this attribute, won't retry as it's not a transient runtime exception |
| 399 | + } else { |
| 400 | + throw e; |
| 401 | + } |
| 402 | + } |
| 403 | + } |
| 404 | + |
395 | 405 | private static boolean isWildcard(JmxMetric.Attribute attribute) { |
396 | 406 | return "*".equals(attribute.getJmxAttributeName()); |
397 | 407 | } |
@@ -486,7 +496,7 @@ public double get() { |
486 | 496 | value = ((Number) ((CompositeData) server.getAttribute(objectName, jmxAttribute)).get(compositeDataKey)).doubleValue(); |
487 | 497 | } |
488 | 498 | return value; |
489 | | - } catch (InstanceNotFoundException | AttributeNotFoundException e) { |
| 499 | + } catch (InstanceNotFoundException | AttributeNotFoundException | RuntimeMBeanException e) { |
490 | 500 | if (unsubscribeOnError) { |
491 | 501 | unregister(tracer); |
492 | 502 | } |
|
0 commit comments