io.amient.kafka.metrics.ConsumerGroupReporter Maven / Gradle / Ivy
package io.amient.kafka.metrics;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.*;
import com.yammer.metrics.reporting.AbstractPollingReporter;
import kafka.coordinator.group.GroupOverview;
import kafka.utils.VerifiableProperties;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.common.TopicPartition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.collection.JavaConverters;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
public class ConsumerGroupReporter implements kafka.metrics.KafkaMetricsReporter,
io.amient.kafka.metrics.ConsumerGroupReporterMBean {
private static final Logger log = LoggerFactory.getLogger(ConsumerGroupReporter.class);
private static final String CONFIG_POLLING_INTERVAL = "kafka.metrics.polling.interval";
private boolean initialized;
private Properties props;
private long pollingIntervalSeconds;
private int brokerId;
private boolean running;
private Reporter underlying;
@Override
public String getMBeanName() {
return "kafka:type=io.amient.kafka.metrics.ConsumerGroupReporter";
}
@Override
public void init(VerifiableProperties props) {
if (!initialized) {
this.props = new Properties();
if (props.containsKey(CONFIG_POLLING_INTERVAL)) {
this.pollingIntervalSeconds = props.getInt(CONFIG_POLLING_INTERVAL);
} else {
this.pollingIntervalSeconds = 10;
}
this.brokerId = Integer.parseInt(props.getProperty("broker.id"));
log.info("Building ConsumerGroupReporter: polling.interval=" + pollingIntervalSeconds);
Enumeration