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

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

There is a newer version: 4.8
Show newest version
package com.wavefront.ingester;

import com.google.common.base.Preconditions;

import java.util.List;

import sunnylabs.report.ReportPoint;

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

  private final String hostName;
  private static final IngesterFormatter FORMAT = IngesterFormatter.newBuilder().whiteSpace()
      .appendCaseInsensitiveLiteral("put").whiteSpace()
      .appendMetricName().whiteSpace()
      .appendTimestamp().whiteSpace()
      .appendValue().whiteSpace()
      .appendAnnotationsConsumer().whiteSpace().build();
  private List customSourceTags;

  public OpenTSDBDecoder(List customSourceTags) {
    this.hostName = "unknown";
    Preconditions.checkNotNull(customSourceTags);
    this.customSourceTags = customSourceTags;
  }

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

  @Override
  public void decodeReportPoints(String msg, List out, String customerId) {
    ReportPoint point = FORMAT.drive(msg, hostName, customerId, customSourceTags);
    if (out != null) {
      out.add(point);
    }
  }

  @Override
  public void decodeReportPoints(String msg, List out) {
    ReportPoint point = FORMAT.drive(msg, hostName, "dummy", customSourceTags);
    if (out != null) {
      out.add(point);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy