All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.metrics.graphite.GraphiteReporterFactory Maven / Gradle / Ivy

There is a newer version: 5.0.0-rc.3
Show newest version
package io.dropwizard.metrics.graphite;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.ScheduledReporter;
import com.codahale.metrics.graphite.Graphite;
import com.codahale.metrics.graphite.GraphiteReporter;
import com.codahale.metrics.graphite.GraphiteUDP;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.google.common.annotations.VisibleForTesting;
import io.dropwizard.metrics.BaseReporterFactory;
import io.dropwizard.validation.OneOf;
import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotNull;

/**
 * A factory for {@link GraphiteReporter} instances.
 * 

* Configuration Parameters: *

* * * * * * * * * * * * * * * * * * * * * * * * * *
NameDefaultDescription
hostlocalhostThe hostname of the Graphite server to report to.
port8080The port of the Graphite server to report to.
prefixNoneThe prefix for Metric key names to report to Graphite.
transporttcpThe transport used to report to Graphite. One of {@code tcp} or * {@code udp}.
*/ @JsonTypeName("graphite") public class GraphiteReporterFactory extends BaseReporterFactory { @NotEmpty private String host = "localhost"; @Range(min = 0, max = 49151) private int port = 8080; @NotNull private String prefix = ""; @NotNull @OneOf(value = {"tcp", "udp"}, ignoreCase = true) private String transport = "tcp"; @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; } @JsonProperty public String getTransport() { return transport; } @JsonProperty public void setTransport(String transport) { this.transport = transport; } @Override public ScheduledReporter build(MetricRegistry registry) { GraphiteReporter.Builder builder = builder(registry); if ("udp".equalsIgnoreCase(transport)) { return builder.build(new GraphiteUDP(host, port)); } else { return builder.build(new Graphite(host, port)); } } @VisibleForTesting protected GraphiteReporter.Builder builder(MetricRegistry registry) { return GraphiteReporter.forRegistry(registry) .convertDurationsTo(getDurationUnit()) .convertRatesTo(getRateUnit()) .filter(getFilter()) .prefixedWith(getPrefix()); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy