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

com.wavefront.ingester.OpenTSDBMetricDecoder Maven / Gradle / Ivy

There is a newer version: 2023-22.3
Show newest version
package com.wavefront.ingester;

import com.google.common.base.Preconditions;

import java.util.List;

import com.google.common.collect.ImmutableList;

import wavefront.report.ReportMetric;

/**
 * OpenTSDB decoder that takes in a point of the type:
 *
 * PUT [metric] [timestamp] [value] [annotations]
 *
 * @author Clement Pang ([email protected]).
 */
public class OpenTSDBMetricDecoder implements ReportableEntityDecoder {

  private static final AbstractIngesterFormatter FORMAT =
      ReportMetricIngesterFormatter.newBuilder().
          caseInsensitiveLiterals(ImmutableList.of("put")).
          text(ReportMetric::setMetric).
          timestamp(ReportMetric::setTimestamp).
          value(ReportMetric::setValue).
          annotationList(ReportMetric::setAnnotations).
          build();
  private final String hostName;
  private final List customSourceTags;

  public OpenTSDBMetricDecoder(List customSourceTags) {
    this("unknown", customSourceTags);
  }

  public OpenTSDBMetricDecoder(String hostName, List customSourceTags) {
    Preconditions.checkNotNull(hostName);
    Preconditions.checkNotNull(customSourceTags);
    this.hostName = hostName;
    this.customSourceTags = customSourceTags;
  }

  @Override
  public void decode(String msg, List out, String customerId, IngesterContext ctx) {
    ReportMetric point = FORMAT.drive(msg, () -> hostName, customerId, customSourceTags, null, null, null, null, ctx);
    if (out != null) {
      out.add(point);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy