Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
Expand All @@ -24,6 +26,8 @@ public abstract class AbstractJmxPerformanceCounter implements PerformanceCounte
private final Collection<JmxAttributeData> attributes;
private boolean alreadyLogged = false;

private final Set<String> invalidJmxMetrics = new HashSet<>();

/**
* The main method. The method will fetch the data and send it. The method will not do anything if
* there was a major problem accessing the needed counter.
Expand All @@ -38,6 +42,7 @@ public synchronized void report(TelemetryClient telemetryClient) {
for (Map.Entry<String, Collection<Object>> displayAndValues : result.entrySet()) {
boolean ok = true;
double value = 0.0;
String metricName = displayAndValues.getKey();
for (Object obj : displayAndValues.getValue()) {
try {
if (obj instanceof Boolean) {
Expand All @@ -46,14 +51,22 @@ public synchronized void report(TelemetryClient telemetryClient) {
value += Double.parseDouble(String.valueOf(obj));
}
} catch (RuntimeException e) {
if (!invalidJmxMetrics.contains(metricName)) {
invalidJmxMetrics.add(metricName);
try (MDC.MDCCloseable ignored = CUSTOM_JMX_METRIC_ERROR.makeActive()) {
logger.warn(
"{} JMX metric is invalid because only numeric and boolean JMX metric values are supported.",
metricName);
}
}
ok = false;
break;
}
}

if (ok) {
try {
send(telemetryClient, displayAndValues.getKey(), value);
send(telemetryClient, metricName, value);
} catch (RuntimeException e) {
try (MDC.MDCCloseable ignored = CUSTOM_JMX_METRIC_ERROR.makeActive()) {
logger.error("Error while sending JMX data: '{}'", e.toString());
Expand Down
Loading