Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log errors encountered by java-dogstatsd-client #208

Merged
merged 1 commit into from
Mar 1, 2019
Merged
Changes from all commits
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 @@ -3,18 +3,29 @@
import com.timgroup.statsd.NonBlockingStatsDClient;
import com.timgroup.statsd.ServiceCheck;
import com.timgroup.statsd.StatsDClient;
import com.timgroup.statsd.StatsDClientErrorHandler;
import org.apache.log4j.Logger;
import org.datadog.jmxfetch.Instance;
import org.datadog.jmxfetch.JmxAttribute;
import org.datadog.jmxfetch.Status;

/** A reporter class to submit metrics via statsd. */
public class StatsdReporter extends Reporter {

private static final Logger LOGGER = Logger.getLogger(StatsdReporter.class.getName());
private StatsDClient statsDClient;
private String statsdHost;
private int statsdPort;
private long initializationTime;

private class LoggingErrorHandler implements StatsDClientErrorHandler {

@Override
public void handle(Exception exception) {
LOGGER.error("statsd client error:", exception);
}
}

/** Constructor, instantiates statsd reported to provided host and port. */
public StatsdReporter(String statsdHost, int statsdPort) {
this.statsdHost = statsdHost;
Expand All @@ -26,7 +37,11 @@ private void init() {
initializationTime = System.currentTimeMillis();
statsDClient =
new NonBlockingStatsDClient(
null, this.statsdHost, this.statsdPort, new String[] {});
null,
this.statsdHost,
this.statsdPort,
new String[] {},
new LoggingErrorHandler());
}

protected void sendMetricPoint(
Expand Down