|
@@ -1,6 +1,5 @@
|
|
package com.provectus.kafka.ui.kafka;
|
|
package com.provectus.kafka.ui.kafka;
|
|
|
|
|
|
-import com.provectus.kafka.ui.cluster.config.KafkaJmxProperties;
|
|
|
|
import com.provectus.kafka.ui.cluster.model.*;
|
|
import com.provectus.kafka.ui.cluster.model.*;
|
|
import com.provectus.kafka.ui.cluster.util.ClusterUtil;
|
|
import com.provectus.kafka.ui.cluster.util.ClusterUtil;
|
|
import com.provectus.kafka.ui.cluster.util.JmxClusterUtil;
|
|
import com.provectus.kafka.ui.cluster.util.JmxClusterUtil;
|
|
@@ -13,7 +12,6 @@ import lombok.RequiredArgsConstructor;
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import org.apache.kafka.clients.admin.*;
|
|
import org.apache.kafka.clients.admin.*;
|
|
-import org.apache.kafka.clients.consumer.Consumer;
|
|
|
|
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
|
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
|
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
|
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
|
import org.apache.kafka.common.KafkaFuture;
|
|
import org.apache.kafka.common.KafkaFuture;
|
|
@@ -21,8 +19,6 @@ import org.apache.kafka.common.Node;
|
|
import org.apache.kafka.common.TopicPartition;
|
|
import org.apache.kafka.common.TopicPartition;
|
|
import org.apache.kafka.common.config.ConfigResource;
|
|
import org.apache.kafka.common.config.ConfigResource;
|
|
import org.apache.kafka.common.serialization.BytesDeserializer;
|
|
import org.apache.kafka.common.serialization.BytesDeserializer;
|
|
-import org.apache.kafka.common.serialization.LongDeserializer;
|
|
|
|
-import org.apache.kafka.common.serialization.StringDeserializer;
|
|
|
|
import org.apache.kafka.common.utils.Bytes;
|
|
import org.apache.kafka.common.utils.Bytes;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -30,8 +26,7 @@ import reactor.core.publisher.Mono;
|
|
import reactor.util.function.Tuple2;
|
|
import reactor.util.function.Tuple2;
|
|
import reactor.util.function.Tuples;
|
|
import reactor.util.function.Tuples;
|
|
|
|
|
|
-import javax.management.MBeanServer;
|
|
|
|
-import java.lang.management.ManagementFactory;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -50,7 +45,7 @@ public class KafkaService {
|
|
private final ZookeeperService zookeeperService;
|
|
private final ZookeeperService zookeeperService;
|
|
private final Map<String, ExtendedAdminClient> adminClientCache = new ConcurrentHashMap<>();
|
|
private final Map<String, ExtendedAdminClient> adminClientCache = new ConcurrentHashMap<>();
|
|
private final Map<AdminClient, Map<TopicPartition, Integer>> leadersCache = new ConcurrentHashMap<>();
|
|
private final Map<AdminClient, Map<TopicPartition, Integer>> leadersCache = new ConcurrentHashMap<>();
|
|
- private final KafkaJmxProperties kafkaJmxDto;
|
|
|
|
|
|
+ private final JmxClusterUtil jmxClusterUtil;
|
|
|
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
public Mono<KafkaCluster> getUpdatedCluster(KafkaCluster cluster) {
|
|
public Mono<KafkaCluster> getUpdatedCluster(KafkaCluster cluster) {
|
|
@@ -72,18 +67,6 @@ public class KafkaService {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- public static Consumer<Long, String> createConsumer() {
|
|
|
|
- Properties props = new Properties();
|
|
|
|
- props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:29091");
|
|
|
|
- props.put(ConsumerConfig.GROUP_ID_CONFIG, "test");
|
|
|
|
- props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, LongDeserializer.class.getName());
|
|
|
|
- props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
|
|
|
|
- props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
|
|
|
|
- Consumer<Long, String> consumer = new KafkaConsumer<>(props);
|
|
|
|
- consumer.subscribe(Collections.singletonList("users"));
|
|
|
|
- return consumer;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private KafkaCluster buildFromData(KafkaCluster currentCluster, InternalSegmentSizeDto segmentSizeDto) {
|
|
private KafkaCluster buildFromData(KafkaCluster currentCluster, InternalSegmentSizeDto segmentSizeDto) {
|
|
|
|
|
|
var topics = segmentSizeDto.getInternalTopicWithSegmentSize();
|
|
var topics = segmentSizeDto.getInternalTopicWithSegmentSize();
|
|
@@ -181,17 +164,17 @@ public class KafkaService {
|
|
.flatMap(brokers ->
|
|
.flatMap(brokers ->
|
|
ClusterUtil.toMono(client.describeCluster().controller()).map(
|
|
ClusterUtil.toMono(client.describeCluster().controller()).map(
|
|
c -> {
|
|
c -> {
|
|
|
|
+ jmxClusterUtil.fillJmxPool(c, cluster);
|
|
InternalClusterMetrics.InternalClusterMetricsBuilder metricsBuilder = InternalClusterMetrics.builder();
|
|
InternalClusterMetrics.InternalClusterMetricsBuilder metricsBuilder = InternalClusterMetrics.builder();
|
|
metricsBuilder.brokerCount(brokers.size()).activeControllers(c != null ? 1 : 0);
|
|
metricsBuilder.brokerCount(brokers.size()).activeControllers(c != null ? 1 : 0);
|
|
- Map<String, String> bytesInPerSec;
|
|
|
|
- Map<String, String> bytesOutPerSec;
|
|
|
|
- bytesInPerSec = JmxClusterUtil.getJmxTrafficMetrics(cluster.getJmxPort(), cluster.getJmxHost(), JmxClusterUtil.BYTES_IN_PER_SEC);
|
|
|
|
- bytesOutPerSec = JmxClusterUtil.getJmxTrafficMetrics(cluster.getJmxPort(), cluster.getJmxHost(), JmxClusterUtil.BYTES_OUT_PER_SEC);
|
|
|
|
|
|
+ Map<String, BigDecimal> bytesInPerSec;
|
|
|
|
+ Map<String, BigDecimal> bytesOutPerSec;
|
|
|
|
+ bytesInPerSec = jmxClusterUtil.getJmxTrafficMetrics(cluster.getJmxPort(), c.host(), JmxClusterUtil.BYTES_IN_PER_SEC);
|
|
|
|
+ bytesOutPerSec = jmxClusterUtil.getJmxTrafficMetrics(cluster.getJmxPort(), c.host(), JmxClusterUtil.BYTES_OUT_PER_SEC);
|
|
metricsBuilder
|
|
metricsBuilder
|
|
.internalBrokerMetrics((brokers.stream().map(Node::id).collect(Collectors.toMap(k -> k, v -> InternalBrokerMetrics.builder().build()))))
|
|
.internalBrokerMetrics((brokers.stream().map(Node::id).collect(Collectors.toMap(k -> k, v -> InternalBrokerMetrics.builder().build()))))
|
|
.bytesOutPerSec(bytesOutPerSec)
|
|
.bytesOutPerSec(bytesOutPerSec)
|
|
.bytesInPerSec(bytesInPerSec);
|
|
.bytesInPerSec(bytesInPerSec);
|
|
-
|
|
|
|
return metricsBuilder.build();
|
|
return metricsBuilder.build();
|
|
}
|
|
}
|
|
)
|
|
)
|
|
@@ -223,17 +206,8 @@ public class KafkaService {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- @SneakyThrows
|
|
|
|
- private Mono<String> getClusterId(AdminClient adminClient) {
|
|
|
|
- return ClusterUtil.toMono(adminClient.describeCluster().clusterId());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
public Mono<ExtendedAdminClient> getOrCreateAdminClient(KafkaCluster cluster) {
|
|
public Mono<ExtendedAdminClient> getOrCreateAdminClient(KafkaCluster cluster) {
|
|
- Consumer<Long, String> kek = createConsumer();
|
|
|
|
- MBeanServer server = ManagementFactory.getPlatformMBeanServer();
|
|
|
|
-
|
|
|
|
return Mono.justOrEmpty(adminClientCache.get(cluster.getName()))
|
|
return Mono.justOrEmpty(adminClientCache.get(cluster.getName()))
|
|
.switchIfEmpty(createAdminClient(cluster))
|
|
.switchIfEmpty(createAdminClient(cluster))
|
|
.map(e -> adminClientCache.computeIfAbsent(cluster.getName(), key -> e));
|
|
.map(e -> adminClientCache.computeIfAbsent(cluster.getName(), key -> e));
|