-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathStorageSection.tsx
169 lines (158 loc) · 6.39 KB
/
StorageSection.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { Stack, Text, Paper } from '@mantine/core';
import classes from './styles/Systems.module.css';
import { AreaChart, ChartTooltipProps } from '@mantine/charts';
import { IngestorQueryRecord } from '@/@types/parseable/api/clusterInfo';
import _ from 'lodash';
import { useMemo } from 'react';
import { useClusterStore } from './providers/ClusterProvider';
import { calcCompressionRate, formatBytes } from '@/utils/formatBytes';
import { IconArrowDown } from '@tabler/icons-react';
import timeRangeUtils from '@/utils/timeRangeUtils';
const { formatDateWithTimezone } = timeRangeUtils;
function ChartTooltip({ payload }: ChartTooltipProps) {
if (!payload || (Array.isArray(payload) && payload.length === 0)) return null;
const { size, date } = payload[0]?.payload || {};
return (
<Paper px="md" py="sm" withBorder shadow="md" radius="md">
<Text fw={600} mb={5}>
{date}
</Text>
<Stack style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
<Text>Storage Used</Text>
<Text>{formatBytes(size)}</Text>
</Stack>
</Paper>
);
}
const Graph = (props: { data: { date: string; value: string }[] }) => {
return (
<Stack className={classes.graphContainer} h="100%">
<AreaChart
data={props.data}
dataKey="date"
series={[{ name: 'size', color: 'indigo.6' }]}
curveType="linear"
style={{ height: '100%' }}
tooltipProps={{
content: ({ label, payload }) => <ChartTooltip label={label} payload={payload} />,
position: { y: -20 },
}}
yAxisProps={{ tickFormatter: (value) => `${formatBytes(value)}`, fontSize: '12px' }}
/>
</Stack>
);
};
const StorageSizeGraph = () => {
const [data] = useClusterStore((store) => store.currentMachineData);
const graphData = _.reduce(
data,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
(acc, record) => {
const date = _.get(record, 'event_time', '');
const localDate = new Date(`${date}Z`);
const parsedDate = formatDateWithTimezone(localDate, 'HH:mm A z');
const size = _.get(record, 'parseable_storage_size_data', 0);
return [...acc, { date: parsedDate, size }];
},
[],
);
return (
<Stack className={classes.eventCountGraph}>
<Stack style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
<Text className={classes.fieldTitle}>Storage Size</Text>
</Stack>
<Graph data={graphData} />
</Stack>
);
};
const OverallSection = () => {
const [record] = useClusterStore((store) => store.currentMachineRecentRecord);
const opts = useMemo(() => makeOverallStorageSectionProps(record), [record]);
return (
<Stack className={classes.overallSectionContainer}>
<Text className={classes.fieldTitle}>Overall Storage Stats</Text>
<Stack gap={0} style={{ justifyContent: 'space-between', flexDirection: 'row' }}>
<Text size="md">Used</Text>
<Stack gap={0} style={{ justifyContent: 'flex-end', alignItems: 'flex-end' }}>
<Stack gap="0.5rem" style={{ flexDirection: 'row' }}>
<Text size="md">{`${opts.storageSize} ${' '}`}</Text>
<Stack style={{ flexDirection: 'row', alignItems: 'center' }} gap={0}>
<Text ta="center" size="md" className={classes.compressionText}>
( {opts.activeCompressionRate}
</Text>
<IconArrowDown className={classes.compressionText} size="0.9rem" />
<Text size="md" className={classes.compressionText}>
)
</Text>
</Stack>
</Stack>
<Stack style={{ width: '100%', alignItems: 'flex-end' }}>
<Text className={classes.fieldDescription}>{opts.ingestedSize} Ingested</Text>
</Stack>
</Stack>
</Stack>
<Stack gap={0} style={{ justifyContent: 'space-between', flexDirection: 'row' }}>
<Text size="md">Lifetime</Text>
<Stack gap={0} style={{ justifyContent: 'flex-end', alignItems: 'flex-end' }}>
<Stack gap="0.5rem" style={{ flexDirection: 'row' }}>
<Text size="md">{`${opts.lifetimeStorageSize} ${' '}`}</Text>
{/* <Stack style={{ flexDirection: 'row', alignItems: 'center' }} gap={0}>
<Text ta="center" className={classes.compressionText}>
( {opts.activeCompressionRate}
</Text>
<IconArrowDown className={classes.compressionText} size="1.3rem" />)
</Stack> */}
</Stack>
<Stack style={{ width: '100%', alignItems: 'flex-end' }}>
<Text className={classes.fieldDescription}>{opts.lifetimeIngestedSize} Ingested</Text>
</Stack>
</Stack>
</Stack>
<Stack gap={0} style={{ justifyContent: 'space-between', flexDirection: 'row' }}>
<Text size="md">Deleted</Text>
<Stack gap={0} style={{ justifyContent: 'flex-end', alignItems: 'flex-end' }}>
<Stack gap="0.5rem" style={{ flexDirection: 'row' }}>
<Text size="md">{`${opts.deletedStorageSize} ${' '}`}</Text>
{/* <Stack style={{ flexDirection: 'row', alignItems: 'center' }} gap={0}>
<Text ta="center" className={classes.compressionText}>
( {opts.activeCompressionRate}
</Text>
<IconArrowDown className={classes.compressionText} size="1.3rem" />)
</Stack> */}
</Stack>
{/* <Stack style={{ width: '100%', alignItems: 'flex-end' }}>
<Text className={classes.fieldDescription}>{opts.ingestedSize} Ingested</Text>
</Stack> */}
</Stack>
</Stack>
</Stack>
);
};
const StorageSection = () => {
return (
<Stack style={{ height: '33%', flexDirection: 'row', overflow: 'hidden' }}>
<StorageSizeGraph />
<OverallSection />
</Stack>
);
};
const makeOverallStorageSectionProps = (record: IngestorQueryRecord | null) => {
const storageSize = _.get(record, 'parseable_storage_size_data', 0);
const lifetimeStorageSize = _.get(record, 'parseable_lifetime_storage_size.data', 0);
const deletedStorageSize = _.get(record, 'parseable_deleted_storage_size.data', 0);
const ingestedSize = _.get(record, 'parseable_events_ingested_size', 0);
const lifetimeIngestedSize = _.get(record, 'parseable_lifetime_events_ingested_size', 0);
const lifetimeCompressionRate = calcCompressionRate(lifetimeStorageSize, lifetimeIngestedSize);
const activeCompressionRate = calcCompressionRate(storageSize, ingestedSize);
return {
storageSize: formatBytes(storageSize),
lifetimeIngestedSize: formatBytes(lifetimeIngestedSize),
lifetimeStorageSize: formatBytes(lifetimeStorageSize),
deletedStorageSize: formatBytes(deletedStorageSize),
ingestedSize: formatBytes(ingestedSize),
lifetimeCompressionRate,
activeCompressionRate,
};
};
export default StorageSection;