com.yammer.metrics.core.Histogram Java Examples

The following examples show how to use com.yammer.metrics.core.Histogram. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomReporter.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public void processHistogram(final MetricName name,
        final Histogram histogram, final PrintStream stream) {
    final Snapshot snapshot = histogram.getSnapshot();
    stream.printf(locale, "               min = %,2.2f\n", histogram.min());
    stream.printf(locale, "               max = %,2.2f\n", histogram.max());
    stream.printf(locale, "              mean = %,2.2f\n", histogram.mean());
    stream.printf(locale, "            stddev = %,2.2f\n",
            histogram.stdDev());
    stream.printf(locale, "            median = %,2.2f\n",
            snapshot.getMedian());
    stream.printf(locale, "              75%% <= %,2.2f\n",
            snapshot.get75thPercentile());
    stream.printf(locale, "              95%% <= %,2.2f\n",
            snapshot.get95thPercentile());
    stream.printf(locale, "              98%% <= %,2.2f\n",
            snapshot.get98thPercentile());
    stream.printf(locale, "              99%% <= %,2.2f\n",
            snapshot.get99thPercentile());
    stream.printf(locale, "            99.9%% <= %,2.2f\n",
            snapshot.get999thPercentile());
}
 
Example #2
Source File: YammerFacadeMetric.java    From storm-metrics-reporter with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void processHistogram(final MetricName metricName,
                             final Histogram histogram,
                             final Map context) throws Exception {

  final Snapshot snapshot = histogram.getSnapshot();

  final Map subMetrics =
          ImmutableMap
                  .builder()
                  .put("75percentile", snapshot.get75thPercentile())
                  .put("95percentile", snapshot.get95thPercentile())
                  .put("99percentile", snapshot.get99thPercentile())
                  .put("median", snapshot.getMedian())
                  .put("mean", histogram.mean())
                  .put("min", histogram.min())
                  .put("max", histogram.max())
                  .put("stddev", histogram.stdDev())
                  .build();


  context.put(toString(metricName), subMetrics);
}
 
Example #3
Source File: ScheduledReporterTest.java    From ambari-metrics with Apache License 2.0 6 votes vote down vote up
private Set<Entry<MetricName, Metric>> set(List<Metric> metrics) {
  final Map<MetricName, Metric> map = new HashMap<MetricName, Metric>();
  for (Metric metric : metrics) {
    String name = null;
    if (metric instanceof Gauge) {
      name = "gauge";
    } else if (metric instanceof Counter) {
      name = "counter";
    } else if (metric instanceof Histogram) {
      name = "histogram";
    } else if (metric instanceof Meter) {
      name = "meter";
    } else if (metric instanceof Timer) {
      name = "timer";
    }
    map.put(new MetricName(System.class, name), metric);
  }
  return map.entrySet();
}
 
Example #4
Source File: JSONReporter.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Override
public void processHistogram(MetricName name, Histogram histogram, Context context) throws Exception {
  MetricInfo info = context.getMetricInfo(name);
  long time = context.getTime();
  info.addNumber("timestamp", time);
  info.addNumber("min", histogram.min());
  info.addNumber("max", histogram.max());
  info.addNumber("mean", histogram.mean());
  info.addNumber("stdDev", histogram.stdDev());

  Snapshot snapshot = histogram.getSnapshot();
  info.addNumber("median", snapshot.getMedian());
  info.addNumber("75%", snapshot.get75thPercentile());
  info.addNumber("95%", snapshot.get95thPercentile());
  info.addNumber("98%", snapshot.get98thPercentile());
  info.addNumber("99%", snapshot.get99thPercentile());
  info.addNumber("99.9%", snapshot.get999thPercentile());
}
 
