Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-metrics</artifactId>
<version>0.7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.bealetech.metrics.reporting;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.ScheduledReporter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.dropwizard.metrics.BaseReporterFactory;
import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotNull;

/**
* A factory for {@link com.bealetech.metrics.reporting.StatsdReporter} instances.
* <p/>
* <b>Configuration Parameters:</b>
* <table>
* <tr>
* <td>Name</td>
* <td>Default</td>
* <td>Description</td>
* </tr>
* <tr>
* <td>host</td>
* <td>localhost</td>
* <td>The hostname of the Statsd server to report to.</td>
* </tr>
* <tr>
* <td>port</td>
* <td>8080</td>
* <td>The port of the Statsd server to report to.</td>
* </tr>
* <tr>
* <td>prefix</td>
* <td><i>None</i></td>
* <td>The prefix for Metric key names to report to Statsd.</td>
* </tr>
* </table>
*/
@JsonTypeName("statsd")
public class StatsdReporterFactory extends BaseReporterFactory {
@NotEmpty
private String host = "localhost";

@Range(min = 0, max = 49151)
private int port = 8080;

@NotNull
private String prefix = "";

@JsonProperty
public String getHost() {
return host;
}

@JsonProperty
public void setHost(String host) {
this.host = host;
}

@JsonProperty
public int getPort() {
return port;
}

@JsonProperty
public void setPort(int port) {
this.port = port;
}

@JsonProperty
public String getPrefix() {
return prefix;
}

@JsonProperty
public void setPrefix(String prefix) {
this.prefix = prefix;
}

/**
* Configures and builds a {@link com.codahale.metrics.ScheduledReporter} instance for the given registry.
*
* @param registry the metrics registry to report metrics from.
* @return a reporter configured for the given metrics registry.
*/
@Override
public ScheduledReporter build(MetricRegistry registry) {
Statsd statsd = new Statsd(host, port);
return StatsdReporter.forRegistry(registry)
.prefixedWith(prefix)
.convertDurationsTo(getDurationUnit())
.convertRatesTo(getRateUnit())
.filter(getFilter())
.build(statsd);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.bealetech.metrics.reporting.StatsdReporterFactory