InternalClusterState.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.provectus.kafka.ui.model;
  2. import com.google.common.base.Throwables;
  3. import java.math.BigDecimal;
  4. import java.util.List;
  5. import java.util.Optional;
  6. import java.util.stream.Collectors;
  7. import lombok.Data;
  8. @Data
  9. public class InternalClusterState {
  10. private String name;
  11. private ServerStatusDTO status;
  12. private MetricsCollectionErrorDTO lastError;
  13. private Integer topicCount;
  14. private Integer brokerCount;
  15. private Integer activeControllers;
  16. private Integer onlinePartitionCount;
  17. private Integer offlinePartitionCount;
  18. private Integer inSyncReplicasCount;
  19. private Integer outOfSyncReplicasCount;
  20. private Integer underReplicatedPartitionCount;
  21. private List<BrokerDiskUsageDTO> diskUsage;
  22. private String version;
  23. private List<Feature> features;
  24. private BigDecimal bytesInPerSec;
  25. private BigDecimal bytesOutPerSec;
  26. private Boolean readOnly;
  27. public InternalClusterState(KafkaCluster cluster, Statistics statistics) {
  28. name = cluster.getName();
  29. status = statistics.getStatus();
  30. lastError = Optional.ofNullable(statistics.getLastKafkaException())
  31. .map(e -> new MetricsCollectionErrorDTO()
  32. .message(e.getMessage())
  33. .stackTrace(Throwables.getStackTraceAsString(e)))
  34. .orElse(null);
  35. topicCount = statistics.getTopicDescriptions().size();
  36. brokerCount = statistics.getClusterDescription().getNodes().size();
  37. activeControllers = statistics.getClusterDescription().getController() != null ? 1 : 0;
  38. version = statistics.getVersion();
  39. if (statistics.getLogDirInfo() != null) {
  40. diskUsage = statistics.getLogDirInfo().getBrokerStats().entrySet().stream()
  41. .map(e -> new BrokerDiskUsageDTO()
  42. .brokerId(e.getKey())
  43. .segmentSize(e.getValue().getSegmentSize())
  44. .segmentCount(e.getValue().getSegmentsCount()))
  45. .collect(Collectors.toList());
  46. }
  47. features = statistics.getFeatures();
  48. bytesInPerSec = statistics
  49. .getMetrics()
  50. .getBytesInPerSec()
  51. .values().stream()
  52. .reduce(BigDecimal.ZERO, BigDecimal::add);
  53. bytesOutPerSec = statistics
  54. .getMetrics()
  55. .getBytesOutPerSec()
  56. .values().stream()
  57. .reduce(BigDecimal.ZERO, BigDecimal::add);
  58. var partitionsStats = new PartitionsStats(statistics.getTopicDescriptions().values());
  59. onlinePartitionCount = partitionsStats.getOnlinePartitionCount();
  60. offlinePartitionCount = partitionsStats.getOfflinePartitionCount();
  61. inSyncReplicasCount = partitionsStats.getInSyncReplicasCount();
  62. outOfSyncReplicasCount = partitionsStats.getOutOfSyncReplicasCount();
  63. underReplicatedPartitionCount = partitionsStats.getUnderReplicatedPartitionCount();
  64. readOnly = cluster.isReadOnly();
  65. }
  66. }