Example #5
Source File: CustomReporter.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@Override
public void processHistogram(final MetricName name,
        final Histogram histogram, final PrintStream stream) {
    final Snapshot snapshot = histogram.getSnapshot();
    stream.printf(locale, "               min = %,2.2f\n", histogram.min());
    stream.printf(locale, "               max = %,2.2f\n", histogram.max());
    stream.printf(locale, "              mean = %,2.2f\n", histogram.mean());
    stream.printf(locale, "            stddev = %,2.2f\n",
            histogram.stdDev());
    stream.printf(locale, "            median = %,2.2f\n",
            snapshot.getMedian());
    stream.printf(locale, "              75%% <= %,2.2f\n",
            snapshot.get75thPercentile());
    stream.printf(locale, "              95%% <= %,2.2f\n",
            snapshot.get95thPercentile());
    stream.printf(locale, "              98%% <= %,2.2f\n",
            snapshot.get98thPercentile());
    stream.printf(locale, "              99%% <= %,2.2f\n",
            snapshot.get99thPercentile());
    stream.printf(locale, "            99.9%% <= %,2.2f\n",
            snapshot.get999thPercentile());
}
 
Example #6
Source File: HdfsDirectory.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
protected MetricsGroup createNewMetricsGroup(String scope) {
  MetricName readRandomAccessName = new MetricName(ORG_APACHE_BLUR, HDFS, "Read Random Latency in \u00B5s", scope);
  MetricName readStreamAccessName = new MetricName(ORG_APACHE_BLUR, HDFS, "Read Stream Latency in \u00B5s", scope);
  MetricName writeAcccessName = new MetricName(ORG_APACHE_BLUR, HDFS, "Write Latency in \u00B5s", scope);
  MetricName readRandomThroughputName = new MetricName(ORG_APACHE_BLUR, HDFS, "Read Random Throughput", scope);
  MetricName readStreamThroughputName = new MetricName(ORG_APACHE_BLUR, HDFS, "Read Stream Throughput", scope);
  MetricName readSeekName = new MetricName(ORG_APACHE_BLUR, HDFS, "Read Stream Seeks", scope);
  MetricName writeThroughputName = new MetricName(ORG_APACHE_BLUR, HDFS, "Write Throughput", scope);
  MetricName totalHdfsBlocks = new MetricName(ORG_APACHE_BLUR, HDFS, "Hdfs Blocks Total", scope);
  MetricName localHdfsBlocks = new MetricName(ORG_APACHE_BLUR, HDFS, "Hdfs Blocks Local", scope);

  Histogram readRandomAccess = Metrics.newHistogram(readRandomAccessName);
  Histogram readStreamAccess = Metrics.newHistogram(readStreamAccessName);
  Histogram writeAccess = Metrics.newHistogram(writeAcccessName);
  Meter readRandomThroughput = Metrics.newMeter(readRandomThroughputName, "Read Random Bytes", TimeUnit.SECONDS);
  Meter readStreamThroughput = Metrics.newMeter(readStreamThroughputName, "Read Stream Bytes", TimeUnit.SECONDS);
  Meter readStreamSeek = Metrics.newMeter(readSeekName, "Read Stream Seeks", TimeUnit.SECONDS);
  Meter writeThroughput = Metrics.newMeter(writeThroughputName, "Write Bytes", TimeUnit.SECONDS);
  Counter totalHdfsBlock = Metrics.newCounter(totalHdfsBlocks);
  Counter localHdfsBlock = Metrics.newCounter(localHdfsBlocks);

  return new MetricsGroup(readRandomAccess, readStreamAccess, writeAccess, readRandomThroughput,
      readStreamThroughput, readStreamSeek, writeThroughput, totalHdfsBlock, localHdfsBlock);
}
 
Example #7
Source File: MemoryReporter.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Override
public void processHistogram(MetricName name, Histogram histogram,
    ConcurrentMap<String, org.apache.blur.thrift.generated.Metric> context) throws Exception {
  org.apache.blur.thrift.generated.Metric metric = getMetric(name, context);
  metric.putToDoubleMap("min", histogram.min());
  metric.putToDoubleMap("max", histogram.max());
  metric.putToDoubleMap("mean", histogram.mean());
  metric.putToDoubleMap("stdDev", histogram.stdDev());

  Snapshot snapshot = histogram.getSnapshot();
  metric.putToDoubleMap("median", snapshot.getMedian());
  metric.putToDoubleMap("75%", snapshot.get75thPercentile());
  metric.putToDoubleMap("95%", snapshot.get95thPercentile());
  metric.putToDoubleMap("98%", snapshot.get98thPercentile());
  metric.putToDoubleMap("99%", snapshot.get99thPercentile());
  metric.putToDoubleMap("99.9%", snapshot.get999thPercentile());
}
 
Example #8
Source File: KafkaTimelineMetricsReporter.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public void processHistogram(MetricName name, Histogram histogram, Context context) throws Exception {
  final long currentTimeMillis = System.currentTimeMillis();
  final Snapshot snapshot = histogram.getSnapshot();
  final String sanitizedName = sanitizeName(name);

  String[] metricHNames = cacheKafkaSummarizable(currentTimeMillis, sanitizedName, histogram);
  String[] metricSNames = cacheKafkaSnapshot(currentTimeMillis, sanitizedName, snapshot);

  String[] metricNames = (String[]) ArrayUtils.addAll(metricHNames, metricSNames);

  populateMetricsList(context, MetricType.GAUGE, metricNames);
}
 
Example #9
Source File: AggregateMetricSenderSessionWrapper.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #10
Source File: MetricsGroup.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
MetricsGroup(Histogram readRandomAccess, Histogram readStreamAccess, Histogram writeAccess,
    Meter readRandomThroughput, Meter readStreamThroughput, Meter readStreamSeek, Meter writeThroughput,
    Counter totalHdfsBlock, Counter localHdfsBlock) {
  this.readRandomAccess = readRandomAccess;
  this.readStreamAccess = readStreamAccess;
  this.writeAccess = writeAccess;
  this.readRandomThroughput = readRandomThroughput;
  this.readStreamThroughput = readStreamThroughput;
  this.writeThroughput = writeThroughput;
  this.readStreamSeek = readStreamSeek;
  this.totalHdfsBlock = totalHdfsBlock;
  this.localHdfsBlock = localHdfsBlock;
}
 
Example #11
Source File: StatsDReporterTest.java    From kafka-statsd-metrics2 with Apache License 2.0 5 votes vote down vote up
static Histogram createHistogram() throws Exception {
  final Histogram mock = mock(Histogram.class);
  setupSummarizableMock(mock);
  setupSamplingMock(mock);
  return configureMatcher(mock, doAnswer(new MetricsProcessorAction() {
    @Override
    void delegateToProcessor(MetricProcessor<Object> processor, MetricName name, Object context) throws Exception {
      processor.processHistogram(name, mock, context);
    }
  }));
}
 
Example #12
Source File: StatsDReporterTest.java    From kafka-statsd-metrics2 with Apache License 2.0 5 votes vote down vote up
@Test
public final void histogram() throws Exception {
  addMetricAndRunReporter(
      new Callable<Histogram>() {
        @Override
        public Histogram call() throws Exception {
          return createHistogram();
        }
      });
  verifyHistogram();
}
 
