com.yammer.metrics.core.Counter Java Examples

The following examples show how to use com.yammer.metrics.core.Counter. 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: HBaseIndexerMapper.java    From hbase-indexer with Apache License 2.0 6 votes vote down vote up
private void copyIndexingMetricsToCounters(Context context) {
    final String COUNTER_GROUP = "HBase Indexer Metrics";
    SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics = Metrics.defaultRegistry().groupedMetrics(
            new IndexerMetricsUtil.IndexerMetricPredicate());
    for (Entry<String, SortedMap<MetricName, Metric>> metricsGroupEntry : groupedMetrics.entrySet()) {
        SortedMap<MetricName, Metric> metricsGroupMap = metricsGroupEntry.getValue();
        for (Entry<MetricName, Metric> metricEntry : metricsGroupMap.entrySet()) {
            MetricName metricName = metricEntry.getKey();
            Metric metric = metricEntry.getValue();
            String counterName = metricName.getType() + ": " + metricName.getName();
            if (metric instanceof Counter) {
                Counter counter = (Counter) metric;
                context.getCounter(COUNTER_GROUP, counterName).increment(counter.count());
            } else if (metric instanceof Meter) {
                Meter meter = (Meter) metric;
                context.getCounter(COUNTER_GROUP, counterName).increment(meter.count());
            } else if (metric instanceof Timer) {
                Timer timer = (Timer) metric;
                context.getCounter(COUNTER_GROUP, counterName).increment((long) timer.sum());
            }
        }
    }
}
 
Example #2
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 #3
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 #4
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 #5
Source File: AggregatedCounter.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Update counter from underlying counters.
 */
public void refresh() {
  long count = 0;
  for (Metric m : _counters) {
    if (m instanceof Counter) {
      count += ((Counter) m).count();
    } else if (m instanceof AggregatedCounter) {
      count += ((AggregatedCounter) m).count();
    }
  }
  _count = count;
}
 
Example #6
Source File: YammerExample.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
private static Counter getCounter(MetricsRegistry metricsRegistry,
                                  MetricMetadata metricMetadata) {
    Counter counter = metricsRegistry.newCounter(YammerExample.class, "yammer.test.counter");
    metricMetadata.forMetric(counter)
            .withSourceName("signalFx")
            .withDimension(LIBRARY_VERSION, YAMMER);
    return counter;
}
 
Example #7
Source File: JSONReporter.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Override
public void processCounter(MetricName name, Counter counter, Context context) throws Exception {
  MetricInfo info = context.getMetricInfo(name);
  long time = context.getTime();
  info.addNumber("timestamp", time);
  info.addNumber("value", counter.count());
}
 
Example #8
Source File: StatsDReporterTest.java    From kafka-statsd-metrics2 with Apache License 2.0 5 votes vote down vote up
static Counter createCounter(long count) throws Exception {
  final Counter mock = mock(Counter.class);
  when(mock.count()).thenReturn(count);
  return configureMatcher(mock, doAnswer(new MetricsProcessorAction() {
    @Override
    void delegateToProcessor(MetricProcessor<Object> processor, MetricName name, Object context) throws Exception {
      processor.processCounter(name, mock, context);
    }
  }));
}
 
Example #9
Source File: StatsDReporterTest.java    From kafka-statsd-metrics2 with Apache License 2.0 5 votes vote down vote up
@Test
public final void counter() throws Exception {
  final long count = new Random().nextInt(Integer.MAX_VALUE);
  addMetricAndRunReporter(
      new Callable<Counter>() {
        @Override
        public Counter call() throws Exception {
          return createCounter(count);
        }
      });
  verifyCounter(count);
}
 
Example #10
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 #11
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 #12
Source File: KafkaTimelineMetricsReporter.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public void processCounter(MetricName name, Counter counter, Context context) throws Exception {
  final long currentTimeMillis = System.currentTimeMillis();
  final String sanitizedName = sanitizeName(name);

  final String metricCountName = cacheSanitizedTimelineMetric(currentTimeMillis, sanitizedName,
      COUNT_SUFIX, counter.count());

  populateMetricsList(context, MetricType.COUNTER, metricCountName);
}
 
Example #13
Source File: HintedHandoffMetrics.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public Counter load(InetAddress address)
{
    return Metrics.newCounter(factory.createMetricName("Hints_created-" + address.getHostAddress().replace(':', '.')));
}
 
Example #14
Source File: MemoryReporter.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
@Override
public void processCounter(MetricName name, Counter counter,
    ConcurrentMap<String, org.apache.blur.thrift.generated.Metric> context) throws Exception {
  org.apache.blur.thrift.generated.Metric metric = getMetric(name, context);
  metric.putToLongMap("value", counter.count());
}
 
Example #15
Source File: CustomReporter.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public void processCounter(final MetricName name, final Counter counter,
        final PrintStream stream) {
    stream.printf(locale, "    count = %,d\n", counter.count());
}
 
Example #16
Source File: CustomReporter.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
public void processCounter(final MetricName name, final Counter counter,
        final PrintStream stream) {
    stream.printf(locale, "    count = %,d\n", counter.count());
}
 
Example #17
Source File: YammerMetricProcessor.java    From cruise-control with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void processCounter(MetricName metricName, Counter counter, Context context) {
  if (MetricsUtils.isInterested(metricName)) {
    LOG.warn("Not processing metric {} of type Counter.", metricName);
  }
}
 
Example #18
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#newCounter}
 */
public Counter createCounter(final String component, final String methodName) {
  return metricsRegistry.newCounter(getMetricName(component, methodName));
}
 
Example #19
Source File: YammerFacadeMetric.java    From storm-metrics-reporter with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void processCounter(final MetricName name, final Counter counter, final Map context) throws Exception {
  context.put(toString(name), counter.count());
}
 
Example #20
Source File: YammerExample.java    From signalfx-java with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        System.out.println("Running example...");

        Properties prop = new Properties();
        prop.load(new FileInputStream("auth.properties"));
        final String auth_token = prop.getProperty("auth");
        final String hostUrlStr = prop.getProperty("host");
        final URL hostUrl = new URL(hostUrlStr);
        System.out.println("Auth=" + auth_token + " .. host=" + hostUrl);
        SignalFxReceiverEndpoint endpoint = new SignalFxEndpoint(hostUrl.getProtocol(),
                hostUrl.getHost(), hostUrl.getPort());

        MetricsRegistry metricsRegistry = new MetricsRegistry();
        SignalFxReporter reporter = new SignalFxReporter.Builder(metricsRegistry,
                new StaticAuthToken(auth_token),
                hostUrlStr).setEndpoint(endpoint)
                .setOnSendErrorHandlerCollection(
                        Collections.<OnSendErrorHandler>singleton(new OnSendErrorHandler() {
                            public void handleError(MetricError error) {
                                System.out.println("" + error.getMessage());
                            }
                        }))
                .setDetailsToAdd(ImmutableSet.of(SignalFxReporter.MetricDetails.COUNT,
                        SignalFxReporter.MetricDetails.MIN,
                        SignalFxReporter.MetricDetails.MAX))
                .build();

        final MetricMetadata metricMetadata = reporter.getMetricMetadata();

        Counter counter = getCounter(metricsRegistry, metricMetadata);

        Metric cumulativeCounter = getCumulativeCounter(metricsRegistry, metricMetadata);

        Gauge gauge1 = getGauge(metricsRegistry, metricMetadata);

        Timer timer = getTimer(metricsRegistry, metricMetadata);

        // main body generating data and sending it in a loop
        while (true) {
            final TimerContext context = timer.time();
            try {
                System.out.println("Sending data...");
                Thread.sleep(500);
                counter.inc();
            } finally {
                context.stop();
            }
            reporter.report(); // Report all metrics
        }

    }
 
Example #21
Source File: MetricsHelper.java    From incubator-pinot with Apache License 2.0 3 votes vote down vote up
/**
 *
 * Return an existing counter if
 *  (a) A counter already exist with the same metric name.
 * Otherwise, creates a new meter and registers
 *
 * @param registry MetricsRegistry
 * @param name metric name
 * @return Counter
 */
public static Counter newCounter(MetricsRegistry registry, MetricName name) {
  if (registry != null) {
    return registry.newCounter(name);
  } else {
    return Metrics.newCounter(name);
  }
}
 
Example #22
Source File: ValidatingMetricProcessor.java    From kafka-graphite with Apache License 2.0 2 votes vote down vote up
@Override
public void processCounter(MetricName name, Counter counter, Object context) throws Exception {

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

private SortedMap<MetricName, Counter> getCounters(MetricPredicate filter) {
	return getMetrics(Counter.class, filter);
}
 
Example #24
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);