@Test public void testWithOptimer() { setupClient(); final MetricsRegistry registry = new MetricsRegistry(); final MetricsOpTimer opTimer = new MetricsOpTimer(registry, "TEST_CLUSTER", TimeUnit.NANOSECONDS, TimeUnit.SECONDS); connectionManager.setTimer(opTimer); connectionManager.operateWithFailover(new NullOp()); final SortedMap<String, SortedMap<MetricName, Metric>> metrics = registry.groupedMetrics(); assertNotNull("Hector metric should exist in metrics registry", metrics); assertFalse("Hector metrics should exist in metrics register", metrics.isEmpty()); final Entry<String, SortedMap<MetricName, Metric>> entry = metrics.entrySet().iterator().next(); assertEquals("Incorrect metrics key should be [cluster_name].hector", "TEST_CLUSTER.hector", entry.getKey()); final Entry<MetricName, Metric> metric = entry.getValue().entrySet().iterator().next(); assertEquals("Incorrect metrics name should be META_READ", "META_READ", metric.getKey() .getName()); assertEquals("Incorrect metrics type should be timer", Timer.class, metric.getValue() .getClass()); }
/** * Returns a grouped and sorted map of all registered metrics. * * @return all registered metrics, grouped by name and sorted */ public SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics() { return groupedMetrics(MetricPredicate.ALL); }
private void printRegularMetrics() { for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry().groupedMetrics().entrySet()) { for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { final Metric metric = subEntry.getValue(); if (metric != null) { try { metric.processWith(this, subEntry.getKey(), null); } catch (Exception suppressed) { log.error("Error printing regular metrics:", suppressed); } } } } }
protected void printRegularMetrics(long epoch) { for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry().groupedMetrics(predicate).entrySet()) { for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { final Metric metric = subEntry.getValue(); if (metric != null) { try { metric.processWith(this, subEntry.getKey(), epoch); } catch (Exception ignored) { LOG.error("Error printing regular metrics:", ignored); } } } } }
protected void printRegularMetrics(final Long epoch) { for (Entry<String,SortedMap<MetricName,Metric>> entry : getMetricsRegistry().groupedMetrics( predicate).entrySet()) { for (Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { final Metric metric = subEntry.getValue(); if (metric != null) { try { metric.processWith(this, subEntry.getKey(), epoch); } catch (Exception ignored) { LOG.error("Error printing regular metrics:", ignored); } } } } }
protected void pushRegularMetrics(long epoch) { for (Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry() .groupedMetrics(predicate).entrySet()) { for (Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { final Metric metric = subEntry.getValue(); if (metric != null) { try { metric.processWith(this, subEntry.getKey(), epoch); } catch (Exception e) { LOG.error("Error pushing metric", e); } } } } }
@Override public void run() { for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry().groupedMetrics( MetricPredicate.ALL).entrySet()) { try { for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { out.print(" " + subEntry.getKey().getName()); out.println(':'); subEntry.getValue().processWith(this, subEntry.getKey(), out); } } catch (Exception e) { e.printStackTrace(out); } } }
public void writeRegularMetrics(JsonGenerator json, String classPrefix, boolean showFullSamples) throws IOException { for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : registry.groupedMetrics().entrySet()) { if (classPrefix == null || entry.getKey().startsWith(classPrefix)) { json.writeFieldName(entry.getKey()); json.writeStartObject(); { for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { json.writeFieldName(subEntry.getKey().getName()); try { subEntry.getValue() .processWith(this, subEntry.getKey(), new Context(json, showFullSamples)); } catch (Exception e) { LOGGER.warn("Error writing out {}", subEntry.getKey(), e); } } } json.writeEndObject(); } } }
@Override public void run() { for (Map.Entry<String, SortedMap<MetricName, Metric>> group : getMetricsRegistry().groupedMetrics().entrySet()) { for (Map.Entry<MetricName, Metric> entry : group.getValue().entrySet()) { if (entry.getValue() == null || entry.getKey() == null) { logger.severe("Application Error! Pulled null value from metrics registry."); } MetricName metricName = entry.getKey(); Metric metric = entry.getValue(); try { TimeSeries timeSeries = TimeSeriesUtils.fromMetricName(metricName); metric.processWith(flushProcessor, metricName, new FlushProcessorContext(timeSeries, prefix, pointHandler)); } catch (Exception e) { logger.log(Level.SEVERE, "Uncaught exception in MetricsReporter", e); } } } }
@Override public void run() { for (Map.Entry<String, SortedMap<MetricName, Metric>> group : getMetricsRegistry().groupedMetrics().entrySet()) { for (Map.Entry<MetricName, Metric> entry : group.getValue().entrySet()) { if (entry.getValue() == null || entry.getKey() == null) { logger.severe("Application Error! Pulled null value from metrics registry."); } MetricName metricName = entry.getKey(); Metric metric = entry.getValue(); try { TimeSeries timeSeries = TimeSeriesUtils.fromMetricName(metricName); metric.processWith(flushProcessor, metricName, new FlushProcessorContext(timeSeries, prefix, pointHandler)); } catch (Exception e) { logger.log(Level.SEVERE, "Uncaught exception in MetricsReporter", e); } } } }
for (Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry().groupedMetrics( predicate).entrySet()) { out.print(entry.getKey());
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); } } }
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); } } }
@Nullable Map<String, String> pointTags, @Nullable MetricTranslator metricTranslator) throws IOException { for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : registry.groupedMetrics().entrySet()) { for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { MetricName key = subEntry.getKey();
@Nullable Map<String, String> pointTags, @Nullable MetricTranslator metricTranslator) throws IOException { for (Map.Entry<String, SortedMap<MetricName, Metric>> entry : registry.groupedMetrics().entrySet()) { for (Map.Entry<MetricName, Metric> subEntry : entry.getValue().entrySet()) { MetricName key = subEntry.getKey();
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()); } } } }
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()); } } } }