Example #13
Source File: YammerMetricProcessor.java    From cruise-control with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void processHistogram(MetricName metricName, Histogram histogram, Context context) {
  if (MetricsUtils.isInterested(metricName)) {
    LOG.trace("Processing metric {} of type Histogram.", metricName);
    // Get max metric value
    CruiseControlMetric ccm = MetricsUtils.toCruiseControlMetric(context.time(),
                                                                 context.brokerId(),
                                                                 metricName,
                                                                 histogram.max(),
                                                                 MetricsUtils.ATTRIBUTE_MAX);
    context.reporter().sendCruiseControlMetric(ccm);

    // Get mean metric value
    ccm = MetricsUtils.toCruiseControlMetric(context.time(),
                                             context.brokerId(),
                                             metricName,
                                             histogram.mean(),
                                             MetricsUtils.ATTRIBUTE_MEAN);
    context.reporter().sendCruiseControlMetric(ccm);

    Snapshot snapshot = histogram.getSnapshot();
    // Get 50th percentile (i.e. median) metric value
    ccm = MetricsUtils.toCruiseControlMetric(context.time(),
                                             context.brokerId(),
                                             metricName,
                                             snapshot.getMedian(),
                                             MetricsUtils.ATTRIBUTE_50TH_PERCENTILE);
    context.reporter().sendCruiseControlMetric(ccm);

    // Get 999th percentile metric value
    ccm = MetricsUtils.toCruiseControlMetric(context.time(),
                                             context.brokerId(),
                                             metricName,
                                             snapshot.get999thPercentile(),
                                             MetricsUtils.ATTRIBUTE_999TH_PERCENTILE);
    context.reporter().sendCruiseControlMetric(ccm);
  }
}
 
Example #14
Source File: ScheduledReporterTest.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
  Gauge g = registry.newGauge(System.class, "gauge", gauge);
  Counter counter = registry.newCounter(System.class, "counter");
  Histogram histogram = registry.newHistogram(System.class, "histogram");
  Meter meter = registry.newMeter(System.class, "meter", "empty", TimeUnit.MILLISECONDS);
  Timer timer = registry.newTimer(System.class, "timer");
  list.add(g);
  list.add(counter);
  list.add(histogram);
  list.add(meter);
  list.add(timer);
  reporter.start(200, TimeUnit.MILLISECONDS);
}
 
Example #15
Source File: KafkaTimelineMetricsReporterTest.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  @SuppressWarnings({ "rawtypes", "unchecked" })
  Gauge g = registry.newGauge(System.class, "gauge", gauge);
  Counter counter = registry.newCounter(System.class, "counter");
  Histogram histogram = registry.newHistogram(System.class, "histogram");
  Meter meter = registry.newMeter(System.class, "meter", "empty", TimeUnit.MILLISECONDS);
  Timer timer = registry.newTimer(System.class, "timer");
  list.add(g);
  list.add(counter);
  list.add(histogram);
  list.add(meter);
  list.add(timer);
  Properties properties = new Properties();
  properties.setProperty("zookeeper.connect", "localhost:2181");
  properties.setProperty("kafka.timeline.metrics.sendInterval", "5900");
  properties.setProperty("kafka.timeline.metrics.maxRowCacheSize", "10000");
  properties.setProperty("kafka.timeline.metrics.hosts", "localhost:6188");
  properties.setProperty("kafka.timeline.metrics.port", "6188");
  properties.setProperty("kafka.timeline.metrics.reporter.enabled", "true");
  properties.setProperty("external.kafka.metrics.exclude.prefix", "a.b.c");
  properties.setProperty("external.kafka.metrics.include.prefix", "a.b.c.d");
  properties.setProperty("external.kafka.metrics.include.regex", "a.b.c.*.f");
  properties.setProperty("kafka.timeline.metrics.instanceId", "cluster");
  properties.setProperty("kafka.timeline.metrics.set.instanceId", "false");
  props = new VerifiableProperties(properties);
}
 
Example #16
Source File: StormYammerMetricsAdapter.java    From storm-metrics-reporter with Apache License 2.0 4 votes vote down vote up
/**
 * See {@link com.yammer.metrics.core.MetricsRegistry#newHistogram}
 */
public Histogram createHistogram(final String component, final String methodName, final boolean biased) {
  return metricsRegistry.newHistogram(getMetricName(component, methodName), biased);
}
 
