entry : defaultDimensions.entrySet()) {
- String dimName = entry.getKey();
- DimensionInclusion dimValue = entry.getValue();
- if (!ignoredDimensions.contains(dimName) && !tags.containsKey(dimName)
- && dimValue.shouldInclude(metricType)) {
- builder.addDimensions(SignalFxProtocolBuffers.Dimension.newBuilder().setKey(dimName)
- .setValue(dimValue.getValue()));
- }
- }
-
- if (injectCurrentTimestamp) {
- final long currentTimestamp = System.currentTimeMillis();
- builder.setTimestamp(currentTimestamp);
- }
-
- if (value instanceof Long || value instanceof Integer || value instanceof Short) {
- builder.setValue(SignalFxProtocolBuffers.Datum
- .newBuilder().setIntValue(value.longValue()));
- } else {
- final double doubleToSend = value.doubleValue();
- if (Double.isInfinite(doubleToSend) || Double.isNaN(doubleToSend)) {
- return;
- }
- builder.setValue(SignalFxProtocolBuffers.Datum.newBuilder()
- .setDoubleValue(doubleToSend));
- }
-
- metricSenderSession.setDatapoint(builder.build());
- }
-}
diff --git a/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/DimensionInclusion.java b/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/DimensionInclusion.java
deleted file mode 100644
index 14521697..00000000
--- a/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/DimensionInclusion.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * Copyright (C) 2015 SignalFx, Inc.
- */
-package com.signalfx.codahale.reporter;
-
-import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers;
-
-/**
- * Collection of flags to indicate if a default dimension should be added to a type of metric
- *
- */
-public class DimensionInclusion {
-
- public static final short COUNTER = 1 << 0;
- public static final short CUMULATIVE_COUNTER = 1 << 1;
- public static final short GAUGE = 1 << 2;
-
- public static final short ALL = COUNTER | CUMULATIVE_COUNTER | GAUGE;
- public static final short NOT_COUNTER = CUMULATIVE_COUNTER | GAUGE;
-
- private final String value;
- private final short inclusion;
-
- private DimensionInclusion(String value, short inclusion) {
- this.value = value;
- this.inclusion = inclusion;
- }
-
- public static DimensionInclusion unique(String value) {
- return new DimensionInclusion(value, NOT_COUNTER);
- }
-
- public static DimensionInclusion shared(String value) {
- return new DimensionInclusion(value, ALL);
- }
-
- public boolean shouldInclude(SignalFxProtocolBuffers.MetricType metricType) {
- switch (metricType) {
- case GAUGE:
- return checkBit(GAUGE);
- case COUNTER:
- return checkBit(COUNTER);
- case CUMULATIVE_COUNTER:
- return checkBit(CUMULATIVE_COUNTER);
- case ENUM:
- default:
- return false;
- }
- }
-
- public String getValue() {
- return value;
- }
-
- private boolean checkBit(short bit) {
-
- return (inclusion & bit) == bit;
- }
-}
diff --git a/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/IncrementalCounter.java b/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/IncrementalCounter.java
deleted file mode 100644
index b0cc0e97..00000000
--- a/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/IncrementalCounter.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package com.signalfx.codahale.reporter;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.Metric;
-import com.signalfx.codahale.metrics.MetricBuilder;
-
-/**
- *
- * An {@link com.signalfx.codahale.reporter.IncrementalCounter} is a counter that reports
- * incremental values to SignalFx rather than absolute counts. For example,
- * a regular {@link com.codahale.metrics.Counter} reports a monotonically increasing series of
- * values (1, 2, 3, 4, ...) while this class reports a series of increments (+1, +1, +1, +1), but
- * both represent the same rate of 1 unit per reporting interval. A
- * {@link com.codahale.metrics.Counter} created the regular Codahale way is the preferred way
- * to report incremental values to SignalFx when possible.
- *
- *
- * An example use case of this class would be if you wanted to count the number of requests to a webpage,
- * but didn't care about that as a dimension of the code serving the request. So instead
- * of reporting source=hostname metric=webpage.user_login.hits", which multiplies by the
- * number of different source=hostname that are reporting, you can report the metric as
- * source=webpage metric=user_login.hits and all servers will increment the same metric, even though
- * they have different rolling counts.
- *
- *
- * A {@link com.codahale.metrics.Counter} assumes metric type
- * {@link com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.MetricType#CUMULATIVE_COUNTER},
- * while this class assumes metric type
- * {@link com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.MetricType#COUNTER}
- */
-public class IncrementalCounter extends Counter {
- /**
- * The last value when {@link #getCountChange()} was called.
- */
- private long lastValue;
-
- /**
- * Returns the difference between the current value of the counter and the value when this
- * function was last called.
- *
- * @return Counter difference
- */
- public synchronized long getCountChange() {
- final long currentCount = getCount();
- final long countChange = currentCount - lastValue;
- lastValue = currentCount;
- return countChange;
- }
-
- public final static class Builder implements MetricBuilder {
- public static final Builder INSTANCE = new Builder();
-
- private Builder() {
- }
-
- @Override
- public IncrementalCounter newMetric() {
- return new IncrementalCounter();
- }
-
- @Override
- public boolean isInstance(Metric metric) {
- return metric instanceof IncrementalCounter;
- }
- }
-}
diff --git a/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/MetricMetadata.java b/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/MetricMetadata.java
deleted file mode 100644
index 8b61ebaf..00000000
--- a/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/MetricMetadata.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package com.signalfx.codahale.reporter;
-
-import java.util.Map;
-import com.codahale.metrics.Metric;
-import com.codahale.metrics.MetricRegistry;
-import com.google.common.base.Optional;
-import com.signalfx.codahale.metrics.MetricBuilder;
-import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers;
-
-/**
- * Allows users to modify a metric with different source or metric parts than the default we pick
- * from codahale. Note: This class must be thread safe.
- */
-public interface MetricMetadata {
- public static final String SOURCE = "source";
- public static final String METRIC = "metric";
- public Map getTags(Metric metric);
- public Optional getMetricType(Metric metric);
-
- /**
- * Create an object to tag a metric with data. Registering two different metrics with the same
- * metadata will result in an exception. In that case, use {@link #forBuilder(com.signalfx.codahale.metrics.MetricBuilder)}
- * @param metric The metric will tag.
- * @param The type of metric. It is implied by the metric type.
- * @return An object to tag the given metric.
- */
- public Tagger forMetric(M metric);
-
- @Deprecated
- public Tagger tagMetric(M metric);
-
- /**
- * Create a tagger for a type of objects. This is different than {@link #forMetric(com.codahale.metrics.Metric)}
- * because it will not use the builder to create a metric unless if it already exists.
- * @param metricBuilder The builder that creates metrics.
- * @param The type of metric to create.
- * @return An object to tag metrics.
- */
- public BuilderTagger forBuilder(MetricBuilder metricBuilder);
-
- /**
- * Removes the specified metric from the metric metadata and registry.
- * @param metric The metric to remove, cannot be null.
- * @param metricRegistry Registry to remove the metric from
- * @return True if the metric was found and removed, false otherwise
- */
- public boolean removeMetric(M metric, MetricRegistry metricRegistry);
-
- public interface TaggerBase> {
- /**
- * Tag the metric with a sf_source
- * @param sourceName Source name for the sf_source
- * @return this
- * @deprecated The use of the build in source parameter is deprecated and discouraged. Use
- * {@link #withDimension(String, String)} instead.
- */
- @Deprecated
- T withSourceName(String sourceName);
-
- /**
- * Changes the metric name of this metric from the default (which is the codahale metric
- * name), to another string
- * @param metricName The new name in SignalFx of this metric
- * @return this
- */
- T withMetricName(String metricName);
-
- /**
- * Adds a dimension to this metric
- * @param key The dimension key to add
- * @param value The dimensino value to add
- * @return this
- */
- T withDimension(String key, String value);
-
- /**
- * Changes the default metric type of this metric to the SignalFx metric type passed in
- * @param metricType The new metric type of this metric
- * @return this
- */
- T withMetricType(SignalFxProtocolBuffers.MetricType metricType);
- }
-
- public interface Tagger extends TaggerBase> {
- /**
- * Helper that registers a metric in the registry, throwing an exception if it already
- * exists.
- * @param metricRegistry Where to register the metric.
- * @return The new metric
- */
- M register(MetricRegistry metricRegistry);
-
- /**
- * Returns the tagged metric
- * @return the tagged metric
- */
- M metric();
- }
-
- public interface BuilderTagger extends TaggerBase> {
- /**
- * Create this metric in the registry, or return the currently registered metric if it
- * already exists.
- * @param metricRegistry Registry to create the metric in
- * @return The new (or existing) metric.
- */
- M createOrGet(MetricRegistry metricRegistry);
- }
-}
diff --git a/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/MetricMetadataImpl.java b/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/MetricMetadataImpl.java
deleted file mode 100644
index 631e3acc..00000000
--- a/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/MetricMetadataImpl.java
+++ /dev/null
@@ -1,252 +0,0 @@
-package com.signalfx.codahale.reporter;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import com.codahale.metrics.Metric;
-import com.codahale.metrics.MetricRegistry;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.signalfx.codahale.metrics.MetricBuilder;
-import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.MetricType;
-
-public class MetricMetadataImpl implements MetricMetadata {
- private final ConcurrentMap metaDataCollection;
-
- public MetricMetadataImpl() {
- // This map must be thread safe
- metaDataCollection = new ConcurrentHashMap();
- }
-
- @Override
- public Map getTags(Metric metric) {
- Metadata existingMetaData = metaDataCollection.get(metric);
- if (existingMetaData == null) {
- return Collections.emptyMap();
- } else {
- return Collections.unmodifiableMap(existingMetaData.tags);
- }
- }
-
- @Override
- public Optional getMetricType(Metric metric) {
- Metadata existingMetaData = metaDataCollection.get(metric);
- if (existingMetaData == null || existingMetaData.metricType == null) {
- return Optional.absent();
- } else {
- return Optional.of(existingMetaData.metricType);
- }
- }
-
- @Override
- public Tagger tagMetric(M metric) {
- return forMetric(metric);
- }
-
- @Override
- public Tagger forMetric(M metric) {
- Metadata metadata = metaDataCollection.get(metric);
- if (metadata == null) {
- synchronized (this) {
- metadata = metaDataCollection.get(metric);
- if (metadata == null) {
- metadata = new Metadata();
- Metadata oldMetaData = metaDataCollection.put(metric, metadata);
- Preconditions.checkArgument(oldMetaData == null,
- "Concurrency issue adding metadata");
- }
- }
- }
- return new TaggerImpl(metric, metadata);
- }
-
- @Override
- public BuilderTagger forBuilder(
- MetricBuilder metricBuilder) {
- return new BuilderTaggerImpl(metricBuilder, metaDataCollection, new Metadata());
- }
-
- @Override
- public boolean removeMetric(M metric, MetricRegistry metricRegistry) {
- Metadata metadata = metaDataCollection.remove(metric);
- if (metadata == null) {
- return false;
- }
- metricRegistry.remove(metadata.getCodahaleName());
- return true;
- }
-
- private static abstract class TaggerBaseImpl>
- implements TaggerBase{
- protected final Metadata thisMetricsMetadata;
-
- @Override
- public T withDimension(String key, String value) {
- thisMetricsMetadata.tags.put(key, value);
- return (T) this;
- }
-
- TaggerBaseImpl(Metadata thisMetricsMetadata) {
- this.thisMetricsMetadata = thisMetricsMetadata;
- }
-
- @Override
- public T withSourceName(String sourceName) {
- thisMetricsMetadata.tags.put(SOURCE, sourceName);
- return (T) this;
- }
-
- @Override
- public T withMetricName(String metricName) {
- thisMetricsMetadata.tags.put(METRIC, metricName);
- return (T) this;
- }
-
- @Override
- public T withMetricType(MetricType metricType) {
- thisMetricsMetadata.metricType = metricType;
- return (T) this;
- }
-
- protected String createCodahaleName() {
- return thisMetricsMetadata.getCodahaleName();
- }
- }
-
- private static final class TaggerImpl extends TaggerBaseImpl>
- implements Tagger {
- private final M metric;
-
- TaggerImpl(M metric, Metadata thisMetricsMetadata) {
- super(thisMetricsMetadata);
- this.metric = metric;
- }
-
- @Override
- public M register(MetricRegistry metricRegistry) {
- String compositeName = createCodahaleName();
- return metricRegistry.register(compositeName, metric);
- }
-
- @Override public M metric() {
- return metric;
- }
- }
-
- private class BuilderTaggerImpl extends TaggerBaseImpl>
- implements BuilderTagger {
- private final MetricBuilder metricBuilder;
- private final ConcurrentMap metaDataCollection;
-
- public BuilderTaggerImpl(MetricBuilder metricBuilder,
- ConcurrentMap metaDataCollection,
- Metadata thisMetricsMetadata) {
- super(thisMetricsMetadata);
- this.metricBuilder = metricBuilder;
- this.metaDataCollection = metaDataCollection;
- }
-
- @Override
- public M createOrGet(MetricRegistry metricRegistry) {
- String compositeName = createCodahaleName();
- Metric existingMetric = metricRegistry.getMetrics().get(compositeName);
- if (existingMetric != null && metaDataCollection.get(existingMetric) != null) {
- return validateMetric(existingMetric, compositeName);
- }
- // Lock on an object that is shared by the metadata tagger, not *this* which is not.
- synchronized (metaDataCollection) {
- existingMetric = metricRegistry.getMetrics().get(compositeName);
- if (existingMetric != null) {
- return validateMetric(existingMetric, compositeName);
- }
- // This could throw a IllegalArgumentException. That would only happen if another
- // metric was made with our name, but not constructed by the metadata tagger. This
- // is super strange and deserves an exception.
- Metric newMetric = metricRegistry.register(compositeName,
- metricBuilder.newMetric());
- Preconditions.checkArgument(
- null == metaDataCollection.put(newMetric, thisMetricsMetadata));
- return (M) newMetric;
- }
- }
-
- private M validateMetric(Metric existingMetric, String compositeName) {
- if (!metricBuilder.isInstance(existingMetric)) {
- throw new IllegalArgumentException(
- String.format("The metric %s is not of the correct type",
- compositeName));
- }
- if (!thisMetricsMetadata.equals(metaDataCollection.get(existingMetric))) {
- throw new IllegalArgumentException(String.format(
- "Existing metric has different tags. Unable to differentiate " +
- "metrics: %s",
- compositeName));
- }
- return (M) existingMetric;
- }
- }
-
- private static final class Metadata {
- private final Map tags;
- private MetricType metricType;
-
- private Metadata() {
- tags = new ConcurrentHashMap(6);
- }
-
- public String getCodahaleName() {
- final String existingMetricName = Preconditions.checkNotNull(
- tags.get(MetricMetadata.METRIC),
- "The register helper needs a base metric name to build a readable "
- + "metric. use withMetricName or codahale directly");
-
- // The names should be unique so we sort each parameter by the tag key.
- SortedMap extraParameters = new TreeMap();
- for (Map.Entry entry : tags.entrySet()) {
- // Don't re-add the metric name
- if (!MetricMetadata.METRIC.equals(entry.getKey())) {
- extraParameters.put(entry.getKey(), entry.getValue());
- }
- }
- StringBuilder compositeName = new StringBuilder();
- // Add each entry in sorted order
- for (Map.Entry entry : extraParameters.entrySet()) {
- compositeName.append(entry.getValue()).append('.');
- }
- compositeName.append(existingMetricName);
- return compositeName.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof Metadata)) {
- return false;
- }
-
- Metadata metadata = (Metadata) o;
-
- if (metricType != metadata.metricType) {
- return false;
- }
- if (tags != null ? !tags.equals(metadata.tags) : metadata.tags != null) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = tags != null ? tags.hashCode() : 0;
- result = 31 * result + (metricType != null ? metricType.hashCode() : 0);
- return result;
- }
- }
-}
diff --git a/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/SignalFxReporter.java b/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/SignalFxReporter.java
deleted file mode 100644
index 153fb7d9..00000000
--- a/signalfx-codahale/src/main/java/com/signalfx/codahale/reporter/SignalFxReporter.java
+++ /dev/null
@@ -1,350 +0,0 @@
-/**
-* Copyright (C) 2015 SignalFx, Inc.
-*/
-package com.signalfx.codahale.reporter;
-
-import static java.util.Objects.requireNonNull;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.concurrent.TimeUnit;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.Gauge;
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.Meter;
-import com.codahale.metrics.MetricFilter;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.ScheduledReporter;
-import com.codahale.metrics.Timer;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.signalfx.endpoint.SignalFxEndpoint;
-import com.signalfx.endpoint.SignalFxReceiverEndpoint;
-import com.signalfx.metrics.SourceNameHelper;
-import com.signalfx.metrics.auth.AuthToken;
-import com.signalfx.metrics.auth.StaticAuthToken;
-import com.signalfx.metrics.connection.DataPointReceiverFactory;
-import com.signalfx.metrics.connection.HttpDataPointProtobufReceiverFactory;
-import com.signalfx.metrics.errorhandler.OnSendErrorHandler;
-import com.signalfx.metrics.flush.AggregateMetricSender;
-import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers;
-
-/**
- * Reporter object for codahale metrics that reports values to com.signalfx.signalfx at some
- * interval.
- * @deprecated Migrate to OpenTelemetry to send metric telemetry to Splunk.
- */
-@Deprecated
-public class SignalFxReporter extends ScheduledReporter {
- private final AggregateMetricSender aggregateMetricSender;
- private final Set detailsToAdd;
- private final MetricMetadata metricMetadata;
- private final boolean useLocalTime;
- private final ImmutableMap defaultDimensions;
-
- protected SignalFxReporter(MetricRegistry registry, String name, MetricFilter filter,
- TimeUnit rateUnit, TimeUnit durationUnit,
- AggregateMetricSender aggregateMetricSender,
- Set detailsToAdd,
- MetricMetadata metricMetadata) {
- this(registry, name, filter, rateUnit, durationUnit, aggregateMetricSender, detailsToAdd,
- metricMetadata, false, Collections. emptyMap());
- }
-
- public SignalFxReporter(MetricRegistry registry, String name, MetricFilter filter,
- TimeUnit rateUnit, TimeUnit durationUnit,
- AggregateMetricSender aggregateMetricSender,
- Set detailsToAdd, MetricMetadata metricMetadata,
- boolean useLocalTime, Map defaultDimensions) {
- super(registry, name, filter, rateUnit, durationUnit);
- this.aggregateMetricSender = aggregateMetricSender;
- this.useLocalTime = useLocalTime;
- this.detailsToAdd = detailsToAdd;
- this.metricMetadata = metricMetadata;
- this.defaultDimensions = ImmutableMap.copyOf(defaultDimensions);
- }
-
- @Override
- public void report(SortedMap gauges, SortedMap counters,
- SortedMap histograms, SortedMap meters,
- SortedMap timers) {
- AggregateMetricSenderSessionWrapper session = new AggregateMetricSenderSessionWrapper(
- aggregateMetricSender.createSession(), Collections.unmodifiableSet(detailsToAdd), metricMetadata,
- aggregateMetricSender.getDefaultSourceName(), "sf_source", useLocalTime, defaultDimensions);
-
- try {
- for (Map.Entry entry : gauges.entrySet()) {
- session.addMetric(entry.getValue(), entry.getKey(),
- SignalFxProtocolBuffers.MetricType.GAUGE, entry.getValue().getValue());
- }
- for (Map.Entry entry : counters.entrySet()) {
- if (entry.getValue() instanceof IncrementalCounter) {
- session.addMetric(entry.getValue(), entry.getKey(),
- SignalFxProtocolBuffers.MetricType.COUNTER,
- ((IncrementalCounter)entry.getValue()).getCountChange());
- } else {
- session.addMetric(entry.getValue(), entry.getKey(),
- SignalFxProtocolBuffers.MetricType.CUMULATIVE_COUNTER,
- entry.getValue().getCount());
- }
- }
- for (Map.Entry entry : histograms.entrySet()) {
- session.addHistogram(entry.getKey(), entry.getValue());
- }
- for (Map.Entry entry : meters.entrySet()) {
- session.addMetered(entry.getKey(), entry.getValue());
- }
- for (Map.Entry entry : timers.entrySet()) {
- session.addTimer(entry.getKey(), entry.getValue());
- }
- } finally {
- try {
- session.close();
- } catch (Exception e) {
- // Unable to register... these exceptions handled by AggregateMetricSender
- }
- }
- }
-
- public MetricMetadata getMetricMetadata() {
- return metricMetadata;
- }
-
- public enum MetricDetails {
- // For {@link com.codahale.metrics.Sampling}
- MEDIAN("median"),
- PERCENT_75("75th"),
- PERCENT_95("95th"),
- PERCENT_98("98th"),
- PERCENT_99("99th"),
- PERCENT_999("999th"),
- MAX("max"),
- MIN("min"),
- STD_DEV("stddev"),
- MEAN("mean"),
-
- // For {@link com.codahale.metrics.Counting}
- COUNT("count"),
-
- // For {@link com.codahale.metrics.Metered}
- RATE_MEAN("rate.mean"),
- RATE_1_MIN("rate.1min"),
- RATE_5_MIN("rate.5min"),
- RATE_15_MIN("rate.15min");
- public static final Set ALL = Collections.unmodifiableSet(EnumSet.allOf(MetricDetails.class));
- public static final Set DEFAULTS = ImmutableSet.of(COUNT, MIN, MEAN, MAX);
-
- private final String description;
-
- MetricDetails(String description) {
- this.description = description;
- }
-
- public String getDescription() {
- return description;
- }
- }
-
- public static final class Builder {
- private final MetricRegistry registry;
- private String defaultSourceName;
- private AuthToken authToken;
- private SignalFxReceiverEndpoint endpoint = new SignalFxEndpoint();
- private String name = "signalfx-reporter";
- private int timeoutMs = HttpDataPointProtobufReceiverFactory.DEFAULT_TIMEOUT_MS;
- private DataPointReceiverFactory dataPointReceiverFactory = new
- HttpDataPointProtobufReceiverFactory(endpoint);
- private MetricFilter filter = MetricFilter.ALL;
- private TimeUnit rateUnit = TimeUnit.SECONDS;
- private TimeUnit durationUnit = TimeUnit.MILLISECONDS; // Maybe nano eventually?
- private Set detailsToAdd = MetricDetails.DEFAULTS;
- private Collection onSendErrorHandlerCollection = Collections.emptyList();
- private MetricMetadata metricMetadata = new MetricMetadataImpl();
- private boolean useLocalTime = false;
- private final ImmutableMap.Builder defaultDimensions = new ImmutableMap.Builder();
-
- public Builder(MetricRegistry registry, String authToken) {
- this(registry, new StaticAuthToken(authToken));
- }
-
- public Builder(MetricRegistry registry, AuthToken authToken) {
- this(registry, authToken, SourceNameHelper.getDefaultSourceName());
- }
-
- public Builder(MetricRegistry registry, AuthToken authToken, String defaultSourceName) {
- this.registry = registry;
- this.authToken = authToken;
- this.defaultSourceName = requireNonNull(defaultSourceName, "defaultSourceName must be a non-null value");
- }
-
- public Builder setDefaultSourceName(String defaultSourceName) {
- this.defaultSourceName = requireNonNull(defaultSourceName, "defaultSourceName must be a non-null value");
- return this;
- }
-
- public Builder setAuthToken(AuthToken authToken) {
- this.authToken = authToken;
- return this;
- }
-
- public Builder setEndpoint(SignalFxReceiverEndpoint endpoint) {
- this.endpoint = endpoint;
- this.dataPointReceiverFactory =
- new HttpDataPointProtobufReceiverFactory(endpoint)
- .setTimeoutMs(this.timeoutMs);
- return this;
- }
-
- public Builder setName(String name) {
- this.name = name;
- return this;
- }
-
- public Builder setTimeoutMs(int timeoutMs) {
- this.timeoutMs = timeoutMs;
- this.dataPointReceiverFactory =
- new HttpDataPointProtobufReceiverFactory(endpoint)
- .setTimeoutMs(this.timeoutMs);
- return this;
- }
-
- @Deprecated
- public Builder setVersion(int version) {
- return this;
- }
-
- public Builder setDataPointReceiverFactory(
- DataPointReceiverFactory dataPointReceiverFactory) {
- this.dataPointReceiverFactory = dataPointReceiverFactory;
- return this;
- }
-
- public Builder setFilter(MetricFilter filter) {
- this.filter = filter;
- return this;
- }
-
- public Builder setRateUnit(TimeUnit rateUnit) {
- this.rateUnit = rateUnit;
- return this;
- }
-
- public Builder setDurationUnit(TimeUnit durationUnit) {
- this.durationUnit = durationUnit;
- return this;
- }
-
- public Builder setDetailsToAdd(Set detailsToAdd) {
- this.detailsToAdd = detailsToAdd;
- return this;
- }
-
- public Builder setOnSendErrorHandlerCollection(
- Collection onSendErrorHandlerCollection) {
- this.onSendErrorHandlerCollection = onSendErrorHandlerCollection;
- return this;
- }
-
- public Builder setMetricMetadata(MetricMetadata metricMetadata) {
- this.metricMetadata = metricMetadata;
- return this;
- }
-
- /**
- * Will use the local system time, rather than zero, on sent datapoints.
- * @param useLocalTime If true, use local system time
- * @return this
- */
- public Builder useLocalTime(boolean useLocalTime) {
- this.useLocalTime = useLocalTime;
- return this;
- }
-
- /**
- * Adds all dimensions to the default dimensions to be sent with every datapoint from this
- * reporter. This means they will be added to distributed counters (as opposed to cumulative counters),
- * which means that if there is any dimension in this map which is unique to the emitter (i.e a hostname)
- * then the distributed counter will not aggregate as expected. For dimension that are unique to each emitter use
- * either {@link #addUniqueDimension(String, String)} or {@link #addUniqueDimensions(Map)}
- *
- * @param dimensions
- * non-null map of string value pairs
- * @return this
- */
- public Builder addDimensions(Map dimensions) {
- // loop here to get "null value" protection of addDimension
- for (Map.Entry entry: dimensions.entrySet()) {
- this.addDimension(entry.getKey(), entry.getValue());
- }
- return this;
- }
-
- /**
- * Adds a dimension to the default dimensions to be sent with every datapoint from this
- * reporter. This means they will be added to distributed counters (as opposed to cumulative counters),
- * which means that if the name and value is unique to the emitter (i.e a hostname)
- * then the distributed counter will not aggregate as expected. For dimension that are unique to each emitter use
- * {@link #addUniqueDimension(String, String)}
- *
- * @param name
- * Name of the dimension
- * @param value
- * Value of the dimension. If null then the dimension is not added.
- * @return this
- */
- public Builder addDimension(String name, String value) {
- if (value != null) {
- this.defaultDimensions.put(name, DimensionInclusion.shared(value));
- }
- return this;
- }
-
- /**
- * Adds all dimensions to the default dimensions to be sent with every datapoint that is not a distributed counter.
- * This method should be used for adding dimensions which are unique to the emitter (such as host name), for shared
- * dimensions which can be sent with distributed counters use either {@link #addDimension(String, String)} or {@link #addDimensions(Map)}
- * @param dimensions
- * non-null map of string value pairs
- * @return this
- */
- public Builder addUniqueDimensions(Map dimensions) {
- // loop here to get "null value" protection of addDimension
- for (Map.Entry entry: dimensions.entrySet()) {
- this.addUniqueDimension(entry.getKey(), entry.getValue());
- }
- return this;
- }
-
- /**
- * Adds a dimension to the default dimensions to be sent with every datapoint that is not a distributed counter.
- * This method should be used for adding dimensions which are unique to the emitter (such as host name), for shared
- * dimensions use {@link #addDimension(String, String)}
- *
- * @param name
- * Name of the dimension
- * @param value
- * Value of the dimension. If null then the dimension is not added.
- * @return this
- */
- public Builder addUniqueDimension(String name, String value) {
- if (value != null) {
- this.defaultDimensions.put(name, DimensionInclusion.unique(value));
- }
- return this;
- }
-
- public SignalFxReporter build() {
- AggregateMetricSender aggregateMetricSender = new AggregateMetricSender(
- defaultSourceName, dataPointReceiverFactory, authToken,
- onSendErrorHandlerCollection);
- return new SignalFxReporter(registry, name, filter, rateUnit, durationUnit,
- aggregateMetricSender, detailsToAdd, metricMetadata, useLocalTime,
- defaultDimensions.build());
- }
- }
-}
diff --git a/signalfx-codahale/src/main/java/com/signalfx/codahale/util/BasicJvmMetrics.java b/signalfx-codahale/src/main/java/com/signalfx/codahale/util/BasicJvmMetrics.java
deleted file mode 100644
index 54ac83e3..00000000
--- a/signalfx-codahale/src/main/java/com/signalfx/codahale/util/BasicJvmMetrics.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/**
- * Copyright (C) 2014 SignalFx, Inc.
- */
-package com.signalfx.codahale.util;
-
-
-import java.lang.management.GarbageCollectorMXBean;
-import java.lang.management.ManagementFactory;
-import java.lang.management.MemoryMXBean;
-import java.lang.management.RuntimeMXBean;
-import java.lang.management.ThreadMXBean;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-import com.codahale.metrics.Gauge;
-import com.codahale.metrics.MetricRegistry;
-
-
-/**
- * Report a basic set of JVM metrics to SignalFx.
- *
- */
-public class BasicJvmMetrics {
- /**
- * Report JVM uptime (milliseconds).
- */
- public final Gauge uptimeGauge;
- /**
- * Reports total memory used by the JVM heap (bytes).
- */
- public final Gauge totalMemoryGauge;
- /**
- * Reports current in-use memory in the JVP heap (bytes).
- */
- public final Gauge usedMemoryGauge;
- /**
- * Reports maximum size of JVM heap (bytes).
- */
- public final Gauge maxMemoryGauge;
- /**
- * Reports current CPU load (percent, normalized by number of CPUs available to the JVM.
- */
- public final Gauge cpuLoadGauge;
- /**
- * Reports total number of user and daemon threads.
- */
- public final Gauge totalThreadCountGauge;
- /**
- * Reports number of daemon threads.
- */
- public final Gauge daemonThreadCountGauge;
- /**
- * Reports total time spent in garbage collection (nanoseconds).
- */
- public final Gauge gcTimeGauge;
- /**
- * Reports number of young-generation garbage collections.
- */
- public final Gauge gcYoungCountGauge;
- /**
- * Reports number of old-generation garbage collections.
- */
- public final Gauge gcOldCountGauge;
- /**
- * Reports current GC load (percent, normalized by number of CPUs available to the JVM.
- */
- public final Gauge gcLoadGauge;
-
- private final RuntimeMXBean runtimeBean;
- private final MemoryMXBean memoryBean;
- private final ThreadMXBean threadBean;
- private final List oldGenGcBeans = new ArrayList();
- private final List youngGenGcBeans = new ArrayList();
- private final List allGcBeans = new ArrayList();
-
- // observed name of the old generation memory pool.
- private static final String OLD_GEN_POOL_NAME = "PS Old Gen";
-
- /**
- * Construct the basic JVM metrics using a supplied SignalFx MetricFactory.
- *
- * @param metricRegistry The registry to give these metrics to
- */
- public BasicJvmMetrics(MetricRegistry metricRegistry) {
-
- runtimeBean = ManagementFactory.getRuntimeMXBean();
- memoryBean = ManagementFactory.getMemoryMXBean();
- threadBean = ManagementFactory.getThreadMXBean();
-
- for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
- allGcBeans.add(gcBean);
-
- Set poolNames = new HashSet(Arrays.asList(gcBean.getMemoryPoolNames()));
-
- if (poolNames.contains(OLD_GEN_POOL_NAME)) {
- // We'll count garbage collectors managing the OLD_GEN_POOL_NAME as 'old generation'
- oldGenGcBeans.add(gcBean);
- } else {
- // and all others as 'young generation'
- youngGenGcBeans.add(gcBean);
- }
- }
-
- this.uptimeGauge = createPeriodicGauge(metricRegistry, "jvm.uptime", new UptimeCallback());
-
- this.totalMemoryGauge = createPeriodicGauge(metricRegistry, "jvm.heap.size",
- new TotalMemoryCallback());
-
- this.usedMemoryGauge = createPeriodicGauge(metricRegistry, "jvm.heap.used",
- new UsedMemoryCallback());
-
- this.maxMemoryGauge = createPeriodicGauge(metricRegistry, "jvm.heap.max",
- new MaxMemoryCallback());
-
- this.cpuLoadGauge = createDoublePeriodicGauge(metricRegistry, "jvm.cpu.load", new CpuLoadCallback());
-
- this.totalThreadCountGauge = createIntegerPeriodicGauge(metricRegistry, "jvm.threads.total",
- new TotalThreadCountCallback());
-
- this.daemonThreadCountGauge = createIntegerPeriodicGauge(metricRegistry, "jvm.threads.daemon",
- new DaemonThreadCountCallback());
-
- this.gcTimeGauge = createPeriodicGauge(metricRegistry, "jvm.gc.time", new GcTimeCallback());
-
- this.gcLoadGauge = createDoublePeriodicGauge(metricRegistry, "jvm.gc.load", new GcLoadCallback());
-
- this.gcYoungCountGauge = createPeriodicGauge(metricRegistry, "jvm.gc.young.count",
- new GcCountCallback(youngGenGcBeans));
-
- this.gcOldCountGauge = createPeriodicGauge(metricRegistry, "jvm.gc.old.count",
- new GcCountCallback(oldGenGcBeans));
- }
-
- private Gauge createPeriodicGauge(MetricRegistry metricRegistry, String name,
- Gauge gauge) {
- return metricRegistry.register(name, gauge);
- }
-
- private Gauge createIntegerPeriodicGauge(MetricRegistry metricRegistry, String name,
- Gauge gauge) {
- return metricRegistry.register(name, gauge);
- }
-
- private Gauge createDoublePeriodicGauge(MetricRegistry metricRegistry, String name,
- Gauge gauge) {
- return metricRegistry.register(name, gauge);
- }
-
- private class UptimeCallback implements Gauge {
- @Override
- public Long getValue() {
- return runtimeBean.getUptime();
- }
- }
-
- private class TotalMemoryCallback implements Gauge {
- @Override
- public Long getValue() {
- return memoryBean.getHeapMemoryUsage().getCommitted();
- }
- }
-
- private class UsedMemoryCallback implements Gauge {
- @Override
- public Long getValue() {
- return memoryBean.getHeapMemoryUsage().getUsed();
- }
- }
-
- private class MaxMemoryCallback implements Gauge {
- @Override
- public Long getValue() {
- return memoryBean.getHeapMemoryUsage().getMax();
- }
- }
-
- private class TotalThreadCountCallback implements Gauge {
- @Override
- public Integer getValue() {
- return threadBean.getThreadCount();
- }
- }
-
- private class DaemonThreadCountCallback implements Gauge {
- @Override
- public Integer getValue() {
- return threadBean.getDaemonThreadCount();
- }
- }
-
- private class GcTimeCallback implements Gauge {
- @Override
- public Long getValue() {
- long total = 0;
- for (GarbageCollectorMXBean gcBean : allGcBeans) {
- long sample = gcBean.getCollectionTime();
- if (sample > 0) {
- total += sample;
- }
- }
- return total;
- }
- }
-
- private static class GcCountCallback implements Gauge {
- final private List gcBeans;
-
- private GcCountCallback(List gcBeans) {
- this.gcBeans = gcBeans;
- }
-
- @Override
- public Long getValue() {
- long total = 0;
- for (GarbageCollectorMXBean gcBean : gcBeans) {
- long sample = gcBean.getCollectionCount();
- if (sample > 0) {
- total += sample;
- }
- }
- return total;
- }
- }
-
- private abstract class LoadCallback implements Gauge {
- private static final int PERCENT = 100;
-
- private long previousTime;
- private double previousValue;
- private Map samples = new HashMap();
- private final TimeUnit timeUnit;
-
- LoadCallback(TimeUnit timeUnit) {
- this.previousTime = 0;
- this.previousValue = 0;
- this.timeUnit = timeUnit;
- }
-
- protected abstract Map getSamples();
-
- private long computeDelta(Map newSamples) {
- long delta = 0;
-
- for (Map.Entry entry : newSamples.entrySet()) {
- T key = entry.getKey();
- Long sample = entry.getValue();
- if (sample < 0) {
- // not valid for this key
- } else {
- Long previous = samples.get(key);
- if (previous == null) {
- delta += sample; // first sample
- } else {
- delta += sample - previous;
- }
- }
- }
- samples = newSamples;
-
- return delta;
- }
-
- @Override
- public Double getValue() {
- long time = runtimeBean.getUptime();
- long deltaTime = time - previousTime;
-
- if (deltaTime < 100) {
- return previousValue;
- }
-
- Map samples = getSamples();
-
- long deltaLoad = computeDelta(samples);
-
- previousValue = (double) PERCENT * timeUnit.toNanos(deltaLoad)
- / TimeUnit.MILLISECONDS.toNanos(deltaTime)
- / Runtime.getRuntime().availableProcessors();
-
- previousTime = time;
-
- return previousValue;
- }
- }
-
- // com.sun.management.OperatingSystemMXBean has a getProcessCpuTime()
- // but java.lang.management.OperatingSystemMXBean does not
- private class CpuLoadCallback extends LoadCallback {
- CpuLoadCallback() {
- super(TimeUnit.NANOSECONDS);
- }
-
- @Override
- protected Map getSamples() {
- Map samples = new HashMap();
- for (long threadId : threadBean.getAllThreadIds()) {
- samples.put(threadId, threadBean.getThreadCpuTime(threadId));
- }
- return samples;
- }
- }
-
- // factor stuff out of this and CpuLoadCallback
- private class GcLoadCallback extends LoadCallback {
- GcLoadCallback() {
- super(TimeUnit.MILLISECONDS);
- }
-
- @Override
- protected Map getSamples() {
- Map samples = new HashMap();
- for (GarbageCollectorMXBean gcBean : allGcBeans) {
- samples.put(gcBean.getName(), gcBean.getCollectionTime());
- }
- return samples;
- }
- }
-}
diff --git a/signalfx-codahale/src/test/java/com/signalfx/codahale/metrics/MetricMetadataTest.java b/signalfx-codahale/src/test/java/com/signalfx/codahale/metrics/MetricMetadataTest.java
deleted file mode 100644
index c404a553..00000000
--- a/signalfx-codahale/src/test/java/com/signalfx/codahale/metrics/MetricMetadataTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Copyright (C) 2017 SignalFx, Inc. All rights reserved.
- */
-package com.signalfx.codahale.metrics;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.Metric;
-import com.codahale.metrics.MetricRegistry;
-import com.signalfx.codahale.reporter.MetricMetadata;
-import com.signalfx.codahale.reporter.MetricMetadataImpl;
-import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers.MetricType;
-
-public class MetricMetadataTest {
-
- @Test
- public void testRemoveExisting() {
- MetricRegistry metricRegistry = new MetricRegistry();
- MetricMetadata metadata = new MetricMetadataImpl();
- Metric metric = metadata.forBuilder(SettableLongGauge.Builder.INSTANCE)
- .withMetricName("gauge").withDimension("host", "myhost")
- .withMetricType(MetricType.GAUGE).createOrGet(metricRegistry);
- assertFalse(metricRegistry.getMetrics().isEmpty());
- assertTrue(metadata.getMetricType(metric).isPresent());
- assertTrue(metadata.removeMetric(metric, metricRegistry));
- assertFalse(metadata.getMetricType(metric).isPresent());
- assertTrue(metricRegistry.getMetrics().isEmpty());
- }
-
- @Test
- public void testRemoveMissing() {
- MetricRegistry metricRegistry = new MetricRegistry();
- MetricMetadata metadata = new MetricMetadataImpl();
- Counter counter = metricRegistry.counter("counter");
- assertFalse(metadata.removeMetric(counter, metricRegistry));
- }
-}
diff --git a/signalfx-codahale/src/test/java/com/signalfx/codahale/metrics/SignalFxReporterTest.java b/signalfx-codahale/src/test/java/com/signalfx/codahale/metrics/SignalFxReporterTest.java
deleted file mode 100644
index ce437d0b..00000000
--- a/signalfx-codahale/src/test/java/com/signalfx/codahale/metrics/SignalFxReporterTest.java
+++ /dev/null
@@ -1,325 +0,0 @@
-package com.signalfx.codahale.metrics;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.Gauge;
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.Timer;
-import com.google.common.collect.ImmutableSet;
-import com.signalfx.codahale.SfxMetrics;
-import com.signalfx.codahale.reporter.IncrementalCounter;
-import com.signalfx.codahale.reporter.SignalFxReporter;
-import com.signalfx.metrics.auth.StaticAuthToken;
-import com.signalfx.metrics.connection.StaticDataPointReceiverFactory;
-import com.signalfx.metrics.connection.StoredDataPointReceiver;
-import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers;
-import java.util.concurrent.TimeUnit;
-import org.junit.Before;
-import org.junit.Test;
-
-public class SignalFxReporterTest {
-
- private static final String SOURCE_NAME = "myserver";
-
- private MetricRegistry metricRegistry;
- private SignalFxReporter reporter;
- private SfxMetrics sfxMetrics;
- private StoredDataPointReceiver dbank;
-
- @Before
- public void setup() {
- metricRegistry = new MetricRegistry();
- dbank = new StoredDataPointReceiver();
- reporter = new SignalFxReporter
- .Builder(metricRegistry, new StaticAuthToken(""), SOURCE_NAME)
- .setDataPointReceiverFactory(new StaticDataPointReceiverFactory(dbank))
- .setDetailsToAdd(ImmutableSet.of(SignalFxReporter.MetricDetails.COUNT,
- SignalFxReporter.MetricDetails.MIN,
- SignalFxReporter.MetricDetails.MAX))
- .build();
- sfxMetrics = new SfxMetrics(metricRegistry, reporter.getMetricMetadata());
- }
-
- @Test
- public void testEmptyDataBank() {
- StoredDataPointReceiver dbank = new StoredDataPointReceiver();
- assertEquals(0, dbank.addDataPoints.size());
- }
-
- @Test
- public void testGauge() {
- Gauge gauge = sfxMetrics.registerGauge("gauge", new Gauge() {
- @Override
- public Integer getValue() {
- return 1;
- }
- });
- reporter.report();
- assertEquals(1, dbank.addDataPoints.size());
- assertTrue(sfxMetrics.unregister(gauge));
- }
-
- @Test
- public void testCounter() {
- Counter counter = sfxMetrics.counter("counter");
- counter.inc();
- counter.inc();
- reporter.report();
- assertEquals(1, dbank.addDataPoints.size());
- // counter without dimensions doesn't get into MetricMetadata, so we cannot unregister
- // from SfxMetrics. But we can remove it from MetricRegistry.
- assertFalse(sfxMetrics.unregister(counter));
- assertTrue(metricRegistry.remove("counter"));
- }
-
- @Test
- public void testCounterWithDimensions() {
- Counter counter = sfxMetrics.counter("counter", "dimName", "dimValue");
- counter.inc();
- counter.inc();
- reporter.report();
- assertEquals(1, dbank.addDataPoints.size());
- assertTrue(sfxMetrics.unregister(counter));
- }
-
- @Test
- public void testRawCounter() {
- Counter rawCounter = reporter.getMetricMetadata()
- .forMetric(metricRegistry.counter("rawCounter"))
- .withMetricType(SignalFxProtocolBuffers.MetricType.COUNTER).metric();
- rawCounter.inc(10);
- reporter.report();
- rawCounter.inc(14);
- reporter.report();
- // Users have to use an IncrementalCounter if they want to see the count value of 14 each time
- assertEquals(24, dbank.lastValueFor(SOURCE_NAME, "rawCounter").getIntValue());
- assertEquals(SignalFxProtocolBuffers.MetricType.COUNTER,
- dbank.registeredMetrics.get("rawCounter"));
- }
-
- @Test
- public void testIncrementalCounter() {
- IncrementalCounter incrementalCounter = sfxMetrics
- .incrementalCounter("incrementalCounter");
- incrementalCounter.inc(3);
- assertEquals(false, sfxMetrics.unregister(new Counter()));
- reporter.report();
- assertEquals(1, dbank.addDataPoints.size());
- assertEquals(3, dbank.lastValueFor(SOURCE_NAME, "incrementalCounter").getIntValue());
- }
-
- @Test
- public void testTimer() throws Exception {
- Timer timer = sfxMetrics.timer("timer", "dimName", "dimValue");
- // track time taken.
- for (int i = 0; i < 4; i++) {
- Timer.Context context = timer.time();
- try {
- Thread.sleep(10 + i * 10);
- } finally {
- context.close();
- }
- }
- /*
- Java 7 alternative:
- try (Timer.Context ignored = t.time()) {
- System.out.println("Doing store things");
- }
- */
- reporter.report();
- assertEquals(3, dbank.addDataPoints.size());
- assertEquals(SignalFxProtocolBuffers.MetricType.CUMULATIVE_COUNTER,
- dbank.registeredMetrics.get("timer.count"));
- assertEquals(SignalFxProtocolBuffers.MetricType.GAUGE,
- dbank.registeredMetrics.get("timer.max"));
- assertEquals(SignalFxProtocolBuffers.MetricType.GAUGE,
- dbank.registeredMetrics.get("timer.min"));
- assertTrue(sfxMetrics.unregister(timer));
- }
-
- @Test
- public void testResettingTimer() {
- Timer resettingTimer = sfxMetrics.resettingTimer("resettingTimer", "dimName", "dimValue");
- resettingTimer.update(20, TimeUnit.MILLISECONDS);
- resettingTimer.update(30, TimeUnit.MILLISECONDS);
- reporter.report();
- assertEquals(3, dbank.addDataPoints.size());
- assertEquals(2, dbank.lastValueFor(SOURCE_NAME, "resettingTimer.count").getIntValue());
- assertEquals(20000000, dbank.lastValueFor(SOURCE_NAME, "resettingTimer.min").getIntValue());
- assertEquals(30000000, dbank.lastValueFor(SOURCE_NAME, "resettingTimer.max").getIntValue());
- dbank.addDataPoints.clear();
- resettingTimer.update(25, TimeUnit.MILLISECONDS);
- reporter.report();
- assertEquals(3, dbank.addDataPoints.size());
- assertEquals(3, dbank.lastValueFor(SOURCE_NAME, "resettingTimer.count").getIntValue());
- assertEquals(25000000, dbank.lastValueFor(SOURCE_NAME, "resettingTimer.min").getIntValue());
- assertEquals(25000000, dbank.lastValueFor(SOURCE_NAME, "resettingTimer.max").getIntValue());
- }
-
- @Test
- public void testHistogram() {
- Histogram histogram = sfxMetrics.histogram("histogram", "dimName", "dimValue");
- histogram.update(20);
- histogram.update(30);
- reporter.report();
- assertEquals(3, dbank.addDataPoints.size());
- assertEquals(2, dbank.lastValueFor(SOURCE_NAME, "histogram.count").getIntValue());
- assertEquals(20, dbank.lastValueFor(SOURCE_NAME, "histogram.min").getIntValue());
- assertEquals(30, dbank.lastValueFor(SOURCE_NAME, "histogram.max").getIntValue());
- dbank.addDataPoints.clear();
- histogram.update(25);
- reporter.report();
- assertEquals(3, dbank.addDataPoints.size());
- assertEquals(3, dbank.lastValueFor(SOURCE_NAME, "histogram.count").getIntValue());
- assertEquals(20, dbank.lastValueFor(SOURCE_NAME, "histogram.min").getIntValue());
- assertEquals(30, dbank.lastValueFor(SOURCE_NAME, "histogram.max").getIntValue());
- }
-
- @Test
- public void testResettingHistogram() {
- Histogram resettingHistogram = sfxMetrics.resettingHistogram("resettingHistogram");
- resettingHistogram.update(20);
- resettingHistogram.update(30);
- reporter.report();
- assertEquals(3, dbank.addDataPoints.size());
- assertEquals(2, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.count").getIntValue());
- assertEquals(20, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.min").getIntValue());
- assertEquals(30, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.max").getIntValue());
- dbank.addDataPoints.clear();
- resettingHistogram.update(25);
- reporter.report();
- assertEquals(3, dbank.addDataPoints.size());
- assertEquals(3, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.count").getIntValue());
- assertEquals(25, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.min").getIntValue());
- assertEquals(25, dbank.lastValueFor(SOURCE_NAME, "resettingHistogram.max").getIntValue());
- }
-
- @Test
- public void testMultipleRegistersOfResettingHistogramWithSameName() {
- Histogram resettingHistogram = sfxMetrics.resettingHistogram("resettingHistogram");
- resettingHistogram.update(20);
- Histogram resettingHistogram1 = sfxMetrics.resettingHistogram("resettingHistogram");
- assertEquals(resettingHistogram, resettingHistogram1);
- assertEquals(1, resettingHistogram1.getCount());
- assertEquals(20, resettingHistogram1.getSnapshot().getMax());
-
- Histogram resettingHistogramWithDims = sfxMetrics.resettingHistogram("resettingHistogram", "foo", "bar");
- assertNotEquals(resettingHistogram, resettingHistogramWithDims);
- resettingHistogramWithDims.update(30);
- Histogram resettingHistogramWithDims1 = sfxMetrics.resettingHistogram("resettingHistogram", "foo", "bar");
- assertEquals(1, resettingHistogramWithDims1.getCount());
- assertEquals(30, resettingHistogramWithDims1.getSnapshot().getMax());
- }
-
- @Test
- public void testMultipleRegistersOfResettingTimerWithSameName() {
- Timer resettingTimer = sfxMetrics.resettingTimer("resettingTimer");
- long timeInNanos = TimeUnit.NANOSECONDS.convert(20, TimeUnit.SECONDS);
- resettingTimer.update(timeInNanos, TimeUnit.NANOSECONDS);
- Timer resettingTimer1 = sfxMetrics.resettingTimer("resettingTimer");
- assertEquals(resettingTimer, resettingTimer1);
- assertEquals(1, resettingTimer1.getCount());
- assertEquals(timeInNanos, resettingTimer1.getSnapshot().getMax());
-
- Timer resettingTimerWithDims = sfxMetrics.resettingTimer("resettingTimer", "foo", "bar");
- assertNotEquals(resettingTimer, resettingTimerWithDims);
- timeInNanos = TimeUnit.NANOSECONDS.convert(30, TimeUnit.SECONDS);
- resettingTimerWithDims.update(timeInNanos, TimeUnit.NANOSECONDS);
- Timer resettingTimerWithDims1 = sfxMetrics.resettingTimer("resettingTimer", "foo", "bar");
- assertEquals(1, resettingTimerWithDims1.getCount());
- assertEquals(timeInNanos, resettingTimerWithDims1.getSnapshot().getMax());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testDuplicateMetricRegistrationAroundResettingHistogramTimers() {
- sfxMetrics.resettingHistogram("countstuff");
- sfxMetrics.resettingTimer("countstuff");
- fail("I expect an already registered metric on this name");
- }
-
- @Test
- public void testReportingGaugeAsCummulativeCounter() {
- String cumulativeCounterCallback = "cumulativeCounterCallback";
- sfxMetrics.registerGaugeAsCumulativeCounter(cumulativeCounterCallback,
- new Gauge() {
- private long i = 0;
-
- @Override
- public Long getValue() {
- return i++;
- }
- });
- reporter.report();
- assertEquals(0, dbank.lastValueFor(SOURCE_NAME, cumulativeCounterCallback).getIntValue());
- reporter.report();
- reporter.report();
- assertEquals(2, dbank.lastValueFor(SOURCE_NAME, cumulativeCounterCallback).getIntValue());
- assertEquals(SignalFxProtocolBuffers.MetricType.CUMULATIVE_COUNTER,
- dbank.registeredMetrics.get(cumulativeCounterCallback));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testDuplicateMetricRegistration() {
- sfxMetrics.counter("countstuff");
- sfxMetrics.incrementalCounter("countstuff");
- fail("I expect an already registered metric on this name");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testUpdatingMetricTypeToIncompatibleValue() {
- reporter.getMetricMetadata()
- .forBuilder(IncrementalCounter.Builder.INSTANCE)
- .withSourceName(SOURCE_NAME)
- .withMetricName("name")
- .createOrGet(metricRegistry)
- .inc(3);
- reporter.getMetricMetadata()
- .forBuilder(IncrementalCounter.Builder.INSTANCE)
- .withSourceName(SOURCE_NAME)
- .withMetricName("name")
- .withMetricType(SignalFxProtocolBuffers.MetricType.GAUGE)
- .createOrGet(metricRegistry);
- fail("I expect an error if it's a gauge");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testCreateOrGetMetricSameNameDifferentType() {
- reporter.getMetricMetadata().forBuilder(IncrementalCounter.Builder.INSTANCE)
- .withSourceName("asource")
- .withMetricName("name")
- .createOrGet(metricRegistry)
- .inc(1);
- reporter.getMetricMetadata().forBuilder(SettableLongGauge.Builder.INSTANCE)
- .withSourceName("asource")
- .withMetricName("name")
- .createOrGet(metricRegistry);
- fail("We shouldn't be able to make it with the same name and different type");
- }
-
- @Test
- public void shouldFailOnNullDefaultSourceMethod_constructor() {
- try {
- new SignalFxReporter.Builder(null, null, null);
- fail("NPE was expected");
- } catch (NullPointerException npe) {
- assertTrue(npe.getMessage().contains("defaultSourceName"));
- }
- }
-
- @Test
- public void shouldFailOnNullDefaultSourceMethod_method() {
- try {
- new SignalFxReporter.Builder(null, "test")
- .setDefaultSourceName(null);
- fail("NPE was expected");
- } catch (NullPointerException npe) {
- assertTrue(npe.getMessage().contains("defaultSourceName"));
- }
- }
-}
diff --git a/signalfx-codahale/src/test/java/com/signalfx/codahale/metrics/util/BasicJvmMetrisTest.java b/signalfx-codahale/src/test/java/com/signalfx/codahale/metrics/util/BasicJvmMetrisTest.java
deleted file mode 100644
index 92e20d3d..00000000
--- a/signalfx-codahale/src/test/java/com/signalfx/codahale/metrics/util/BasicJvmMetrisTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Copyright (C) 2014-2016 SignalFx, Inc. All rights reserved.
- */
-package com.signalfx.codahale.metrics.util;
-
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.concurrent.TimeUnit;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.codahale.metrics.Counter;
-import com.codahale.metrics.Gauge;
-import com.codahale.metrics.Histogram;
-import com.codahale.metrics.Meter;
-import com.codahale.metrics.MetricFilter;
-import com.codahale.metrics.MetricRegistry;
-import com.codahale.metrics.ScheduledReporter;
-import com.codahale.metrics.Timer;
-import com.signalfx.codahale.util.BasicJvmMetrics;
-
-public class BasicJvmMetrisTest {
-
- @Test
- public void testPointsSent() throws Exception {
- MetricRegistry registry = new MetricRegistry();
- new BasicJvmMetrics(registry);
-
- ScheduledReporter reporter = new ScheduledReporter(registry, "test", MetricFilter.ALL,
- TimeUnit.SECONDS, TimeUnit.MILLISECONDS) {
-
- @Override
- public void report(SortedMap gauges, SortedMap counters,
- SortedMap histograms,
- SortedMap meters, SortedMap timers) {
- Assert.assertFalse(gauges.isEmpty());
- Assert.assertNotNull(gauges.get("jvm.uptime"));
- for (Map.Entry entry : gauges.entrySet()) {
- Assert.assertNotNull(entry.getValue().getValue());
- }
- }
- };
-
- reporter.report();
- reporter.close();
- }
-}
diff --git a/signalfx-yammer/README.md b/signalfx-yammer/README.md
deleted file mode 100644
index a9b56678..00000000
--- a/signalfx-yammer/README.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-# signalfx-yammer
-
-:warning: `signalfx-yammer` has been deprecated and will be deleted
-in July 2024. No further releases will be available after June 2024.
-
-Users are encouraged to use the
-[OpenTelemetry Java SDK](https://github.com/open-telemetry/opentelemetry-java) or the
-[Splunk Distribution of OpenTelemetry Java Instrumentation](https://github.com/signalfx/splunk-otel-java)
-to send metrics to Splunk.
-
diff --git a/signalfx-yammer/pom.xml b/signalfx-yammer/pom.xml
deleted file mode 100644
index b8fc27a0..00000000
--- a/signalfx-yammer/pom.xml
+++ /dev/null
@@ -1,79 +0,0 @@
-
-
- 4.0.0
-
-
- com.signalfx.public
- clients-parent
- 1.0.43
-
-
- signalfx-yammer
- Yammer to SignalFx
- jar
-
- Codahale yammer metrics plugin for signalfx / yammer metrics lib v2.0
-
-
- http://www.signalfx.com
-
-
-
- Apache License 2.0
- http://www.apache.org/licenses/LICENSE-2.0.html
- repo
-
-
-
-
- scm:git:git@github.com:signalfx/signalfx-java.git
- scm:git:git@github.com:signalfx/signalfx-java.git
- git@github.com:signalfx/signalfx-java.git
-
-
-
-
- signalfx
- SignalFx
- support+java@signalfx.com
- SignalFx, Inc
- http://www.signalfx.com
-
-
-
-
-
-
- com.signalfx.public
- signalfx-java
-
-
- com.signalfx.public
- signalfx-protoc
-
-
- com.google.guava
- guava
-
-
- com.yammer.metrics
- metrics-core
-
-
-
-
- org.slf4j
- slf4j-simple
-
-
- org.hamcrest
- hamcrest-core
-
-
- junit
- junit
-
-
-
diff --git a/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/AggregateMetricSenderSessionWrapper.java b/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/AggregateMetricSenderSessionWrapper.java
deleted file mode 100644
index 88434a29..00000000
--- a/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/AggregateMetricSenderSessionWrapper.java
+++ /dev/null
@@ -1,364 +0,0 @@
-package com.signalfx.codahale.reporter;
-
-import java.io.Closeable;
-import java.util.Map;
-import java.util.Set;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.signalfx.metrics.SignalFxMetricsException;
-import com.signalfx.metrics.flush.AggregateMetricSender;
-import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers;
-import com.yammer.metrics.core.Histogram;
-import com.yammer.metrics.core.Metered;
-import com.yammer.metrics.core.Metric;
-import com.yammer.metrics.core.MetricName;
-import com.yammer.metrics.core.Sampling;
-import com.yammer.metrics.core.Timer;
-import com.yammer.metrics.stats.Snapshot;
-
-/**
- *
- * class to Aggregate and Send metrics
- * used by SignalFxReporter in report() method
- *
- */
-
-class AggregateMetricSenderSessionWrapper implements Closeable {
- private final AggregateMetricSender.Session metricSenderSession;
- private final Set detailsToAdd;
- private final MetricMetadata metricMetadata;
- private final String defaultSourceName;
- private final String sourceDimension;
- private final boolean injectCurrentTimestamp;
- private final boolean sendExtraMetricDimensions;
- private final ImmutableMap defaultDimensions;
-
- AggregateMetricSenderSessionWrapper(
- AggregateMetricSender.Session metricSenderSession,
- Set detailsToAdd,
- MetricMetadata metricMetadata,
- String defaultSourceName,
- String sourceDimension,
- boolean injectCurrentTimestamp,
- boolean sendExtraMetricDimensions,
- ImmutableMap defaultDimensions) {
- this.metricSenderSession = metricSenderSession;
- this.detailsToAdd = detailsToAdd;
- this.metricMetadata = metricMetadata;
- this.defaultSourceName = defaultSourceName;
- this.sourceDimension = sourceDimension;
- this.injectCurrentTimestamp = injectCurrentTimestamp;
- this.sendExtraMetricDimensions = sendExtraMetricDimensions;
- this.defaultDimensions = defaultDimensions;
- }
-
- @Override
- public void close() {
- try {
- metricSenderSession.close();
- } catch (Exception e) {
- throw new SignalFxMetricsException("Unable to close session and send metrics", e);
- }
- }
-
- // These three called from report
- void addTimer(MetricName key, Timer value) {
- addMetered(key, value);
- addSampling(key, value);
- }
-
- /**
- * Add Histogram metric
- * @param baseName
- * @param histogram
- */
-
- void addHistogram(MetricName baseName,
- Histogram histogram) {
- addMetric(histogram, baseName,
- Optional.of(SignalFxReporter.MetricDetails.COUNT),
- SignalFxProtocolBuffers.MetricType.CUMULATIVE_COUNTER, histogram.count());
- addSampling(baseName, histogram);
- }
-
- /**
- * Add Metered metric
- * @param baseName
- * @param metered
- */
-
- void addMetered(MetricName baseName, Metered metered) {
- addMetric(metered, baseName,
- SignalFxReporter.MetricDetails.COUNT,
- SignalFxProtocolBuffers.MetricType.CUMULATIVE_COUNTER, metered.count());
- addMetric(metered, baseName,
- SignalFxReporter.MetricDetails.RATE_15_MIN,
- SignalFxProtocolBuffers.MetricType.GAUGE, metered.fifteenMinuteRate());
- addMetric(metered, baseName,
- SignalFxReporter.MetricDetails.RATE_1_MIN,
- SignalFxProtocolBuffers.MetricType.GAUGE, metered.oneMinuteRate());
- addMetric(metered, baseName,
- SignalFxReporter.MetricDetails.RATE_5_MIN,
- SignalFxProtocolBuffers.MetricType.GAUGE, metered.fiveMinuteRate());
-
- addMetric(metered, baseName,
- SignalFxReporter.MetricDetails.RATE_MEAN,
- SignalFxProtocolBuffers.MetricType.GAUGE, metered.meanRate());
- }
-
- /**
- * Add sampling
- * @param baseName
- * @param sampling
- */
-
- private void addSampling(MetricName baseName, Sampling sampling) {
- Metric metric = (Metric)sampling;
- final Snapshot snapshot = sampling.getSnapshot();
- addMetric(metric, baseName,
- SignalFxReporter.MetricDetails.MEDIAN,
- SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.getMedian());
- addMetric(metric, baseName,
- SignalFxReporter.MetricDetails.PERCENT_75,
- SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get75thPercentile());
- addMetric(metric, baseName,
- SignalFxReporter.MetricDetails.PERCENT_95,
- SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get95thPercentile());
- addMetric(metric, baseName,
- SignalFxReporter.MetricDetails.PERCENT_98,
- SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get98thPercentile());
- addMetric(metric, baseName,
- SignalFxReporter.MetricDetails.PERCENT_99,
- SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get99thPercentile());
- addMetric(metric, baseName,
- SignalFxReporter.MetricDetails.PERCENT_999,
- SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get999thPercentile());
- addMetric(metric, baseName,
- SignalFxReporter.MetricDetails.MAX,
- SignalFxProtocolBuffers.MetricType.GAUGE, getMax(snapshot));
- addMetric(metric, baseName,
- SignalFxReporter.MetricDetails.MIN,
- SignalFxProtocolBuffers.MetricType.GAUGE, getMin(snapshot));
-
-
- // These are slower to calculate. Only calculate if we need.
- if (detailsToAdd.contains(SignalFxReporter.MetricDetails.STD_DEV)) {
- addMetric(metric, baseName,
- SignalFxReporter.MetricDetails.STD_DEV,
- SignalFxProtocolBuffers.MetricType.GAUGE, getStdDev(snapshot));
- }
- if (detailsToAdd.contains(SignalFxReporter.MetricDetails.MEAN)) {
- addMetric(metric, baseName,
- SignalFxReporter.MetricDetails.MEAN,
- SignalFxProtocolBuffers.MetricType.GAUGE, getMean(snapshot));
- }
- }
-
- /**
- * Add metric
- * @param metric
- * @param codahaleName
- * @param defaultMetricType
- * @param originalValue
- */
-
- void addMetric(Metric metric, MetricName codahaleName,
- SignalFxProtocolBuffers.MetricType defaultMetricType,
- Object originalValue) {
- addMetric(metric, codahaleName, Optional.absent(),
- defaultMetricType, originalValue);
- }
-
- /**
- * Add metric
- * @param metric
- * @param codahaleName
- * @param metricDetails
- * @param defaultMetricType
- * @param originalValue
- */
-
- private void addMetric(Metric metric, MetricName codahaleName, SignalFxReporter.MetricDetails metricDetails,
- SignalFxProtocolBuffers.MetricType defaultMetricType,
- Object originalValue) {
- addMetric(metric, codahaleName, Optional.of(metricDetails),
- defaultMetricType, originalValue);
-
- }
-
- /**
- * Add metric
- * @param metric
- * @param codahaleName
- * @param metricDetails
- * @param defaultMetricType
- * @param originalValue
- */
-
- void addMetric(Metric metric, MetricName codahaleName,
- Optional metricDetails,
- SignalFxProtocolBuffers.MetricType defaultMetricType, Object originalValue) {
- final Number value;
- if (originalValue instanceof Number) {
- value = (Number) originalValue;
- } else if (originalValue instanceof Boolean) {
- value = ((Boolean)originalValue).booleanValue() ? 1 : 0;
- } else {
- // Unsupported type
- return;
- }
- final String metricDetailsMetricNameSuffix;
- if (metricDetails.isPresent()) {
- if (!detailsToAdd.contains(metricDetails.get())) {
- return;
- }
- metricDetailsMetricNameSuffix = "." + metricDetails.get().getDescription();
- } else {
- metricDetailsMetricNameSuffix = "";
- }
- Optional userSetMetricType = metricMetadata.getMetricType(metric);
- SignalFxProtocolBuffers.MetricType metricType = userSetMetricType.or(defaultMetricType);
- Map tags = metricMetadata.getTags(metric);
- final String sourceName = Optional.fromNullable(tags.get(MetricMetadata.SOURCE)).or(defaultSourceName);
- final String metricName = Optional.fromNullable(tags.get(MetricMetadata.METRIC)).or(codahaleName.getName()) + metricDetailsMetricNameSuffix;
-
- SignalFxProtocolBuffers.DataPoint.Builder builder = SignalFxProtocolBuffers.DataPoint
- .newBuilder()
- .setMetric(metricName)
- .setMetricType(metricType);
-
- if (!sourceDimension.equals("") && !tags.containsKey(sourceDimension)) {
- builder.addDimensions(SignalFxProtocolBuffers.Dimension.newBuilder()
- .setKey(sourceDimension).setValue(sourceName));
- }
-
- ImmutableSet ignoredDimensions = ImmutableSet.of(
- MetricMetadata.SOURCE, MetricMetadata.METRIC);
-
- for (Map.Entry entry: tags.entrySet()) {
- if (!ignoredDimensions.contains(entry.getKey())) {
- builder.addDimensions(SignalFxProtocolBuffers.Dimension.newBuilder()
- .setKey(entry.getKey()).setValue(entry.getValue()));
- }
- }
-
- if (sendExtraMetricDimensions) {
- if (!Strings.isNullOrEmpty(codahaleName.getGroup())) {
- builder.addDimensions(SignalFxProtocolBuffers.Dimension.newBuilder()
- .setKey("metric_group").setValue(codahaleName.getGroup()));
- }
- if (!Strings.isNullOrEmpty(codahaleName.getType())) {
- builder.addDimensions(SignalFxProtocolBuffers.Dimension.newBuilder()
- .setKey("metric_type").setValue(codahaleName.getType()));
- }
- }
-
- for (Map.Entry entry : defaultDimensions.entrySet()) {
- String dimName = entry.getKey();
- String dimValue = entry.getValue();
- if (!ignoredDimensions.contains(dimName) && !tags.containsKey(dimName)) {
- builder.addDimensions(SignalFxProtocolBuffers.Dimension.newBuilder().setKey(dimName)
- .setValue(dimValue));
- }
- }
-
- if (injectCurrentTimestamp) {
- final long currentTimestamp = System.currentTimeMillis();
- builder.setTimestamp(currentTimestamp);
- }
-
- if (value instanceof Long || value instanceof Integer || value instanceof Short) {
- builder.setValue(SignalFxProtocolBuffers.Datum
- .newBuilder().setIntValue(value.longValue()));
- } else {
- final double doubleToSend = value.doubleValue();
- if (Double.isInfinite(doubleToSend) || Double.isNaN(doubleToSend)) {
- return;
- }
- builder.setValue(SignalFxProtocolBuffers.Datum.newBuilder()
- .setDoubleValue(doubleToSend));
- }
- metricSenderSession.setDatapoint(builder.build());
- }
-
- //--- Aditional Methods
-
- /**
- * calculate Max value for snapshot
- * @param shapshot
- * @return
- */
-
- private double getMax(Snapshot snapshot) {
- double[] values = snapshot.getValues();
- if (values.length == 0) {
- return 0;
- }
- return values[values.length - 1];
- }
-
- /**
- * calculate Min value for snapshot
- * @param shapshot
- * @return
- */
-
- private double getMin(Snapshot snapshot) {
- double[] values = snapshot.getValues();
- if (values.length == 0) {
- return 0;
- }
- return values[0];
- }
-
- /**
- * calculate standard deviation for snapshot
- * @param shapshot
- * @return
- */
-
- private double getStdDev(Snapshot snapshot) {
- // two-pass algorithm for variance, avoids numeric overflow
- double[] values = snapshot.getValues();
-
- if (values.length <= 1) {
- return 0;
- }
-
- final double mean = getMean(snapshot);
- double sum = 0;
-
- for (double value : values) {
- final double diff = value - mean;
- sum += diff * diff;
- }
-
- final double variance = sum / (values.length - 1);
- return Math.sqrt(variance);
- }
-
- /**
- * calculate Mean value for snapshot
- * @param shapshot
- * @return
- */
-
- private double getMean(Snapshot shapshot) {
-
- double[] values = shapshot.getValues();
-
- if (values.length == 0) {
- return 0;
- }
-
- double sum = 0;
- for (double value : values) {
- sum += value;
- }
- return sum / values.length;
- }
-
-}
diff --git a/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/CustomScheduledReporter.java b/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/CustomScheduledReporter.java
deleted file mode 100644
index f43b5482..00000000
--- a/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/CustomScheduledReporter.java
+++ /dev/null
@@ -1,204 +0,0 @@
-package com.signalfx.codahale.reporter;
-
-import java.util.SortedMap;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.*;
-
-import com.yammer.metrics.core.Counter;
-import com.yammer.metrics.core.Gauge;
-import com.yammer.metrics.core.Histogram;
-import com.yammer.metrics.core.Meter;
-import com.yammer.metrics.core.MetricPredicate;
-import com.yammer.metrics.core.MetricsRegistry;
-import com.yammer.metrics.core.Timer;
-import com.yammer.metrics.core.MetricName;
-import com.yammer.metrics.core.Metric;
-
-/**
- * The abstract base class for all scheduled reporters (i.e., reporters which process a registry's
- * metrics periodically).
- *
- */
-public abstract class CustomScheduledReporter {
- /**
- * A simple named thread factory.
- */
- @SuppressWarnings("NullableProblems")
- private static class NamedThreadFactory implements ThreadFactory {
- private final ThreadGroup group;
- private final AtomicInteger threadNumber = new AtomicInteger(1);
- private final String namePrefix;
-
- private NamedThreadFactory(String name) {
- final SecurityManager s = System.getSecurityManager();
- this.group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
- this.namePrefix = "metrics-" + name + "-thread-";
- }
-
- @Override
- public Thread newThread(Runnable r) {
- final Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0);
- t.setDaemon(true);
- if (t.getPriority() != Thread.NORM_PRIORITY) {
- t.setPriority(Thread.NORM_PRIORITY);
- }
- return t;
- }
- }
-
- private final MetricsRegistry registry;
- private final ScheduledExecutorService executor;
- private final MetricPredicate filter;
-
- /**
- * Creates a new {@link CustomScheduledReporter} instance.
- *
- * @param registry the MetricsRegistry containing the metrics this
- * reporter will report
- * @param name the reporter's name
- * @param filter the filter for which metrics to report
- * @param rateUnit
- * @param durationUnit
- */
- protected CustomScheduledReporter(MetricsRegistry registry,
- String name,
- MetricPredicate filter,
- TimeUnit rateUnit,
- TimeUnit durationUnit) {
- this.registry = registry;
- this.filter = filter;
- this.executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory(name));
- }
-
- /**
- * get Metrics by class and predicate
- *
- * @param klass
- * @param filter
- * @return
- */
-
- @SuppressWarnings("unchecked")
- private SortedMap getMetrics(Class klass, MetricPredicate filter) {
-
- Map allMetrics = registry.allMetrics();
- final TreeMap timers = new TreeMap();
-
- for (Map.Entry entry : allMetrics.entrySet()) {
- if (klass.isInstance(entry.getValue()) && filter.matches(entry.getKey(),
- entry.getValue())) {
- timers.put(entry.getKey(), (T) entry.getValue());
- }
- }
-
- return Collections.unmodifiableSortedMap(timers);
- }
-
- /**
- * get all Gauge metrics
- * @param filter
- * @return
- */
-
- private SortedMap getGauges(MetricPredicate filter) {
- return getMetrics(Gauge.class, filter);
- }
-
- /**
- * get all Counter metrics
- * @param filter
- * @return
- */
-
- private SortedMap getCounters(MetricPredicate filter) {
- return getMetrics(Counter.class, filter);
- }
-
- /**
- * get all Histogram metrics
- * @param filter
- * @return
- */
-
- private SortedMap getHistograms(MetricPredicate filter) {
- return getMetrics(Histogram.class, filter);
- }
-
- /**
- * get all Meters metrics
- * @param filter
- * @return
- */
-
- private SortedMap getMeters(MetricPredicate filter) {
- return getMetrics(Meter.class, filter);
- }
-
- /**
- * get all Timers metrics
- * @param filter
- * @return
- */
-
- private SortedMap getTimers(MetricPredicate filter) {
- return getMetrics(Timer.class, filter);
- }
-
- /**
- * Starts the reporter polling at the given period.
- *
- * @param period the amount of time between polls
- * @param unit the unit for {@code period}
- */
- public void start(long period, TimeUnit unit) {
- executor.scheduleAtFixedRate(new Runnable() {
- @Override
- public void run() {
- report();
- }
- }, period, period, unit);
- }
-
- /**
- * Stops the reporter and shuts down its thread of execution.
- */
- public void stop() {
- executor.shutdown();
- try {
- executor.awaitTermination(1, TimeUnit.SECONDS);
- } catch (InterruptedException ignored) {
- // do nothing
- }
- }
-
- /**
- * Report the current values of all metrics in the registry.
- */
- public void report() {
- report(getGauges(filter),
- getCounters(filter),
- getHistograms(filter),
- getMeters(filter),
- getTimers(filter));
- }
-
- /**
- * Called periodically by the polling thread. Subclasses should report all the given metrics.
- *
- * @param gauges all of the gauges in the registry
- * @param counters all of the counters in the registry
- * @param histograms all of the histograms in the registry
- * @param meters all of the meters in the registry
- * @param timers all of the timers in the registry
- */
- public abstract void report(SortedMap gauges,
- SortedMap counters,
- SortedMap histograms,
- SortedMap meters,
- SortedMap timers);
-
-}
diff --git a/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/MetricMetadata.java b/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/MetricMetadata.java
deleted file mode 100644
index 3d525189..00000000
--- a/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/MetricMetadata.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package com.signalfx.codahale.reporter;
-
-import java.util.Map;
-import com.yammer.metrics.core.Metric;
-import com.google.common.base.Optional;
-import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers;
-
-/**
- * Allows users to modify a metric with different source or metric parts than the default we pick
- * from codahale. Note: This class must be thread safe.
- */
-public interface MetricMetadata {
- public static final String SOURCE = "source";
- public static final String METRIC = "metric";
- public Map getTags(Metric metric);
- public Optional getMetricType(Metric metric);
-
- /**
- * Create an object to tag a metric with data. Registering two different metrics with the same
- * metadata will result in an exception.
- * @param metric The metric will tag.
- * @param The type of metric. It is implied by the metric type.
- * @return An object to tag the given metric.
- */
- public Tagger forMetric(M metric);
-
- @Deprecated
- public Tagger tagMetric(M metric);
-
- /**
- * Removes the specified metric from the metric metadata.
- * @param metric The metric to remove, cannot be null.
- * @return True if the metric was found and removed, false otherwise
- */
- public boolean removeMetric(M metric);
-
- public interface TaggerBase> {
- /**
- * Tag the metric with a sf_source
- * @param sourceName Source name for the sf_source
- * @return this
- * @deprecated The use of the build in source parameter is deprecated and discouraged. Use
- * {@link #withDimension(String, String)} instead.
- */
- @Deprecated
- T withSourceName(String sourceName);
-
- /**
- * Changes the metric name of this metric from the default (which is the codahale metric
- * name), to another string
- * @param metricName The new name in SignalFx of this metric
- * @return this
- */
- T withMetricName(String metricName);
-
- /**
- * Adds a dimension to this metric
- * @param key The dimension key to add
- * @param value The dimensino value to add
- * @return this
- */
- T withDimension(String key, String value);
-
- /**
- * Changes the default metric type of this metric to the SignalFx metric type passed in
- * @param metricType The new metric type of this metric
- * @return this
- */
- T withMetricType(SignalFxProtocolBuffers.MetricType metricType);
- }
-
- public interface Tagger extends TaggerBase> {
-
- /**
- * Returns the tagged metric
- * @return the tagged metric
- */
- M metric();
- }
-
-}
diff --git a/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/MetricMetadataImpl.java b/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/MetricMetadataImpl.java
deleted file mode 100644
index 48efbce8..00000000
--- a/signalfx-yammer/src/main/java/com/signalfx/codahale/reporter/MetricMetadataImpl.java
+++ /dev/null
@@ -1,159 +0,0 @@
-package com.signalfx.codahale.reporter;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import com.yammer.metrics.core.Metric;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.signalfx.metrics.protobuf.SignalFxProtocolBuffers;
-
-/**
- *
- * Implementation of MetricMetadata
- *
- */
-
-public class MetricMetadataImpl implements MetricMetadata {
- private final ConcurrentMap metaDataCollection;
-
- public MetricMetadataImpl() {
- // This map must be thread safe
- metaDataCollection = new ConcurrentHashMap