org.apache.kafka.common.Metric.metricValue()方法的使用及代码示例

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

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

Metric.metricValue介绍

[英]The value of the metric, which may be measurable or a non-measurable gauge
[中]度量值,可以是可测量的,也可以是不可测量的

代码示例

代码示例来源:origin: apache/kafka

@Override
  public void run() {
    // Poll as fast as possible to reproduce ConcurrentModificationException
    while (!doStop.get()) {
      try {
        int size = ((Double) metric.metricValue()).intValue();
        observedSize.set(size);
      } catch (Exception e) {
        exceptionHolder.set(e);
        return;
      }
    }
  }
};

代码示例来源:origin: apache/kafka

frequencies.record(config, i % 4 + 1, time.milliseconds());
assertEquals(0.25, (Double) metric1.metricValue(), DELTA);
assertEquals(0.25, (Double) metric2.metricValue(), DELTA);
assertEquals(0.25, (Double) metric3.metricValue(), DELTA);
assertEquals(0.25, (Double) metric4.metricValue(), DELTA);
  frequencies.record(config, i % 2 + 1, time.milliseconds());
assertEquals(0.50, (Double) metric1.metricValue(), DELTA);
assertEquals(0.50, (Double) metric2.metricValue(), DELTA);
assertEquals(0.00, (Double) metric3.metricValue(), DELTA);
assertEquals(0.00, (Double) metric4.metricValue(), DELTA);
  frequencies.record(config, 4.0, time.milliseconds());
assertEquals(0.25, (Double) metric1.metricValue(), DELTA);
assertEquals(0.25, (Double) metric2.metricValue(), DELTA);
assertEquals(0.00, (Double) metric3.metricValue(), DELTA);
assertEquals(0.50, (Double) metric4.metricValue(), DELTA);

代码示例来源:origin: apache/kafka

sensor.record(i);
assertEquals(25, (Double) p25.metricValue(), 1.0);
assertEquals(50, (Double) p50.metricValue(), 1.0);
assertEquals(75, (Double) p75.metricValue(), 1.0);
assertEquals(0.0, (Double) p25.metricValue(), 1.0);
assertEquals(0.0, (Double) p50.metricValue(), 1.0);
assertEquals(0.0, (Double) p75.metricValue(), 1.0);
  sensor.record(i);
assertEquals(25, (Double) p25.metricValue(), 1.0);
assertEquals(50, (Double) p50.metricValue(), 1.0);
assertEquals(75, (Double) p75.metricValue(), 1.0);

代码示例来源:origin: sixt/ja-micro

private synchronized void checkAssignments() {
  logger.debug("Checking partition assignments");
  try {
    KafkaConsumer<String, String> consumer = consumers.iterator().next();
    Map<MetricName, ? extends Metric> metrics = consumer.metrics();
    for (MetricName name : metrics.keySet()) {
      if ("assigned-partitions".equals(name.name())) {
        Metric metric = metrics.get(name);
        Map<String, String> tags = name.tags();
        String clientId = tags.get("client-id");
        int partitionCount = ((Double)metric.metricValue()).intValue();
        processDataPoint(clientId, partitionCount, Instant.now());
      }
    }
  } catch (NoSuchElementException ex) {
  }
}

代码示例来源:origin: com.jkoolcloud/tnt4j

@Override
public KeyValueStats getStats(Map<String, Object> stats) {
  super.getStats(stats);
  if (isOpen()) {
    Map<MetricName, ? extends Metric> kMetrics = producer.metrics();
    Set<MetricName> keys = kMetrics.keySet();
    for (MetricName kMetric : keys) {
      stats.put(Utils.qualify(this, kMetric.group() + "/" + kMetric.name()),
          kMetrics.get(kMetric).metricValue());
    }
  }
  return this;
}

相关文章