Brokers.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React from 'react';
  2. import { ClusterName, ZooKeeperStatus } from 'redux/interfaces';
  3. import useInterval from 'lib/hooks/useInterval';
  4. import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted';
  5. import { useParams } from 'react-router';
  6. import TagStyled from 'components/common/Tag/Tag.styled';
  7. import TableHeaderCell from 'components/common/table/TableHeaderCell/TableHeaderCell';
  8. import { Table } from 'components/common/table/Table/Table.styled';
  9. import PageHeading from 'components/common/PageHeading/PageHeading';
  10. import * as Metrics from 'components/common/Metrics';
  11. import { useAppDispatch, useAppSelector } from 'lib/hooks/redux';
  12. import {
  13. fetchClusterStats,
  14. selectStats,
  15. } from 'redux/reducers/brokers/brokersSlice';
  16. const Brokers: React.FC = () => {
  17. const dispatch = useAppDispatch();
  18. const { clusterName } = useParams<{ clusterName: ClusterName }>();
  19. const {
  20. brokerCount,
  21. activeControllers,
  22. zooKeeperStatus,
  23. onlinePartitionCount,
  24. offlinePartitionCount,
  25. inSyncReplicasCount,
  26. outOfSyncReplicasCount,
  27. underReplicatedPartitionCount,
  28. diskUsage,
  29. version,
  30. } = useAppSelector(selectStats);
  31. React.useEffect(() => {
  32. dispatch(fetchClusterStats(clusterName));
  33. }, [fetchClusterStats, clusterName]);
  34. useInterval(() => {
  35. fetchClusterStats(clusterName);
  36. }, 5000);
  37. const zkOnline = zooKeeperStatus === ZooKeeperStatus.online;
  38. return (
  39. <>
  40. <PageHeading text="Brokers" />
  41. <Metrics.Wrapper>
  42. <Metrics.Section title="Uptime">
  43. <Metrics.Indicator label="Total Brokers">
  44. {brokerCount}
  45. </Metrics.Indicator>
  46. <Metrics.Indicator label="Active Controllers">
  47. {activeControllers}
  48. </Metrics.Indicator>
  49. <Metrics.Indicator label="Zookeeper Status">
  50. <TagStyled color={zkOnline ? 'green' : 'gray'}>
  51. {zkOnline ? 'online' : 'offline'}
  52. </TagStyled>
  53. </Metrics.Indicator>
  54. <Metrics.Indicator label="Version">{version}</Metrics.Indicator>
  55. </Metrics.Section>
  56. <Metrics.Section title="Partitions">
  57. <Metrics.Indicator label="Online" isAlert>
  58. {offlinePartitionCount && offlinePartitionCount > 0 ? (
  59. <Metrics.RedText>{onlinePartitionCount}</Metrics.RedText>
  60. ) : (
  61. onlinePartitionCount
  62. )}
  63. <Metrics.LightText>
  64. {' '}
  65. of {(onlinePartitionCount || 0) + (offlinePartitionCount || 0)}
  66. </Metrics.LightText>
  67. </Metrics.Indicator>
  68. <Metrics.Indicator label="URP" title="Under replicated partitions">
  69. {underReplicatedPartitionCount}
  70. </Metrics.Indicator>
  71. <Metrics.Indicator label="In Sync Replicas">
  72. {inSyncReplicasCount}
  73. </Metrics.Indicator>
  74. <Metrics.Indicator label="Out of Sync Replicas">
  75. {outOfSyncReplicasCount}
  76. </Metrics.Indicator>
  77. </Metrics.Section>
  78. </Metrics.Wrapper>
  79. <Table isFullwidth>
  80. <thead>
  81. <tr>
  82. <TableHeaderCell title="Broker" />
  83. <TableHeaderCell title="Segment size (Mb)" />
  84. <TableHeaderCell title="Segment Count" />
  85. </tr>
  86. </thead>
  87. <tbody>
  88. {diskUsage?.map(({ brokerId, segmentSize, segmentCount }) => (
  89. <tr key={brokerId}>
  90. <td>{brokerId}</td>
  91. <td>
  92. <BytesFormatted value={segmentSize} />
  93. </td>
  94. <td>{segmentCount}</td>
  95. </tr>
  96. ))}
  97. </tbody>
  98. </Table>
  99. </>
  100. );
  101. };
  102. export default Brokers;