
com.wavefront.integrations.metrics.WavefrontReporterFactory Maven / Gradle / Ivy
package com.wavefront.integrations.metrics;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.ScheduledReporter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import io.dropwizard.metrics.BaseReporterFactory;
import io.dropwizard.validation.PortRange;
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.Map;
/**
* A factory for {@link WavefrontReporter} instances.
*
* Configuration Parameters:
*
*
* Name
* Default
* Description
*
*
* proxyHost
* localhost
* The hostname of the Wavefront proxy to report to.
*
*
* proxyPort
* 2003
* The port of the Wavefront proxy to report to.
*
*
* prefix
* None
* The prefix for Metric key names to report to Wavefront.
*
*
* metricSource
* canonical name of localhost
* This is the source name all metrics will report to Wavefront under.
*
*
* pointTags
* None
* Key-value pairs for point tags to be added to each point reporting to Wavefront.
*
*
*/
@JsonTypeName("wavefront")
public class WavefrontReporterFactory extends BaseReporterFactory {
@NotEmpty
private String proxyHost = "localhost";
@PortRange
private int proxyPort = 2878;
@NotNull
private String prefix = "";
@NotNull
private String metricSource = "";
@NotNull
private Map pointTags = Collections.emptyMap();
@JsonProperty
public String getProxyHost() {
return proxyHost;
}
@JsonProperty
public void setProxyHost(String proxyHost) {
this.proxyHost = proxyHost;
}
@JsonProperty
public int getProxyPort() {
return proxyPort;
}
@JsonProperty
public void setProxyPort(int proxyPort) {
this.proxyPort = proxyPort;
}
@JsonProperty
public String getPrefix() {
return prefix;
}
@JsonProperty
public void setPrefix(String prefix) {
this.prefix = prefix;
}
@JsonProperty
public String getMetricSource() {
return metricSource;
}
@JsonProperty
public void setMetricSource(String metricSource) {
this.metricSource = metricSource;
}
@JsonProperty("pointTags")
public Map getPointTags() {
return pointTags;
}
@JsonProperty("pointTags")
public void setPointTags(Map pointTags) {
this.pointTags = ImmutableMap.copyOf(pointTags);
}
@Override
public ScheduledReporter build(MetricRegistry registry) {
return WavefrontReporter.forRegistry(registry)
.convertDurationsTo(getDurationUnit())
.convertRatesTo(getRateUnit())
.filter(getFilter())
.prefixedWith(getPrefix())
.withSource(getSource())
.disabledMetricAttributes(getDisabledAttributes())
.withPointTags(pointTags)
.build(proxyHost, proxyPort);
}
private String getSource() {
try {
return Strings.isNullOrEmpty(getMetricSource()) ?
InetAddress.getLocalHost().getCanonicalHostName() :
getMetricSource();
} catch (UnknownHostException ex) {
return "localhost";
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy