Skip to content

Commit 4ec0422

Browse files
soffestSofia Shnaidman
andauthored
Brokers, Topic details: Display disk usage. (#129)
* Display brokers disk usage. * Fixed disk usage alignment. * Added disk usage to topic details. * Updated metrics wrapper props. Co-authored-by: Sofia Shnaidman <[email protected]>
1 parent 1a7aed1 commit 4ec0422

File tree

8 files changed

+74
-5
lines changed

8 files changed

+74
-5
lines changed

kafka-ui-react-app/src/components/Brokers/Brokers.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import cx from 'classnames';
66
import MetricsWrapper from 'components/common/Dashboard/MetricsWrapper';
77
import Indicator from 'components/common/Dashboard/Indicator';
88
import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb';
9+
import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted';
910

1011
interface Props extends ClusterStats {
1112
clusterName: ClusterName;
@@ -14,7 +15,7 @@ interface Props extends ClusterStats {
1415
fetchBrokers: (clusterName: ClusterName) => void;
1516
}
1617

17-
const Topics: React.FC<Props> = ({
18+
const Brokers: React.FC<Props> = ({
1819
clusterName,
1920
brokerCount,
2021
activeControllers,
@@ -24,6 +25,7 @@ const Topics: React.FC<Props> = ({
2425
inSyncReplicasCount,
2526
outOfSyncReplicasCount,
2627
underReplicatedPartitionCount,
28+
diskUsage,
2729
fetchClusterStats,
2830
fetchBrokers,
2931
}) => {
@@ -73,8 +75,24 @@ const Topics: React.FC<Props> = ({
7375
{outOfSyncReplicasCount}
7476
</Indicator>
7577
</MetricsWrapper>
78+
79+
<MetricsWrapper multiline title="Disk Usage">
80+
{diskUsage?.map((brokerDiskUsage) => (
81+
<React.Fragment key={brokerDiskUsage.brokerId}>
82+
<Indicator className="is-one-third" label="Broker">
83+
{brokerDiskUsage.brokerId}
84+
</Indicator>
85+
<Indicator className="is-one-third" label="Segment Size" title="">
86+
<BytesFormatted value={brokerDiskUsage.segmentSize} />
87+
</Indicator>
88+
<Indicator className="is-one-third" label="Segment count">
89+
{brokerDiskUsage.segmentCount}
90+
</Indicator>
91+
</React.Fragment>
92+
))}
93+
</MetricsWrapper>
7694
</div>
7795
);
7896
};
7997

80-
export default Topics;
98+
export default Brokers;

kafka-ui-react-app/src/components/Brokers/BrokersContainer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const mapStateToProps = (
3131
underReplicatedPartitionCount: brokerSelectors.getUnderReplicatedPartitionCount(
3232
state
3333
),
34+
diskUsage: brokerSelectors.getDiskUsage(state),
3435
});
3536

3637
const mapDispatchToProps = {

kafka-ui-react-app/src/components/Topics/Details/Overview/Overview.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ClusterName, TopicName } from 'redux/interfaces';
33
import { Topic, TopicDetails } from 'generated-sources';
44
import MetricsWrapper from 'components/common/Dashboard/MetricsWrapper';
55
import Indicator from 'components/common/Dashboard/Indicator';
6+
import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted';
67

78
interface Props extends Topic, TopicDetails {
89
isFetched: boolean;
@@ -22,6 +23,8 @@ const Overview: React.FC<Props> = ({
2223
partitionCount,
2324
internal,
2425
replicationFactor,
26+
segmentSize,
27+
segmentCount,
2528
fetchTopicDetails,
2629
}) => {
2730
React.useEffect(() => {
@@ -53,6 +56,10 @@ const Overview: React.FC<Props> = ({
5356
{internal ? 'Internal' : 'External'}
5457
</span>
5558
</Indicator>
59+
<Indicator label="Segment Size" title="">
60+
<BytesFormatted value={segmentSize} />
61+
</Indicator>
62+
<Indicator label="Segment count">{segmentCount}</Indicator>
5663
</MetricsWrapper>
5764
<div className="box">
5865
<table className="table is-striped is-fullwidth">
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
3+
interface Props {
4+
value: string | number | undefined;
5+
precision?: number;
6+
}
7+
8+
const BytesFormatted: React.FC<Props> = ({ value, precision }) => {
9+
const formatBytes = React.useCallback(() => {
10+
const numVal = typeof value === 'string' ? parseInt(value, 10) : value;
11+
if (!numVal) return 0;
12+
const pow = Math.floor(Math.log2(numVal) / 10);
13+
const multiplier = 10 ** (precision || 2);
14+
return (
15+
Math.round((numVal * multiplier) / 1024 ** pow) / multiplier +
16+
['Bytes', 'KB', 'MB', 'GB', 'TB'][pow]
17+
);
18+
}, [value]);
19+
return <span>{formatBytes()}</span>;
20+
};
21+
22+
export default BytesFormatted;

kafka-ui-react-app/src/components/common/Dashboard/Indicator.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import React from 'react';
2+
import cx from 'classnames';
23

34
interface Props {
45
label: string;
56
title?: string;
7+
className?: string;
68
}
79

8-
const Indicator: React.FC<Props> = ({ label, title, children }) => {
10+
const Indicator: React.FC<Props> = ({ label, title, className, children }) => {
911
return (
10-
<div className="level-item level-left">
12+
<div className={cx('level-item', 'level-left', className)}>
1113
<div title={title || label}>
1214
<p className="heading">{label}</p>
1315
<p className="title">{children}</p>

kafka-ui-react-app/src/components/common/Dashboard/MetricsWrapper.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ import cx from 'classnames';
44
interface Props {
55
title?: string;
66
wrapperClassName?: string;
7+
multiline?: boolean;
78
}
89

910
const MetricsWrapper: React.FC<Props> = ({
1011
title,
1112
children,
1213
wrapperClassName,
14+
multiline,
1315
}) => {
1416
return (
1517
<div className={cx('box', wrapperClassName)}>
1618
{title && <h5 className="subtitle is-6">{title}</h5>}
17-
<div className="level">{children}</div>
19+
<div className={cx('level', multiline ? 'level-multiline' : '')}>
20+
{children}
21+
</div>
1822
</div>
1923
);
2024
};

kafka-ui-react-app/src/redux/reducers/brokers/selectors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ export const getUnderReplicatedPartitionCount = createSelector(
4343
brokersState,
4444
({ underReplicatedPartitionCount }) => underReplicatedPartitionCount
4545
);
46+
47+
export const getDiskUsage = createSelector(
48+
brokersState,
49+
({ diskUsage }) => diskUsage
50+
);

kafka-ui-react-app/src/theme/bulma_overrides.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,13 @@
6868
from { opacity: 0; }
6969
to { opacity: 1; }
7070
}
71+
72+
.level.level-multiline {
73+
flex-wrap: wrap;
74+
.level-item.is-one-third {
75+
flex-basis: 26%;
76+
}
77+
.level-item.is-one-third:nth-child(n+4) {
78+
margin-top: 10px;
79+
}
80+
}

0 commit comments

Comments
 (0)