io.dropwizard.metrics.ganglia.GangliaReporterFactory Maven / Gradle / Ivy
package io.dropwizard.metrics.ganglia;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.ScheduledReporter;
import com.codahale.metrics.ganglia.GangliaReporter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import info.ganglia.gmetric4j.gmetric.GMetric;
import io.dropwizard.metrics.BaseReporterFactory;
import io.dropwizard.util.Duration;
import io.dropwizard.validation.MinDuration;
import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.Optional;
import java.util.UUID;
/**
* A factory for {@link GangliaReporter} instances.
*
* Configuration Parameters:
*
*
* Name
* Default
* Description
*
*
* host
* localhost
* The hostname (or group) of the Ganglia server(s) to report to.
*
*
* port
* 8649
* The port of the Ganglia server(s) to report to.
*
*
* mode
* unicast
* The UDP addressing mode to announce the metrics with. One of {@code unicast} or
* {@code multicast}.
*
*
* ttl
* 1
* The time-to-live of the UDP packets for the announced metrics.
*
*
* uuid
* None
* The UUID to tag announced metrics with.
*
*
* spoof
* None
* The hostname and port to use instead of this nodes for the announced metrics. In the
* format {@code hostname:port}.
*
*
* tmax
* 60
* The tmax value to annouce metrics with.
*
*
* dmax
* 0
* The dmax value to announce metrics with.
*
*
*/
@JsonTypeName("ganglia")
public class GangliaReporterFactory extends BaseReporterFactory {
@NotNull
@MinDuration(0)
private Duration tmax = Duration.seconds(1);
@NotNull
@MinDuration(0)
private Duration dmax = Duration.seconds(0);
@NotEmpty
private String host = "localhost";
@Range(min = 1, max = 49151)
private int port = 8649;
@NotNull
private GMetric.UDPAddressingMode mode = GMetric.UDPAddressingMode.UNICAST;
@Range(min = 0, max = 255)
private int ttl = 1;
private String prefix;
private UUID uuid;
private String spoof;
@JsonProperty
public Duration getTmax() {
return tmax;
}
@JsonProperty
public void setTmax(Duration tmax) {
this.tmax = tmax;
}
@JsonProperty
public Duration getDmax() {
return dmax;
}
@JsonProperty
public void setDmax(Duration dmax) {
this.dmax = dmax;
}
@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 GMetric.UDPAddressingMode getMode() {
return mode;
}
@JsonProperty
public void setMode(GMetric.UDPAddressingMode mode) {
this.mode = mode;
}
@JsonProperty
public int getTtl() {
return ttl;
}
@JsonProperty
public void setTtl(int ttl) {
this.ttl = ttl;
}
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
@JsonProperty
public Optional getUuid() {
return Optional.ofNullable(uuid);
}
@JsonProperty
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
@JsonProperty
public Optional getSpoof() {
return Optional.ofNullable(spoof);
}
@JsonProperty
public void setSpoof(String spoof) {
this.spoof = spoof;
}
@Override
public ScheduledReporter build(MetricRegistry registry) {
try {
final GMetric ganglia = new GMetric(host,
port,
mode,
ttl,
uuid != null || spoof != null,
uuid,
spoof);
return GangliaReporter.forRegistry(registry)
.convertDurationsTo(getDurationUnit())
.convertRatesTo(getRateUnit())
.filter(getFilter())
.prefixedWith(getPrefix())
.withDMax((int) dmax.toSeconds())
.withTMax((int) tmax.toSeconds())
.build(ganglia);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy