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

com.wavefront.integrations.metrics.WavefrontReporterFactory Maven / Gradle / Ivy

The newest version!
package com.wavefront.integrations.metrics;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.ScheduledReporter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;

import org.hibernate.validator.constraints.NotEmpty;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.Map;

import javax.validation.constraints.NotNull;

import io.dropwizard.metrics.BaseReporterFactory;
import io.dropwizard.validation.PortRange;

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

* Configuration Parameters: *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
NameDefaultDescription
proxyHostlocalhostThe hostname of the Wavefront proxy to report to.
proxyPort2003The port of the Wavefront proxy to report to.
prefixNoneThe prefix for Metric key names to report to Wavefront.
metricSourcecanonical name of localhostThis is the source name all metrics will report to Wavefront under.
pointTagsNoneKey-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