Skip to content

Commit

Permalink
Added Server Info array to Basic dashboard (#963)
Browse files Browse the repository at this point in the history
* Added Servers array to admin_info api

* Added TableWrapper, wrap

* Created Server table

* Added Servers array to admin_info api

Added TableWrapper, wrap

Created Server table

* Removed testing element

* Formatted server uptime with niceDays

* Added Servers array to admin_info api

Added TableWrapper, wrap

Created Server table

* Removed testing element

* Formatted server uptime with niceDays

* Formatted uptime using niceDays

* Sorted server table by endpoint

Co-authored-by: Harshavardhana <harsha@minio.io>
  • Loading branch information
jinapurapu and harshavardhana committed Aug 24, 2021
1 parent 4c01be2 commit 4306d0f
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 12 deletions.
53 changes: 53 additions & 0 deletions models/admin_info_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions models/server_properties.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@
// 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, { Fragment } from "react";
import React, { Fragment, useState } from "react";
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
import clsx from "clsx";
import Grid from "@material-ui/core/Grid";
import Paper from "@material-ui/core/Paper";
import Typography from "@material-ui/core/Typography";
import { Usage } from "../types";
import { niceBytes } from "../../../../common/utils";
import { Usage, ServerInfo } from "../types";
import { niceBytes, niceDays } from "../../../../common/utils";
import AllBucketsIcon from "../../../../icons/AllBucketsIcon";
import UsageIcon from "../../../../icons/UsageIcon";
import DnsIcon from "@material-ui/icons/Dns";
import EgressIcon from "../../../../icons/EgressIcon";
import TableWrapper from "../../Common/TableWrapper/TableWrapper";
import { TableContainer } from "@material-ui/core";

const styles = (theme: Theme) =>
createStyles({
Expand Down Expand Up @@ -57,6 +60,7 @@ const styles = (theme: Theme) =>
},
notationContainer: {
display: "flex",
flexWrap: "wrap",
},
dashboardBG: {
width: 390,
Expand Down Expand Up @@ -120,6 +124,45 @@ const BasicDashboard = ({ classes, usage }: IDashboardProps) => {
return usage.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
};

const serverColumns = [
{
label: "Endpoint",
elementKey: "endpoint",
},
{
label: "Status",
elementKey: "state",
},
{
label: "Uptime",
elementKey: "uptime",
},
{
label: "Version",
elementKey: "version",
},
];

const makeServerArray = (usage: Usage | null) => {
if (usage != null) {
usage.servers.forEach(s => s.uptime = niceDays(s.uptime))
return usage.servers.sort(function (a, b) {
var nameA = a.endpoint.toUpperCase();
var nameB = b.endpoint.toUpperCase();
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
});
}
else return [];
};

const serverArray = makeServerArray(usage);

return (
<Fragment>
<div className={classes.dashboardBG} />
Expand Down Expand Up @@ -172,6 +215,24 @@ const BasicDashboard = ({ classes, usage }: IDashboardProps) => {
{usage ? prettyNumber(usage.objects) : 0}
</Typography>
</Paper>
<Grid container direction="row" alignItems="center">
<Grid item className={classes.icon}>
<DnsIcon />
</Grid>
<Grid item>
<Typography className={classes.elementTitle}>
{" "}
Servers
</Typography>
</Grid>
<TableWrapper
columns={serverColumns}
isLoading={false}
records={serverArray}
entityName="Servers"
idField="endpoint"
/>
</Grid>
</Grid>
</Grid>
</Grid>
Expand Down
10 changes: 10 additions & 0 deletions portal-ui/src/screens/Console/Dashboard/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ export interface Usage {
buckets: number;
objects: number;
widgets?: any;
servers: ServerInfo[];
}

export interface ServerInfo {
state: string;
endpoint: string;
uptime: string;
version: string;
commitID: string;
poolNumber: number;
}
19 changes: 19 additions & 0 deletions restapi/admin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -62,6 +63,7 @@ type UsageInfo struct {
Objects int64
Usage int64
DisksUsage int64
Servers []*models.ServerProperties
}

// GetAdminInfo invokes admin info and returns a parsed `UsageInfo` structure
Expand All @@ -80,11 +82,27 @@ func GetAdminInfo(ctx context.Context, client MinioAdmin) (*UsageInfo, error) {
}
}

//serverArray contains the serverProperties which describe the servers in the network
var serverArray []*models.ServerProperties
for _, serv := range serverInfo.Servers {
var newServer = &models.ServerProperties{
State: serv.State,
Endpoint: serv.Endpoint,
Uptime: strconv.Itoa(int(serv.Uptime)),
Version: serv.Version,
CommitID: serv.CommitID,
PoolNumber: int64(serv.PoolNumber),
}

serverArray = append(serverArray, newServer)
}

return &UsageInfo{
Buckets: int64(serverInfo.Buckets.Count),
Objects: int64(serverInfo.Objects.Count),
Usage: int64(serverInfo.Usage.Size),
DisksUsage: usedSpace,
Servers: serverArray,
}, nil
}

Expand Down Expand Up @@ -820,6 +838,7 @@ func getUsageWidgetsForDeployment(prometheusURL string, mAdmin *madmin.AdminClie
Buckets: usage.Buckets,
Objects: usage.Objects,
Usage: usage.Usage,
Servers: usage.Servers,
}
return sessionResp, nil
}
Expand Down

0 comments on commit 4306d0f

Please sign in to comment.