InternalClusterState.java 2.8 KB

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