com.signalfx.metrics.errorhandler.CountingOnSendErrorHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signalfx-codahale Show documentation
Show all versions of signalfx-codahale Show documentation
Dropwizard Codahale metrics plugin for signalfx
The newest version!
package com.signalfx.metrics.errorhandler;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Counts errors.
*/
public class CountingOnSendErrorHandler implements OnSendErrorHandler {
private final AtomicInteger totalErrors = new AtomicInteger(0);
private final Map vals = new ConcurrentHashMap();
@Override
public void handleError(MetricError metricError) {
totalErrors.incrementAndGet();
AtomicInteger existingValue = vals.get(metricError.getMetricErrorType());
if (existingValue != null) {
existingValue.incrementAndGet();
} else {
synchronized (this) {
AtomicInteger previousValue = new AtomicInteger(1);
AtomicInteger prevValue = vals.put(metricError.getMetricErrorType(), previousValue);
if (prevValue != null) {
previousValue.addAndGet(prevValue.get());
}
}
}
}
public synchronized Map getValues() {
return new HashMap<>(vals);
}
public int getTotalErrorCount() {
return totalErrors.get();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy