77
88import com .microsoft .applicationinsights .agent .internal .telemetry .TelemetryClient ;
99import java .util .Collection ;
10+ import java .util .HashSet ;
1011import java .util .Map ;
12+ import java .util .Set ;
1113import org .slf4j .Logger ;
1214import org .slf4j .LoggerFactory ;
1315import org .slf4j .MDC ;
@@ -24,6 +26,8 @@ public abstract class AbstractJmxPerformanceCounter implements PerformanceCounte
2426 private final Collection <JmxAttributeData > attributes ;
2527 private boolean alreadyLogged = false ;
2628
29+ private final Set <String > invalidJmxMetrics = new HashSet <>();
30+
2731 /**
2832 * The main method. The method will fetch the data and send it. The method will not do anything if
2933 * there was a major problem accessing the needed counter.
@@ -38,6 +42,7 @@ public synchronized void report(TelemetryClient telemetryClient) {
3842 for (Map .Entry <String , Collection <Object >> displayAndValues : result .entrySet ()) {
3943 boolean ok = true ;
4044 double value = 0.0 ;
45+ String metricName = displayAndValues .getKey ();
4146 for (Object obj : displayAndValues .getValue ()) {
4247 try {
4348 if (obj instanceof Boolean ) {
@@ -46,14 +51,22 @@ public synchronized void report(TelemetryClient telemetryClient) {
4651 value += Double .parseDouble (String .valueOf (obj ));
4752 }
4853 } catch (RuntimeException e ) {
54+ if (!invalidJmxMetrics .contains (metricName )) {
55+ invalidJmxMetrics .add (metricName );
56+ try (MDC .MDCCloseable ignored = CUSTOM_JMX_METRIC_ERROR .makeActive ()) {
57+ logger .warn (
58+ "{} JMX metric is invalid because only numeric and boolean JMX metric values are supported." ,
59+ metricName );
60+ }
61+ }
4962 ok = false ;
5063 break ;
5164 }
5265 }
5366
5467 if (ok ) {
5568 try {
56- send (telemetryClient , displayAndValues . getKey () , value );
69+ send (telemetryClient , metricName , value );
5770 } catch (RuntimeException e ) {
5871 try (MDC .MDCCloseable ignored = CUSTOM_JMX_METRIC_ERROR .makeActive ()) {
5972 logger .error ("Error while sending JMX data: '{}'" , e .toString ());
0 commit comments