Example #17
Source File: SignalFxReporterTest.java    From signalfx-java with Apache License 2.0 4 votes vote down vote up
private void testReporterWithDetails(){
	
	StoredDataPointReceiver dbank = new StoredDataPointReceiver();
       assertEquals(0, dbank.addDataPoints.size());

       Set<SignalFxReporter.MetricDetails> detailsToAdd = new HashSet<SignalFxReporter.MetricDetails>();
       detailsToAdd.add(SignalFxReporter.MetricDetails.STD_DEV);
       detailsToAdd.add(SignalFxReporter.MetricDetails.MEAN);
       
       MetricsRegistry metricRegistery = new MetricsRegistry();
       SignalFxReporter reporter = new SignalFxReporter.Builder(metricRegistery, new StaticAuthToken(""), "myserver")
               .setDataPointReceiverFactory(new StaticDataPointReceiverFactory(dbank))
               .setDetailsToAdd(
           		ImmutableSet.of(
       				SignalFxReporter.MetricDetails.COUNT,
       				SignalFxReporter.MetricDetails.MIN, 
       				SignalFxReporter.MetricDetails.MAX
           		)
               )
               .setName("testReporter")
               .setDefaultSourceName("defaultSource")
               .useLocalTime(false)
               .setOnSendErrorHandlerCollection(
               		Collections.<OnSendErrorHandler>singleton(new OnSendErrorHandler(){
                       	public void handleError(MetricError error){
                       		System.out.println("" + error.getMessage());
                       	}
                       })
               )
               .setFilter(MetricPredicate.ALL)
               .setRateUnit(TimeUnit.SECONDS)
               .setDetailsToAdd(detailsToAdd)
               .build();
       
       final MetricMetadata metricMetadata = reporter.getMetricMetadata();
       
       MetricName histogramName = new MetricName("group1", "type1", "histogram");
       Histogram histogram = metricRegistery.newHistogram(histogramName, true);
       histogram.update(10);
       histogram.update(14);
       histogram.update(7);
       
       metricMetadata.forMetric(histogram)
       	.withMetricName("histogram")
       	.withSourceName("histogram_source")
       	.withMetricType(SignalFxProtocolBuffers.MetricType.GAUGE)
       	.withDimension("key", "value");
       
       reporter.report();
       
       assertEquals(2, dbank.addDataPoints.size());
	
}
 
Example #18
Source File: MetricsHelper.java    From incubator-pinot with Apache License 2.0 3 votes vote down vote up
/**
 *
 * Return an existing histogram if
 *  (a) A histogram already exist with the same metric name.
 * Otherwise, creates a new meter and registers
 *
 * @param registry MetricsRegistry
 * @param name metric name
 * @param biased (true if uniform distribution, otherwise exponential weighted)
 * @return histogram
 */
public static Histogram newHistogram(MetricsRegistry registry, MetricName name, boolean biased) {
  if (registry != null) {
    return registry.newHistogram(name, biased);
  } else {
    return Metrics.newHistogram(name, biased);
  }
}
 
Example #19
Source File: ValidatingMetricProcessor.java    From kafka-graphite with Apache License 2.0 2 votes vote down vote up
@Override
public void processHistogram(MetricName name, Histogram histogram, Object context) throws Exception {

}
 
Example #20
Source File: CustomScheduledReporter.java    From signalfx-java with Apache License 2.0 2 votes vote down vote up
/**
 * get all Histogram metrics
 * @param filter
 * @return
 */

private SortedMap<MetricName, Histogram> getHistograms(MetricPredicate filter) {
	return getMetrics(Histogram.class, filter);
}
 
Example #21
Source File: CustomScheduledReporter.java    From signalfx-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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<MetricName, Gauge> gauges,
                            SortedMap<MetricName, Counter> counters,
                            SortedMap<MetricName, Histogram> histograms,
                            SortedMap<MetricName, Meter> meters,
                            SortedMap<MetricName, Timer> timers);