-
Notifications
You must be signed in to change notification settings - Fork 300
/
Copy pathBasicDashboard.tsx
375 lines (356 loc) · 11 KB
/
BasicDashboard.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// This file is part of MinIO Console Server
// Copyright (c) 2022 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import React from "react";
import { Box, Grid } from "@mui/material";
import {
ArrowRightIcon,
BucketsIcon,
Button,
DiagnosticsMenuIcon,
DrivesIcon,
FormatDrivesIcon,
HealIcon,
HelpBox,
PrometheusErrorIcon,
ServersIcon,
StorageIcon,
TotalObjectsIcon,
UptimeIcon,
} from "mds";
import { calculateBytes, representationNumber } from "../../../../common/utils";
import { IDriveInfo, Usage } from "../types";
import StatusCountCard from "./StatusCountCard";
import groupBy from "lodash/groupBy";
import ServersList from "./ServersList";
import CounterCard from "./CounterCard";
import ReportedUsage from "./ReportedUsage";
import { Link } from "react-router-dom";
import { IAM_PAGES } from "../../../../common/SecureComponent/permissions";
import TimeStatItem from "../TimeStatItem";
import TooltipWrapper from "../../Common/TooltipWrapper/TooltipWrapper";
const BoxItem = ({ children }: { children: any }) => {
return (
<Box
sx={{
border: "1px solid #f1f1f1",
padding: {
md: "15px",
xs: "5px",
},
height: "136px",
maxWidth: {
sm: "100%",
},
}}
>
{children}
</Box>
);
};
interface IDashboardProps {
usage: Usage | null;
}
const getServersList = (usage: Usage | null) => {
if (usage !== null) {
return [...usage.servers].sort(function (a, b) {
const nameA = a.endpoint.toLowerCase();
const nameB = b.endpoint.toLowerCase();
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
});
}
return [];
};
const prettyUsage = (usage: string | undefined) => {
if (usage === undefined) {
return { total: "0", unit: "Mi" };
}
return calculateBytes(usage);
};
const BasicDashboard = ({ usage }: IDashboardProps) => {
const usageValue = usage && usage.usage ? usage.usage.toString() : "0";
const usageToRepresent = prettyUsage(usageValue);
const { lastScan = "n/a", lastHeal = "n/a", upTime = "n/a" } = usage || {};
const serverList = getServersList(usage || null);
let allDrivesArray: IDriveInfo[] = [];
serverList.forEach((server) => {
const drivesInput = server.drives.map((drive) => {
return drive;
});
allDrivesArray = [...allDrivesArray, ...drivesInput];
});
const serversGroup = groupBy(serverList, "state");
const { offline: offlineServers = [], online: onlineServers = [] } =
serversGroup;
const drivesGroup = groupBy(allDrivesArray, "state");
const { offline: offlineDrives = [], ok: onlineDrives = [] } = drivesGroup;
return (
<Box>
<Box
sx={{
display: "grid",
gridTemplateRows: "1fr",
gridTemplateColumns: "1fr",
gap: "27px",
marginBottom: "40px",
}}
>
<Box
sx={{
display: "grid",
gridTemplateColumns: "1fr",
gap: "40px",
}}
>
<Box
sx={{
display: "grid",
gridTemplateRows: "136px",
gridTemplateColumns: {
sm: "1fr 1fr 1fr",
xs: "1fr",
},
gap: {
md: "20px",
xs: "20px",
},
}}
>
<BoxItem>
<CounterCard
label={"Buckets"}
icon={<BucketsIcon />}
counterValue={usage ? representationNumber(usage.buckets) : 0}
actions={
<Link
to={IAM_PAGES.BUCKETS}
style={{
zIndex: 999,
textDecoration: "none",
top: "40px",
position: "relative",
marginRight: "75px",
}}
>
<TooltipWrapper tooltip={"Browse"}>
<Button
id={"browse-dashboard"}
onClick={() => {}}
label={"Browse"}
icon={<ArrowRightIcon />}
variant={"regular"}
style={{
padding: 5,
height: 30,
fontSize: 14,
marginTop: 20,
}}
/>
</TooltipWrapper>
</Link>
}
/>
</BoxItem>
<BoxItem>
<CounterCard
label={"Objects"}
icon={<TotalObjectsIcon />}
counterValue={usage ? representationNumber(usage.objects) : 0}
/>
</BoxItem>
<BoxItem>
<StatusCountCard
onlineCount={onlineServers.length}
offlineCount={offlineServers.length}
label={"Servers"}
icon={<ServersIcon />}
/>
</BoxItem>
<BoxItem>
<StatusCountCard
offlineCount={
usage?.backend.offlineDrives || offlineDrives.length
}
onlineCount={usage?.backend.onlineDrives || onlineDrives.length}
label={"Drives"}
icon={<DrivesIcon />}
/>
</BoxItem>
<Box
sx={{
gridRowStart: "1",
gridRowEnd: "3",
gridColumnStart: "3",
border: "1px solid #f1f1f1",
padding: "15px",
display: "grid",
justifyContent: "stretch",
}}
>
<ReportedUsage
usageValue={usageValue}
total={usageToRepresent.total}
unit={usageToRepresent.unit}
/>
<Box
sx={{
display: "flex",
flexFlow: "column",
gap: "14px",
}}
>
<TimeStatItem
icon={<HealIcon />}
label={
<Box>
<Box
sx={{
display: {
md: "inline",
xs: "none",
},
}}
>
Time since last
</Box>{" "}
Heal Activity
</Box>
}
value={lastHeal}
/>
<TimeStatItem
icon={<DiagnosticsMenuIcon />}
label={
<Box>
<Box
sx={{
display: {
md: "inline",
xs: "none",
},
}}
>
Time since last
</Box>{" "}
Scan Activity
</Box>
}
value={lastScan}
/>
<TimeStatItem
icon={<UptimeIcon />}
label={"Uptime"}
value={upTime}
/>
</Box>
</Box>
</Box>
<Grid container spacing={1}>
<Grid item xs={4}>
<TimeStatItem
icon={<StorageIcon />}
label={"Backend type"}
value={
usage?.backend?.backendType
? usage.backend.backendType
: "Unknown"
}
/>
</Grid>
<Grid item xs={4}>
<TimeStatItem
icon={<FormatDrivesIcon />}
label={"Standard storage class parity"}
value={
usage?.backend?.standardSCParity
? usage.backend.standardSCParity.toString()
: "n/a"
}
/>
</Grid>
<Grid item xs={4}>
<TimeStatItem
icon={<FormatDrivesIcon />}
label={"Reduced redundancy storage class parity"}
value={
usage?.backend?.standardSCParity
? usage.backend.rrSCParity.toString()
: "n/a"
}
/>
</Grid>
</Grid>
<Box
sx={{
display: "grid",
gridTemplateRows: "auto",
gridTemplateColumns: "1fr",
gap: "auto",
}}
>
<ServersList data={serverList} />
</Box>
</Box>
{usage?.advancedMetricsStatus === "not configured" && (
<Box>
<HelpBox
iconComponent={<PrometheusErrorIcon />}
title={"We can’t retrieve advanced metrics at this time."}
help={
<Box>
<Box
sx={{
fontSize: "14px",
}}
>
MinIO Dashboard will display basic metrics as we couldn’t
connect to Prometheus successfully. Please try again in a
few minutes. If the problem persists, you can review your
configuration and confirm that Prometheus server is up and
running.
</Box>
<Box
sx={{
paddingTop: "20px",
fontSize: "14px",
"& a": {
color: (theme) => theme.colors.link,
},
}}
>
<a
href="https://min.io/docs/minio/linux/operations/monitoring/collect-minio-metrics-using-prometheus.html"
target="_blank"
rel="noopener"
>
Read more about Prometheus on our Docs site.
</a>
</Box>
</Box>
}
/>
</Box>
)}
</Box>
</Box>
);
};
export default BasicDashboard;