reporters = new ArrayList<>();
+ private MetricRegistry registry;
+ private String hostname = "localhost";
+ private int port = NonBlockingStatsDClient.DEFAULT_DOGSTATSD_PORT;
+ private StatsDClient client;
+ private long timedThresholdMicros;
+ private String[] tags;
+ private int schedule = 60;
+ private TimeUnit scheduleTimeUnit = TimeUnit.SECONDS;
+
+ @Override
+ public StatsdReporter.Builder hostname(String hostname) {
+ this.hostname = requireNonNull(hostname);
+ return this;
+ }
+
+ @Override
+ public StatsdReporter.Builder port(int port) {
+ this.port = port;
+ return this;
+ }
+
+ @Override
+ public StatsdReporter.Builder client(StatsDClient client) {
+ this.client = client;
+ return this;
+ }
+
+ @Override
+ public StatsdReporter.Builder timedThresholdMicros(long timedThresholdMicros) {
+ this.timedThresholdMicros = timedThresholdMicros;
+ return this;
+ }
+
+ @Override
+ public StatsdReporter.Builder tags(String[] tags) {
+ this.tags = tags;
+ return this;
+ }
+
+ @Override
+ public StatsdReporter.Builder schedule(int schedule, TimeUnit timeUnit) {
+ this.schedule = schedule;
+ this.scheduleTimeUnit = requireNonNull(timeUnit);
+ return this;
+ }
+
+ @Override
+ public StatsdReporter.Builder registry(MetricRegistry registry) {
+ this.registry = requireNonNull(registry);
+ return this;
+ }
+
+ @Override
+ public StatsdReporter.Builder database(Database database) {
+ reporters.add(DatabaseReporter.reporter(database));
+ return this;
+ }
+
+ @Override
+ public StatsdReporter.Builder reporter(StatsdReporter.Reporter reporter) {
+ reporters.add(requireNonNull(reporter));
+ return this;
+ }
+
+ @Override
+ public Reporter build() {
+ if (registry == null) {
+ registry = Metrics.registry();
+ }
+ if (client == null) {
+ client = new NonBlockingStatsDClientBuilder()
+ .hostname(requireNonNull(hostname))
+ .port(port)
+ .constantTags(tags)
+ .build();
+ }
+
+ return new Reporter(registry, client, timedThresholdMicros, schedule, scheduleTimeUnit, reporters);
+ }
+}
diff --git a/metrics-statsd/src/main/java/io/avaje/metrics/statsd/StatsdReporter.java b/metrics-statsd/src/main/java/io/avaje/metrics/statsd/StatsdReporter.java
new file mode 100644
index 0000000..f3d64f6
--- /dev/null
+++ b/metrics-statsd/src/main/java/io/avaje/metrics/statsd/StatsdReporter.java
@@ -0,0 +1,110 @@
+package io.avaje.metrics.statsd;
+
+import com.timgroup.statsd.StatsDClient;
+import io.avaje.metrics.MetricRegistry;
+import io.ebean.Database;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Interface for a StatsD reporter that can be used to report metrics.
+ *
+ * This interface allows for the creation of a StatsD reporter with various configurations such as hostname,
+ * port, client, tags, and reporting schedule.
+ *
+ * The reporter can be started and stopped, and it supports custom reporters that can be included in the
+ * reporting process.
+ */
+public interface StatsdReporter extends AutoCloseable {
+
+ /**
+ * Create a builder for the reporter.
+ */
+ static Builder builder() {
+ return new StatsdBuilder();
+ }
+
+ /**
+ * Start reporting.
+ */
+ void start();
+
+ /**
+ * Shutdown and stop reporting.
+ */
+ void close();
+
+ /**
+ * Custom reporters that can be included.
+ */
+ interface Reporter {
+
+ /**
+ * Report the metrics to the client.
+ */
+ void report(StatsDClient statsdClient);
+ }
+
+ /**
+ * Builder for the StatsdReporter.
+ */
+ interface Builder {
+
+ /**
+ * Specify the hostname to use. Default is localhost.
+ */
+ Builder hostname(String hostname);
+
+ /**
+ * Specify the port to use. Default is 8125.
+ */
+ Builder port(int port);
+
+ /**
+ * Specify the common tags to be used on all the reported metrics. Default is no tags.
+ */
+ Builder tags(String[] tags);
+
+ /**
+ * Specify the StatsD client to use. Default is a NonBlockingStatsDClient.
+ *
+ * When using a custom client, the hostname, port and tags are not used.
+ */
+ Builder client(StatsDClient client);
+
+ /**
+ * Specify the threshold in microseconds for timed metrics to be reported. Default is 0.
+ *
+ * Set this to reduce the number of metrics reported for timed metrics.
+ *
+ * For example, if set to 10_000, metrics with a duration less than 10 milliseconds will not be reported.
+ */
+ Builder timedThresholdMicros(long timedThreshold);
+
+ /**
+ * Specify the schedule in seconds. Default is 60 seconds.
+ */
+ Builder schedule(int schedule, TimeUnit timeUnit);
+
+ /**
+ * Specify the Metrics registry to use. If not specified the global registry is used.
+ */
+ Builder registry(MetricRegistry registry);
+
+ /**
+ * Add a database to report on.
+ */
+ Builder database(Database database);
+
+ /**
+ * Add an additional custom reporter.
+ */
+ Builder reporter(Reporter reporter);
+
+ /**
+ * Build the reporter.
+ */
+ StatsdReporter build();
+
+ }
+}
diff --git a/pom.xml b/pom.xml
index a424a63..38925c4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,6 +28,7 @@
metrics
metrics-graphite
metrics-ebean
+ metrics-statsd