com.yammer.metrics.core.Metric Java Examples
The following examples show how to use
com.yammer.metrics.core.Metric.
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: YammerFacadeMetric.java From storm-metrics-reporter with Apache License 2.0 | 6 votes |
/** * Returns a Map representing all the Yammer metrics managed by this facade metric. * * @return A Map which is in fact a snapshot of all the Yammer metrics managed by this facade metric. */ @Override public Object getValueAndReset() { final Map metricsValues = new HashMap(); for (final Map.Entry<MetricName, Metric> entry : metricsRegistry.allMetrics().entrySet()) { try { entry.getValue().processWith(METRIC_SERIALIZER, entry.getKey(), metricsValues); } catch (final Exception e) { // log? } } return metricsValues; }
Example #2
Source File: CustomScheduledReporter.java From signalfx-java with Apache License 2.0 | 6 votes |
/** * get Metrics by class and predicate * * @param klass * @param filter * @return */ @SuppressWarnings("unchecked") private <T extends Metric> SortedMap<MetricName, T> getMetrics(Class<T> klass, MetricPredicate filter) { Map<MetricName, Metric> allMetrics = registry.allMetrics(); final TreeMap<MetricName, T> timers = new TreeMap<MetricName, T>(); for (Map.Entry<MetricName, Metric> entry : allMetrics.entrySet()) { if (klass.isInstance(entry.getValue()) && filter.matches(entry.getKey(), entry.getValue())) { timers.put(entry.getKey(), (T) entry.getValue()); } } return Collections.unmodifiableSortedMap(timers); }
Example #3
Source File: MemoryReporter.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@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 #4
Source File: MemoryReporter.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@Override public void processTimer(MetricName name, Timer timer, ConcurrentMap<String, org.apache.blur.thrift.generated.Metric> context) throws Exception { org.apache.blur.thrift.generated.Metric metric = getMetric(name, context); addMeter(metric, timer, context); metric.putToStrMap("unit", timer.durationUnit().toString()); metric.putToDoubleMap("min", timer.min()); metric.putToDoubleMap("max", timer.max()); metric.putToDoubleMap("mean", timer.mean()); metric.putToDoubleMap("stdDev", timer.stdDev()); Snapshot snapshot = timer.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 #5
Source File: FilterMetricPredicateTest.java From kafka-graphite with Apache License 2.0 | 6 votes |
@Test public void keepGaugesIfTheyThrowRuntimeExceptions() throws Exception { MetricPredicate predicate = new FilterMetricPredicate(); MetricName metricName = new MetricName("test", "test", "delete", "scope", "mBeanName"); Metric gauge = Metrics.newGauge(metricName, new Gauge<Long>() { @Override public Long value() { throw new RuntimeException("catch me if you can"); } }); assertTrue(predicate.matches(metricName, gauge)); assertTrue("The gauge should be there", Metrics.defaultRegistry().allMetrics().containsKey(metricName)); assertEquals(Metrics.defaultRegistry().allMetrics().get(metricName), gauge); }
Example #6
Source File: FilterMetricPredicate.java From kafka-graphite with Apache License 2.0 | 6 votes |
@Override public boolean matches(MetricName name, Metric metric) { String metricName = sanitizeName(name); boolean isVersionMetric = APPVERSION_PATTERN.matcher(metricName).matches(); if (isVersionMetric || cleanInvalidGauge(name, metric, metricName)) { return false; } if (pattern != null) { return !pattern.matcher(metricName).matches(); } return true; }
Example #7
Source File: YammerExample.java From signalfx-java with Apache License 2.0 | 6 votes |
private static Metric getCumulativeCounter(MetricsRegistry metricsRegistry, MetricMetadata metricMetadata) { MetricName counterCallbackName = new MetricName(YammerExample.class, "yammer.test.cumulativeCounter"); Metric cumulativeCounter = SfUtil.cumulativeCounter( metricsRegistry, counterCallbackName, metricMetadata, new Gauge<Long>() { private long i = 0; @Override public Long value() { return i++; } }); metricMetadata.forMetric(cumulativeCounter) .withSourceName(SIGNAL_FX) .withDimension(LIBRARY_VERSION, YAMMER); return cumulativeCounter; }
Example #8
Source File: ScheduledReporterTest.java From ambari-metrics with Apache License 2.0 | 6 votes |
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 #9
Source File: HBaseIndexerMapper.java From hbase-indexer with Apache License 2.0 | 6 votes |
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 #10
Source File: CustomReporter.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public void run() { try { final DateFormat format = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.MEDIUM, locale); format.setTimeZone(timeZone); final String dateTime = format.format(new Date(clock.time())); out.print(dateTime); out.print(' '); for (int i = 0; i < CONSOLE_WIDTH - dateTime.length() - 1; i++) { out.print('='); } out.println(); for (final Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry() .groupedMetrics(predicate).entrySet()) { out.print(entry.getKey()); out.println(':'); for (final Entry<MetricName, Metric> subEntry : entry .getValue().entrySet()) { out.print(" "); out.print(subEntry.getKey().getName()); out.println(':'); subEntry.getValue().processWith(this, subEntry.getKey(), out); out.println(); } out.println(); } out.println(); out.flush(); } catch (final Exception e) { e.printStackTrace(out); } }
Example #11
Source File: MetricMetadataImpl.java From signalfx-java with Apache License 2.0 | 5 votes |
@Override public Map<String, String> getTags(Metric metric) { Metadata existingMetaData = metaDataCollection.get(metric); if (existingMetaData == null) { return Collections.emptyMap(); } else { return Collections.unmodifiableMap(existingMetaData.tags); } }
Example #12
Source File: AggregateMetricSenderSessionWrapper.java From signalfx-java with Apache License 2.0 | 5 votes |
/** * Add metric * @param metric * @param codahaleName * @param defaultMetricType * @param originalValue */ void addMetric(Metric metric, MetricName codahaleName, SignalFxProtocolBuffers.MetricType defaultMetricType, Object originalValue) { addMetric(metric, codahaleName, Optional.<SignalFxReporter.MetricDetails>absent(), defaultMetricType, originalValue); }
Example #13
Source File: MetricMetadataImpl.java From signalfx-java with Apache License 2.0 | 5 votes |
@Override public <M extends Metric> Tagger<M> forMetric(M metric) { Metadata metadata = metaDataCollection.get(metric); if (metadata == null) { synchronized (this) { if (metadata == null) { metadata = new Metadata(); Metadata oldMetaData = metaDataCollection.put(metric, metadata); Preconditions.checkArgument(oldMetaData == null, "Concurrency issue adding metadata"); } } } return new TaggerImpl<M>(metric, metadata); }
Example #14
Source File: MetricMetadataImpl.java From signalfx-java with Apache License 2.0 | 5 votes |
@Override public Optional<SignalFxProtocolBuffers.MetricType> getMetricType(Metric metric) { Metadata existingMetaData = metaDataCollection.get(metric); if (existingMetaData == null || existingMetaData.metricType == null) { return Optional.absent(); } else { return Optional.of(existingMetaData.metricType); } }
Example #15
Source File: AggregateMetricSenderSessionWrapper.java From signalfx-java with Apache License 2.0 | 5 votes |
/** * Add metric * @param metric * @param codahaleName * @param metricDetails * @param defaultMetricType * @param originalValue */ private void addMetric(Metric metric, MetricName codahaleName, SignalFxReporter.MetricDetails metricDetails, SignalFxProtocolBuffers.MetricType defaultMetricType, Object originalValue) { addMetric(metric, codahaleName, Optional.of(metricDetails), defaultMetricType, originalValue); }
Example #16
Source File: MemoryReporter.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private void addMeter(org.apache.blur.thrift.generated.Metric metric, Metered meter, ConcurrentMap<String, org.apache.blur.thrift.generated.Metric> context) { metric.putToStrMap("rateUnit", meter.rateUnit().toString()); metric.putToStrMap("eventType", meter.eventType()); metric.putToLongMap("count", meter.count()); metric.putToDoubleMap("meanRate", meter.meanRate()); metric.putToDoubleMap("oneMinuteRate", meter.oneMinuteRate()); metric.putToDoubleMap("fiveMinuteRate", meter.fiveMinuteRate()); metric.putToDoubleMap("fifteenMinuteRate", meter.fifteenMinuteRate()); }
Example #17
Source File: MemoryReporter.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private org.apache.blur.thrift.generated.Metric getMetric(MetricName name, ConcurrentMap<String, org.apache.blur.thrift.generated.Metric> context) { String nameStr = name.toString(); org.apache.blur.thrift.generated.Metric metric = context.get(nameStr); if (metric == null) { metric = new org.apache.blur.thrift.generated.Metric(); context.put(nameStr, metric); metric.setName(nameStr); } return metric; }
Example #18
Source File: MemoryReporter.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public void run() { try { MetricsRegistry registry = getMetricsRegistry(); Map<MetricName, Metric> allMetrics = registry.allMetrics(); for (Entry<MetricName, Metric> entry : allMetrics.entrySet()) { entry.getValue().processWith(this, entry.getKey(), _metrics); } } catch (Exception e) { LOG.error("Unknown error during metrics processing.", e); } }
Example #19
Source File: AggregatedCounter.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public <T> void processWith(MetricProcessor<T> processor, MetricName name, T context) throws Exception { for (Metric c : _counters) { c.processWith(processor, name, context); } }
Example #20
Source File: AggregatedCounter.java From incubator-pinot with Apache License 2.0 | 5 votes |
/** * 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 #21
Source File: StatsDReporterTest.java From kafka-statsd-metrics2 with Apache License 2.0 | 5 votes |
protected <T extends Metric> void addMetricAndRunReporter(Callable<T> action) throws Exception { // Invoke the callable to trigger (ie, mark()/inc()/etc) and return the metric final T metric = action.call(); try { // Add the metric to the registry, run the reporter and flush the result registry.add(new MetricName(Object.class, "metric"), metric); reporter.run(); } finally { reporter.shutdown(); } }
Example #22
Source File: AggregatedHistogram.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public <T2> void processWith(MetricProcessor<T2> processor, MetricName name, T2 context) throws Exception { for (T h : _histograms) { if (h instanceof Metric) { ((Metric) h).processWith(processor, name, context); } } }
Example #23
Source File: ExcludeMetricPredicate.java From kafka-statsd-metrics2 with Apache License 2.0 | 5 votes |
@Override public boolean matches(MetricName name, Metric metric) { String n = MetricNameFormatter.format(name); boolean excluded = pattern.matcher(n).matches(); if (excluded) { if (logger.isTraceEnabled()) { logger.trace("Metric " + n + " is excluded"); } } return !excluded; }
Example #24
Source File: FilterMetricPredicateTest.java From kafka-graphite with Apache License 2.0 | 5 votes |
@Test public void deleteGaugesIfTheyThrowNoSuchElementException() throws Exception { MetricPredicate predicate = new FilterMetricPredicate(); MetricName metricNameToBeDeleted = new MetricName("test", "test", "delete", "scope", "mBeanName"); Metric gaugeToBeDeleted = Metrics.newGauge(metricNameToBeDeleted, new Gauge<Long>() { @Override public Long value() { throw new NoSuchElementException("catch me if you can - i'm the the same as in KAFKA-1866"); } }); MetricName metricNameToStay = new MetricName("stay", "stay", "stay", "scope", "stay:mBeanName"); Metric gaugeToStay = Metrics.newGauge(metricNameToStay, new Gauge<Long>() { @Override public Long value() { return 42L; } }); assertFalse(predicate.matches(metricNameToBeDeleted, gaugeToBeDeleted)); assertTrue(predicate.matches(metricNameToStay, gaugeToStay)); assertFalse("The gauge should be deleted", Metrics.defaultRegistry().allMetrics().containsKey(metricNameToBeDeleted)); assertTrue("The gauge should be there", Metrics.defaultRegistry().allMetrics().containsKey(metricNameToStay)); assertEquals(Metrics.defaultRegistry().allMetrics().get(metricNameToStay), gaugeToStay); }
Example #25
Source File: FilterMetricPredicateTest.java From kafka-graphite with Apache License 2.0 | 5 votes |
@Before public void setup() { metricMock = mock(Metric.class); // clean all metrics List<MetricName> metricNames = new ArrayList<MetricName>(Metrics.defaultRegistry().allMetrics().keySet()); for (MetricName metricName : metricNames) { Metrics.defaultRegistry().removeMetric(metricName); } }
Example #26
Source File: IndexerMetricsUtil.java From hbase-indexer with Apache License 2.0 | 5 votes |
public static void shutdownMetrics(String indexerName) { SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics = Metrics.defaultRegistry().groupedMetrics( new IndexerMetricPredicate(indexerName)); for (SortedMap<MetricName, Metric> metricMap : groupedMetrics.values()) { for (MetricName metricName : metricMap.keySet()) { Metrics.defaultRegistry().removeMetric(metricName); } } }
Example #27
Source File: CustomReporter.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override public void run() { try { final DateFormat format = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.MEDIUM, locale); format.setTimeZone(timeZone); final String dateTime = format.format(new Date(clock.time())); out.print(dateTime); out.print(' '); for (int i = 0; i < CONSOLE_WIDTH - dateTime.length() - 1; i++) { out.print('='); } out.println(); for (final Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry() .groupedMetrics(predicate).entrySet()) { out.print(entry.getKey()); out.println(':'); for (final Entry<MetricName, Metric> subEntry : entry .getValue().entrySet()) { out.print(" "); out.print(subEntry.getKey().getName()); out.println(':'); subEntry.getValue().processWith(this, subEntry.getKey(), out); out.println(); } out.println(); } out.println(); out.flush(); } catch (final Exception e) { e.printStackTrace(out); } }
Example #28
Source File: CruiseControlMetricsReporter.java From cruise-control with BSD 2-Clause "Simplified" License | 5 votes |
private void reportYammerMetrics(long now) throws Exception { LOG.debug("Reporting yammer metrics."); YammerMetricProcessor.Context context = new YammerMetricProcessor.Context(this, now, _brokerId, _reportingIntervalMs); for (Map.Entry<com.yammer.metrics.core.MetricName, Metric> entry : Metrics.defaultRegistry().allMetrics().entrySet()) { LOG.trace("Processing yammer metric {}, scope = {}", entry.getKey(), entry.getKey().getScope()); entry.getValue().processWith(_yammerMetricProcessor, entry.getKey(), context); } LOG.debug("Finished reporting yammer metrics."); }
Example #29
Source File: IndexerMetricsUtil.java From hbase-indexer with Apache License 2.0 | 5 votes |
@Override public boolean matches(MetricName metricName, Metric metric) { if (indexerName == null) { return METRIC_GROUP.equals(metricName.getGroup()); } else { return METRIC_GROUP.equals(metricName.getGroup()) && indexerName.equals(metricName.getScope()); } }
Example #30
Source File: AggregateMetricSenderSessionWrapper.java From signalfx-java with Apache License 2.0 | 4 votes |
/** * Add sampling * @param baseName * @param sampling */ private void addSampling(MetricName baseName, Sampling sampling) { Metric metric = (Metric)sampling; final Snapshot snapshot = sampling.getSnapshot(); addMetric(metric, baseName, SignalFxReporter.MetricDetails.MEDIAN, SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.getMedian()); addMetric(metric, baseName, SignalFxReporter.MetricDetails.PERCENT_75, SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get75thPercentile()); addMetric(metric, baseName, SignalFxReporter.MetricDetails.PERCENT_95, SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get95thPercentile()); addMetric(metric, baseName, SignalFxReporter.MetricDetails.PERCENT_98, SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get98thPercentile()); addMetric(metric, baseName, SignalFxReporter.MetricDetails.PERCENT_99, SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get99thPercentile()); addMetric(metric, baseName, SignalFxReporter.MetricDetails.PERCENT_999, SignalFxProtocolBuffers.MetricType.GAUGE, snapshot.get999thPercentile()); addMetric(metric, baseName, SignalFxReporter.MetricDetails.MAX, SignalFxProtocolBuffers.MetricType.GAUGE, getMax(snapshot)); addMetric(metric, baseName, SignalFxReporter.MetricDetails.MIN, SignalFxProtocolBuffers.MetricType.GAUGE, getMin(snapshot)); // These are slower to calculate. Only calculate if we need. if (detailsToAdd.contains(SignalFxReporter.MetricDetails.STD_DEV)) { addMetric(metric, baseName, SignalFxReporter.MetricDetails.STD_DEV, SignalFxProtocolBuffers.MetricType.GAUGE, getStdDev(snapshot)); } if (detailsToAdd.contains(SignalFxReporter.MetricDetails.MEAN)) { addMetric(metric, baseName, SignalFxReporter.MetricDetails.MEAN, SignalFxProtocolBuffers.MetricType.GAUGE, getMean(snapshot)); } }