Report Dropwizard metrics via the Wavefront proxy.
This commit is contained in:
parent
251e1b51c5
commit
0a23b57ff8
|
@ -21,6 +21,7 @@ import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.UriBuilder;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
@ -44,13 +45,13 @@ public class JsonMetricsReporter extends ScheduledReporter {
|
||||||
private final URI uri;
|
private final URI uri;
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
|
|
||||||
public JsonMetricsReporter(MetricRegistry registry, String token, String hostname,
|
public JsonMetricsReporter(MetricRegistry registry, URI uri,
|
||||||
MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit)
|
MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit)
|
||||||
throws UnknownHostException
|
throws UnknownHostException
|
||||||
{
|
{
|
||||||
super(registry, "json-reporter", filter, rateUnit, durationUnit);
|
super(registry, "json-reporter", filter, rateUnit, durationUnit);
|
||||||
this.httpClient = HttpClient.newBuilder().version(HttpClient.Version.HTTP_2).build();
|
this.httpClient = HttpClient.newBuilder().version(HttpClient.Version.HTTP_2).build();
|
||||||
this.uri = URI.create(String.format("https://%s/report/metrics?t=%s&h=%s", hostname, token, InetAddress.getLocalHost().getHostName()));
|
this.uri = UriBuilder.fromUri(uri).queryParam("h", InetAddress.getLocalHost().getHostName()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -210,8 +211,7 @@ public class JsonMetricsReporter extends ScheduledReporter {
|
||||||
private MetricFilter filter = MetricFilter.ALL;
|
private MetricFilter filter = MetricFilter.ALL;
|
||||||
private TimeUnit rateUnit = TimeUnit.SECONDS;
|
private TimeUnit rateUnit = TimeUnit.SECONDS;
|
||||||
private TimeUnit durationUnit = TimeUnit.MILLISECONDS;
|
private TimeUnit durationUnit = TimeUnit.MILLISECONDS;
|
||||||
private String token;
|
private URI uri;
|
||||||
private String hostname;
|
|
||||||
|
|
||||||
private Builder(MetricRegistry registry) {
|
private Builder(MetricRegistry registry) {
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
|
@ -235,26 +235,17 @@ public class JsonMetricsReporter extends ScheduledReporter {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withToken(String token) {
|
public Builder withUri(URI uri) {
|
||||||
this.token = token;
|
this.uri = uri;
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder withHostname(String hostname) {
|
|
||||||
this.hostname = hostname;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonMetricsReporter build() throws UnknownHostException {
|
public JsonMetricsReporter build() throws UnknownHostException {
|
||||||
if (hostname == null) {
|
if (uri == null) {
|
||||||
throw new IllegalArgumentException("No hostname specified!");
|
throw new IllegalArgumentException("No URI specified!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token == null) {
|
return new JsonMetricsReporter(registry, uri, filter, rateUnit, durationUnit);
|
||||||
throw new IllegalArgumentException("No token specified!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new JsonMetricsReporter(registry, token, hostname, filter, rateUnit, durationUnit);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.net.URI;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import io.dropwizard.metrics.BaseReporterFactory;
|
import io.dropwizard.metrics.BaseReporterFactory;
|
||||||
|
@ -20,18 +21,13 @@ public class JsonMetricsReporterFactory extends BaseReporterFactory {
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
@NotNull
|
@NotNull
|
||||||
private String hostname;
|
private URI uri;
|
||||||
|
|
||||||
@JsonProperty
|
|
||||||
@NotNull
|
|
||||||
private String token;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScheduledReporter build(MetricRegistry metricRegistry) {
|
public ScheduledReporter build(MetricRegistry metricRegistry) {
|
||||||
try {
|
try {
|
||||||
return JsonMetricsReporter.forRegistry(metricRegistry)
|
return JsonMetricsReporter.forRegistry(metricRegistry)
|
||||||
.withHostname(hostname)
|
.withUri(uri)
|
||||||
.withToken(token)
|
|
||||||
.convertRatesTo(getRateUnit())
|
.convertRatesTo(getRateUnit())
|
||||||
.convertDurationsTo(getDurationUnit())
|
.convertDurationsTo(getDurationUnit())
|
||||||
.filter(getFilter())
|
.filter(getFilter())
|
||||||
|
|
Loading…
Reference in New Issue