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

com.wavefront.agent.logsharvesting.ReadProcessor Maven / Gradle / Ivy

There is a newer version: 9999.0
Show newest version
package com.wavefront.agent.logsharvesting;

import com.yammer.metrics.core.Counter;
import com.yammer.metrics.core.Gauge;
import com.yammer.metrics.core.Histogram;
import com.yammer.metrics.core.Metered;
import com.yammer.metrics.core.MetricName;
import com.yammer.metrics.core.MetricProcessor;
import com.yammer.metrics.core.Timer;
import com.yammer.metrics.core.WavefrontHistogram;

/**
 * @author Mori Bellamy ([email protected])
 */
public class ReadProcessor implements MetricProcessor {
  @Override
  public void processMeter(MetricName name, Metered meter, ReadProcessorContext context) {
    throw new UnsupportedOperationException();
  }

  @Override
  public void processCounter(MetricName name, Counter counter, ReadProcessorContext context) {
    counter.inc(context.getValue() == null ? 1L : Math.round(context.getValue()));
  }

  @Override
  public void processHistogram(MetricName name, Histogram histogram, ReadProcessorContext context) {
    if (histogram instanceof WavefrontHistogram) {
      ((WavefrontHistogram) histogram).update(context.getValue());
    } else {
      histogram.update(Math.round(context.getValue()));
    }
  }

  @Override
  public void processTimer(MetricName name, Timer timer, ReadProcessorContext context) {
    throw new UnsupportedOperationException();
  }

  @Override
  @SuppressWarnings("unchecked")
  public void processGauge(MetricName name, Gauge gauge, ReadProcessorContext context) throws Exception {
    if (context.getValue() == null) {
      throw new MalformedMessageException("Need an explicit value for updating a gauge.");
    }
    ((ChangeableGauge) gauge).setValue(context.getValue());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy