All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pinterest.doctorkafka.stats.MetricsRetriever Maven / Gradle / Ivy

There is a newer version: 0.3.0-rc.2
Show newest version
package com.pinterest.doctorkafka.stats;

import com.pinterest.doctorkafka.ReplicaStat;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.kafka.common.TopicPartition;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.management.MBeanServerConnection;


public class MetricsRetriever {

  private static final int METRIC_COLLECTOR_THREADPOOL_SIZE = 40;

  private static ExecutorService metricsThreadPool = Executors.newFixedThreadPool(
      METRIC_COLLECTOR_THREADPOOL_SIZE,
      new ThreadFactoryBuilder().setNameFormat("MetricsRetriever: %d").build());

  public static Future getMetricValue(MBeanServerConnection mbs,
                                                        String metricName, String attributeName) {
    Callable task =
        new KafkaMetricRetrievingTask(mbs, metricName, attributeName);
    Future metricFuture = metricsThreadPool.submit(task);
    return metricFuture;
  }

  public static Future getTopicPartitionReplicaStats(MBeanServerConnection mbs,
                                                                  TopicPartition topicPartition,
                                                                  boolean isLeader,
                                                                  boolean inReassign) {
    Callable task = new ReplicaStatsTask(mbs, topicPartition, isLeader, inReassign);
    Future statsFuture = metricsThreadPool.submit(task);
    return statsFuture;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy