com.yammer.metrics.core.MetricsRegistry.groupedMetrics()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中com.yammer.metrics.core.MetricsRegistry.groupedMetrics()方法的一些代码示例,展示了MetricsRegistry.groupedMetrics()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MetricsRegistry.groupedMetrics()方法的具体详情如下:
包路径:com.yammer.metrics.core.MetricsRegistry
类名称:MetricsRegistry
方法名:groupedMetrics

MetricsRegistry.groupedMetrics介绍

[英]Returns a grouped and sorted map of all registered metrics.
[中]返回所有已注册度量的分组和排序映射。

代码示例

代码示例来源:origin: hector-client/hector

@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());
}

代码示例来源:origin: com.yammer.metrics/metrics-core

/**
 * 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);
}

代码示例来源:origin: addthis/hydra

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);
        }
      }
    }
  }
}

代码示例来源:origin: com.readytalk/metrics2-statsd

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);
    }
   }
  }
 }
}

代码示例来源:origin: com.yammer.metrics/metrics-graphite

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);
        }
      }
    }
  }
}

代码示例来源:origin: vistarmedia/metrics-datadog

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);
    }
   }
  }
 }
}

代码示例来源:origin: harbby/presto-connectors

@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);
  }
 }
}

代码示例来源:origin: com.yammer.metrics/metrics-servlet

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();
    }
  }
}

代码示例来源:origin: com.wavefront/proxy

@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);
   }
  }
 }
}

代码示例来源:origin: wavefrontHQ/java

@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);
   }
  }
 }
}

代码示例来源:origin: com.yammer.metrics/metrics-core

for (Entry<String, SortedMap<MetricName, Metric>> entry : getMetricsRegistry().groupedMetrics(
    predicate).entrySet()) {
  out.print(entry.getKey());

代码示例来源:origin: NGDATA/hbase-indexer

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);
    }
  }
}

代码示例来源:origin: com.ngdata/hbase-indexer-common

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);
    }
  }
}

代码示例来源:origin: wavefrontHQ/java

@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();

代码示例来源:origin: com.wavefront/java-lib

@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();

代码示例来源:origin: com.ngdata/hbase-indexer-mr

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());
      }
    }
  }
}

代码示例来源:origin: NGDATA/hbase-indexer

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());
      }
    }
  }
}

相关文章