org.apache.kafka.clients.producer.Producer.metrics()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(4.0k)|赞(0)|评价(0)|浏览(143)

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

Producer.metrics介绍

[英]See KafkaProducer#metrics()
[中]参见《卡夫卡制作人#metrics》()

代码示例

代码示例来源:origin: openzipkin/brave

@Override public Map<MetricName, ? extends Metric> metrics() {
 return delegate.metrics();
}

代码示例来源:origin: spring-projects/spring-kafka

@Override
public Map<MetricName, ? extends Metric> metrics() {
  return this.delegate.metrics();
}

代码示例来源:origin: spring-projects/spring-kafka

@Override
public Map<MetricName, ? extends Metric> metrics() {
  Producer<K, V> producer = getTheProducer();
  try {
    return producer.metrics();
  }
  finally {
    closeProducer(producer, inTransaction());
  }
}

代码示例来源:origin: org.axonframework.extensions.kafka/axon-kafka

@Override
public Map<MetricName, ? extends Metric> metrics() {
  return this.delegate.metrics();
}

代码示例来源:origin: com.github.combinedmq/combinedmq

@Override
public Map<MetricName, ? extends Metric> metrics() {
  return producer.metrics();
}

代码示例来源:origin: io.opentracing.contrib/opentracing-kafka-client

@Override
public Map<MetricName, ? extends Metric> metrics() {
 return producer.metrics();
}

代码示例来源:origin: org.axonframework/axon-kafka

@Override
public Map<MetricName, ? extends Metric> metrics() {
  return this.delegate.metrics();
}

代码示例来源:origin: linkedin/li-apache-kafka-clients

@Override
public Map<MetricName, ? extends Metric> metrics() {
 return _producer.metrics();
}

代码示例来源:origin: opentracing-contrib/java-kafka-client

@Override
public Map<MetricName, ? extends Metric> metrics() {
 return producer.metrics();
}

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-kafka-clients

@Override public Map<MetricName, ? extends Metric> metrics() {
 return delegate.metrics();
}

代码示例来源:origin: allegro/hermes

private void registerGauge(Producer<byte[], byte[]> producer, HermesMetrics metrics, String gauge,
              Predicate<Map.Entry<MetricName, ? extends Metric>> predicate) {
  metrics.registerGauge(gauge, () -> {
    Optional<? extends Map.Entry<MetricName, ? extends Metric>> first =
        producer.metrics().entrySet().stream().filter(predicate).findFirst();
    double value = first.isPresent() ? first.get().getValue().value() : 0.0;
    return value < 0? 0.0 : value;
  });
}

代码示例来源:origin: org.apache.kafka/kafka-streams

public Map<MetricName, Metric> producerMetrics() {
  final LinkedHashMap<MetricName, Metric> result = new LinkedHashMap<>();
  if (producer != null) {
    final Map<MetricName, ? extends Metric> producerMetrics = producer.metrics();
    if (producerMetrics != null) {
      result.putAll(producerMetrics);
    }
  } else {
    // When EOS is turned on, each task will have its own producer client
    // and the producer object passed in here will be null. We would then iterate through
    // all the active tasks and add their metrics to the output metrics map.
    for (final StreamTask task: taskManager.activeTasks().values()) {
      final Map<MetricName, ? extends Metric> taskProducerMetrics = task.getProducer().metrics();
      result.putAll(taskProducerMetrics);
    }
  }
  return result;
}

代码示例来源:origin: com.hotels.road/road-onramp-kafka-impl

producer.metrics().forEach((metricName, metric) -> {
 String name = "onramp_kafka_producer_" + metricName.group() + "_" + metricName.name();
 registry.gauge(name, metric, m -> m.value());

代码示例来源: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;
}

代码示例来源:origin: reactor/reactor-kafka

/**
 * Tests invocation of methods on KafkaProducer using {@link KafkaSender#doOnProducer(java.util.function.Function)}
 */
@Test
public void producerMethods() {
  testProducerMethod(p -> assertEquals(0, p.metrics().size()));
  testProducerMethod(p -> assertEquals(2, p.partitionsFor(topic).size()));
  testProducerMethod(p -> p.flush());
}

相关文章