New admin info (#2982)

This commit is contained in:
ebozduman
2019-12-11 18:25:55 -08:00
committed by kannappanr
parent 7038207039
commit 2616a1d051
6 changed files with 214 additions and 832 deletions
-208
View File
@@ -1,208 +0,0 @@
/*
* MinIO Client (C) 2019 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cmd
import (
"encoding/json"
"fmt"
"net/url"
"sort"
"strings"
"github.com/fatih/color"
"github.com/minio/cli"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/pkg/probe"
"github.com/minio/minio/pkg/madmin"
)
const (
monitor = "BoldGreen"
monitorDegraded = "BoldYellow"
monitorFail = "BoldRed"
)
var adminInfoCPU = cli.Command{
Name: "cpu",
Usage: "display MinIO server cpu information",
Action: mainAdminCPUInfo,
Before: setGlobalsFromContext,
Flags: globalFlags,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Get server CPU information of the 'play' MinIO server.
{{.Prompt}} {{.HelpName}} play/
`,
}
// serverMonitorMessage holds service status info along with
// cpu, mem, net and disk monitoristics
type serverMonitorMessage struct {
Monitor string `json:"status"`
Service string `json:"service"`
Addr string `json:"address"`
Err string `json:"error"`
CPULoad *madmin.ServerCPULoadInfo `json:"cpu,omitempty"`
}
func (s serverMonitorMessage) JSON() string {
s.Monitor = "success"
if s.Err != "" {
s.Monitor = "fail"
}
statusJSONBytes, e := json.MarshalIndent(s, "", " ")
fatalIf(probe.NewError(e), "Unable to marshal into JSON")
return string(statusJSONBytes)
}
func (s serverMonitorMessage) String() string {
msg := ""
dot := "●"
if s.Err != "" || s.Service == "off" {
msg += fmt.Sprintf("%s %s\n", console.Colorize(monitorFail, dot), s.Addr)
msg += fmt.Sprintf(" Server is %s\n", console.Colorize(monitorFail, "offline"))
msg += fmt.Sprintf(" Error : %s\n", console.Colorize(monitorFail, s.Err))
return msg
}
// Print server title
msg += fmt.Sprintf("%s %s \n", console.Colorize(monitor, dot), s.Addr)
msg += "\n"
msg += fmt.Sprintf("%s min avg max\n", console.Colorize(monitor, " CPU"))
for i := range s.CPULoad.Load {
msg += fmt.Sprintf(" current %.2f%% %.2f%% %.2f%%\n", s.CPULoad.Load[i].Min, s.CPULoad.Load[i].Avg, s.CPULoad.Load[i].Max)
if len(s.CPULoad.HistoricLoad) > i {
msg += fmt.Sprintf(" historic %.2f%% %.2f%% %.2f%%\n", s.CPULoad.HistoricLoad[i].Min, s.CPULoad.HistoricLoad[i].Avg, s.CPULoad.HistoricLoad[i].Max)
}
msg += "\n"
}
return msg
}
func mainAdminCPUInfo(ctx *cli.Context) error {
checkAdminCPUInfoSyntax(ctx)
// set the console colors
console.SetColor(monitor, color.New(color.FgGreen, color.Bold))
console.SetColor(monitorDegraded, color.New(color.FgYellow, color.Bold))
console.SetColor(monitorFail, color.New(color.FgRed, color.Bold))
// Get the alias
args := ctx.Args()
aliasedURL := args.Get(0)
// Create a new MinIO admin client
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")
printOfflineErrorMessage := func(err error) {
errMsg := ""
if err != nil {
errMsg = err.Error()
}
printMsg(serverMonitorMessage{
Addr: aliasedURL,
Service: "off",
Err: errMsg,
})
}
processErr := func(e error) error {
switch e.(type) {
case *json.SyntaxError:
printOfflineErrorMessage(e)
return e
case *url.Error:
printOfflineErrorMessage(e)
return e
default:
// If the error is not nil and unrecognized, just print it and exit
fatalIf(probe.NewError(e), "Cannot get service status.")
}
return nil
}
// Fetch info of all CPU loads (all MinIO server instances)
cpuLoads, e := client.ServerCPULoadInfo()
if err := processErr(e); err != nil {
// exit immediately if error encountered
return nil
}
sort.Sort(&sortCPUWrapper{cpuLoads: cpuLoads})
for _, cpuLoad := range cpuLoads {
if cpuLoad.Error != "" {
printMsg(serverMonitorMessage{
Service: "off",
Addr: cpuLoad.Addr,
Err: cpuLoad.Error,
})
continue
}
printMsg(serverMonitorMessage{
Service: "on",
Addr: cpuLoad.Addr,
CPULoad: &cpuLoad,
})
}
return nil
}
type sortCPUWrapper struct {
cpuLoads []madmin.ServerCPULoadInfo
}
func (s *sortCPUWrapper) Len() int {
return len(s.cpuLoads)
}
func (s *sortCPUWrapper) Swap(i, j int) {
if s.cpuLoads != nil {
s.cpuLoads[i], s.cpuLoads[j] = s.cpuLoads[j], s.cpuLoads[i]
return
}
}
func (s *sortCPUWrapper) Less(i, j int) bool {
if s.cpuLoads != nil {
return strings.Compare(s.cpuLoads[i].Addr, s.cpuLoads[j].Addr) < 0
}
return false
}
// checkAdminMonitorSyntax - validate all the passed arguments
func checkAdminCPUInfoSyntax(ctx *cli.Context) {
if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
exit := globalErrorExitStatus
cli.ShowCommandHelpAndExit(ctx, "cpu", exit)
}
}
-210
View File
@@ -1,210 +0,0 @@
/*
* MinIO Client (C) 2019 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cmd
import (
"encoding/json"
"fmt"
"net/url"
"sort"
"strings"
humanize "github.com/dustin/go-humanize"
"github.com/fatih/color"
"github.com/minio/cli"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/pkg/probe"
"github.com/minio/minio/pkg/madmin"
)
const (
memory = "BoldGreen"
memoryDegraded = "BoldYellow"
memoryFail = "BoldRed"
)
var adminInfoMem = cli.Command{
Name: "mem",
Usage: "display MinIO server memory information",
Action: mainAdminMemInfo,
Before: setGlobalsFromContext,
Flags: globalFlags,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Get server CPU information of the 'play' MinIO server.
{{.Prompt}} {{.HelpName}} play/
`,
}
// serverMonitorMessage holds service status info along with
// cpu, mem, net and disk monitoristics
type serverMemoryInfo struct {
Monitor string `json:"status"`
Service string `json:"service"`
Addr string `json:"address"`
Err string `json:"error"`
MemUsage *madmin.ServerMemUsageInfo `json:"mem,omitempty"`
}
func (s serverMemoryInfo) JSON() string {
s.Monitor = "success"
if s.Err != "" {
s.Monitor = "fail"
}
statusJSONBytes, e := json.MarshalIndent(s, "", " ")
fatalIf(probe.NewError(e), "Unable to marshal into JSON")
return string(statusJSONBytes)
}
func (s serverMemoryInfo) String() string {
msg := ""
dot := "●"
if s.Err != "" || s.Service == "off" {
msg += fmt.Sprintf("%s %s\n", console.Colorize(memoryFail, dot), s.Addr)
msg += fmt.Sprintf(" Server is %s\n", console.Colorize(memoryFail, "offline"))
msg += fmt.Sprintf(" Error : %s\n", console.Colorize(memoryFail, s.Err))
return msg
}
// Print server title
msg += fmt.Sprintf("%s %s \n", console.Colorize(memory, dot), s.Addr)
msg += "\n"
// Mem section
msg += fmt.Sprintf("%s usage\n", console.Colorize(memory, " MEM"))
for i := range s.MemUsage.Usage {
msg += fmt.Sprintf(" current %s\n", humanize.IBytes(s.MemUsage.Usage[i].Mem))
if len(s.MemUsage.HistoricUsage) > i {
msg += fmt.Sprintf(" historic %s\n", humanize.IBytes(s.MemUsage.HistoricUsage[i].Mem))
}
msg += "\n"
}
return msg
}
func mainAdminMemInfo(ctx *cli.Context) error {
checkAdminMemInfoSyntax(ctx)
// set the console colors
console.SetColor(memory, color.New(color.FgGreen, color.Bold))
console.SetColor(memoryDegraded, color.New(color.FgYellow, color.Bold))
console.SetColor(memoryFail, color.New(color.FgRed, color.Bold))
// Get the alias
args := ctx.Args()
aliasedURL := args.Get(0)
// Create a new MinIO admin client
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")
printOfflineErrorMessage := func(err error) {
errMsg := ""
if err != nil {
errMsg = err.Error()
}
printMsg(serverMonitorMessage{
Addr: aliasedURL,
Service: "off",
Err: errMsg,
})
}
processErr := func(e error) error {
switch e.(type) {
case *json.SyntaxError:
printOfflineErrorMessage(e)
return e
case *url.Error:
printOfflineErrorMessage(e)
return e
default:
// If the error is not nil and unrecognized, just print it and exit
fatalIf(probe.NewError(e), "Cannot get service status.")
}
return nil
}
memUsages, e := client.ServerMemUsageInfo()
if err := processErr(e); err != nil {
// exit immediately if error encountered
return nil
}
sort.Sort(&sortMemWrapper{memUsages: memUsages})
for _, memUsage := range memUsages {
if memUsage.Error != "" {
printMsg(serverMemoryInfo{
Service: "off",
Addr: memUsage.Addr,
Err: memUsage.Error,
})
continue
}
printMsg(serverMemoryInfo{
Service: "on",
Addr: memUsage.Addr,
MemUsage: &memUsage,
})
}
return nil
}
type sortMemWrapper struct {
memUsages []madmin.ServerMemUsageInfo
}
func (s *sortMemWrapper) Len() int {
return len(s.memUsages)
}
func (s *sortMemWrapper) Swap(i, j int) {
if s.memUsages != nil {
s.memUsages[i], s.memUsages[j] = s.memUsages[j], s.memUsages[i]
}
}
func (s *sortMemWrapper) Less(i, j int) bool {
if s.memUsages != nil {
return strings.Compare(s.memUsages[i].Addr, s.memUsages[j].Addr) < 0
}
return false
}
// checkAdminMonitorSyntax - validate all the passed arguments
func checkAdminMemInfoSyntax(ctx *cli.Context) {
if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
exit := globalErrorExitStatus
cli.ShowCommandHelpAndExit(ctx, "mem", exit)
}
}
-404
View File
@@ -1,404 +0,0 @@
/*
* MinIO Client (C) 2016-2019 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cmd
import (
"fmt"
"net/url"
"sort"
"strings"
"time"
"github.com/dustin/go-humanize"
"github.com/fatih/color"
"github.com/minio/cli"
json "github.com/minio/mc/pkg/colorjson"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/pkg/probe"
"github.com/minio/minio/pkg/madmin"
)
var adminInfoServer = cli.Command{
Name: "server",
Usage: "display MinIO server information",
Action: mainAdminServerInfo,
Before: setGlobalsFromContext,
Flags: globalFlags,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Get server information of the 'play' MinIO server.
{{.Prompt}} {{.HelpName}} play/
`,
}
// backendType - indicates the type of backend storage
type backendType string
const (
fsType = backendType("FS")
erasureType = backendType("Erasure")
)
// fsBackend contains specific FS storage information
type fsBackend struct {
Type backendType `json:"backendType"`
}
// xlBackend contains specific erasure storage information
type xlBackend struct {
Type backendType `json:"backendType"`
OnlineDisks int `json:"onlineDisks"`
OfflineDisks int `json:"offlineDisks"`
// Data disks for currently configured Standard storage class.
StandardSCData int `json:"standardSCData"`
// Parity disks for currently configured Standard storage class.
StandardSCParity int `json:"standardSCParity"`
// Data disks for currently configured Reduced Redundancy storage class.
RRSCData int `json:"rrSCData"`
// Parity disks for currently configured Reduced Redundancy storage class.
RRSCParity int `json:"rrSCParity"`
// List of all disk status.
Sets [][]madmin.DriveInfo `json:"sets"`
}
// backendStatus represents the overall information of all backend storage types
type backendStatus struct {
// Total used space per tenant.
Used uint64 `json:"used"`
// Total available space.
Available uint64 `json:"available"`
// Total disk space.
Total uint64 `json:"total"`
// Backend type.
Backend interface{} `json:"backend"`
}
// ServerInfo holds the whole server information that will be
// returned by ServerInfo API.
type ServerInfo struct {
ConnStats madmin.ServerConnStats `json:"network"`
Properties madmin.ServerProperties `json:"server"`
CPULoad madmin.ServerCPULoadInfo `json:"cpu,omitempty"`
MemUsage madmin.ServerMemUsageInfo `json:"mem,omitempty"`
}
// infoMessage container to hold service status information.
type infoMessage struct {
Status string `json:"status"`
Service string `json:"service"`
Addr string `json:"address"`
Err string `json:"error"`
StorageInfo backendStatus `json:"storage"`
*ServerInfo
}
func filterPerNode(addr string, m map[string]int) int {
if val, ok := m[addr]; ok {
return val
}
return -1
}
// String colorized service status message.
func (u infoMessage) String() (msg string) {
dot := "●"
// When service is offline
if u.Service == "off" {
msg += fmt.Sprintf("%s %s\n", console.Colorize("InfoFail", dot), console.Colorize("PrintB", u.Addr))
msg += fmt.Sprintf(" Uptime: %s\n", console.Colorize("InfoFail", "offline"))
return
}
// Print error if any and exit
if u.Err != "" {
msg += fmt.Sprintf("%s %s\n", console.Colorize("InfoFail", dot), console.Colorize("PrintB", u.Addr))
msg += fmt.Sprintf(" Uptime: %s\n", console.Colorize("InfoFail", "offline"))
e := u.Err
if strings.Trim(e, " ") == "rpc: retry error" {
e = "unreachable"
}
msg += fmt.Sprintf(" Error: %s", console.Colorize("InfoFail", e))
return
}
// Print server title
msg += fmt.Sprintf("%s %s\n", console.Colorize("Info", dot), console.Colorize("PrintB", u.Addr))
// Uptime
msg += fmt.Sprintf(" Uptime: %s\n", console.Colorize("Info",
humanize.RelTime(time.Now(), time.Now().Add(-u.ServerInfo.Properties.Uptime), "", "")))
// Version
version := u.ServerInfo.Properties.Version
if u.ServerInfo.Properties.Version == "DEVELOPMENT.GOGET" {
version = "<development>"
}
msg += fmt.Sprintf(" Version: %s\n", version)
// Region
if u.ServerInfo.Properties.Region != "" {
msg += fmt.Sprintf(" Region: %s\n", u.ServerInfo.Properties.Region)
}
// ARNs
sqsARNs := ""
for _, v := range u.ServerInfo.Properties.SQSARN {
sqsARNs += fmt.Sprintf("%s ", v)
}
if sqsARNs != "" {
msg += fmt.Sprintf(" SQS ARNs: %s\n", sqsARNs)
}
// Incoming/outgoing
msg += fmt.Sprintf(" Storage: Used %s, Free %s",
humanize.IBytes(u.StorageInfo.Used),
humanize.IBytes(u.StorageInfo.Available))
if v, ok := u.StorageInfo.Backend.(xlBackend); ok {
upBackends := 0
downBackends := 0
for _, set := range v.Sets {
for _, s := range set {
if len(s.Endpoint) > 0 && (strings.Contains(s.Endpoint, u.Addr) || s.Endpoint[0] == '/' || s.Endpoint[0] == '.') {
if s.State == "ok" {
upBackends++
} else {
downBackends++
}
}
}
}
upBackendsString := fmt.Sprintf("%d", upBackends)
if downBackends != 0 {
upBackendsString = console.Colorize("InfoFail", fmt.Sprintf("%d", upBackends))
}
msg += fmt.Sprintf("\n Drives: %s/%d %s\n", upBackendsString,
upBackends+downBackends, console.Colorize("Info", "OK"))
msg += "\n"
//CPU section
msg += fmt.Sprintf("%s min avg max\n", console.Colorize("Info", " CPU"))
for i := range u.CPULoad.Load {
msg += fmt.Sprintf(" current %.2f%% %.2f%% %.2f%%\n", u.CPULoad.Load[i].Min, u.CPULoad.Load[i].Avg, u.CPULoad.Load[i].Max)
if len(u.CPULoad.HistoricLoad) > i {
msg += fmt.Sprintf(" historic %.2f%% %.2f%% %.2f%%\n", u.CPULoad.HistoricLoad[i].Min, u.CPULoad.HistoricLoad[i].Avg, u.CPULoad.HistoricLoad[i].Max)
}
msg += "\n"
}
// Mem section
msg += fmt.Sprintf("%s usage\n", console.Colorize("Info", " MEM"))
for i := range u.MemUsage.Usage {
msg += fmt.Sprintf(" current %s\n", humanize.IBytes(u.MemUsage.Usage[i].Mem))
if len(u.MemUsage.HistoricUsage) > i {
msg += fmt.Sprintf(" historic %s\n", humanize.IBytes(u.MemUsage.HistoricUsage[i].Mem))
}
msg += "\n"
}
}
return
}
// JSON jsonified service status message.
func (u infoMessage) JSON() string {
u.Status = "success"
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
return string(statusJSONBytes)
}
// checkAdminInfoSyntax - validate all the passed arguments
func checkAdminServerInfoSyntax(ctx *cli.Context) {
if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
cli.ShowCommandHelpAndExit(ctx, "server", 1) // last argument is exit code
}
}
func mainAdminServerInfo(ctx *cli.Context) error {
checkAdminServerInfoSyntax(ctx)
console.SetColor("Info", color.New(color.FgGreen, color.Bold))
console.SetColor("InfoDegraded", color.New(color.FgYellow, color.Bold))
console.SetColor("InfoFail", color.New(color.FgRed, color.Bold))
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
// Create a new MinIO Admin Client
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")
printOfflineErrorMessage := func(err error) {
errMsg := ""
if err != nil {
errMsg = err.Error()
}
printMsg(infoMessage{
Addr: aliasedURL,
Service: "off",
Err: errMsg,
})
}
processErr := func(e error) error {
switch e.(type) {
case *json.SyntaxError:
printOfflineErrorMessage(e)
return e
case *url.Error:
printOfflineErrorMessage(e)
return e
default:
// If the error is not nil and unrecognized, just print it and exit
fatalIf(probe.NewError(e), "Cannot get service status.")
}
return nil
}
// Fetch info of all servers (cluster or single server)
serversInfo, e := client.ServerInfo()
if err := processErr(e); err != nil {
// exit immediately if error encountered
return nil
}
// Fetch storage info of all servers (cluster or single server)
storageInfo, e := client.StorageInfo()
if err := processErr(e); err != nil {
// exit immediately if error encountered
return nil
}
// Fetch info of all CPU loads (all MinIO server instances)
cpuLoads, e := client.ServerCPULoadInfo()
if err := processErr(e); err != nil {
// exit immediately if error encountered
return nil
}
memUsages, e := client.ServerMemUsageInfo()
if err := processErr(e); err != nil {
// exit immediately if error encountered
return nil
}
infoMessages := []infoMessage{}
// Checks if the corresponding mountPath is found for the the given nodeAddr.
foundMatchingPath := func(mountPath, nodeAddr string) bool {
// NOTE: XL/FS mountpaths will have `/` as the first character denoting the absolute disk path.
return strings.Contains(mountPath, nodeAddr) || mountPath[0] == '/' || nodeAddr[0] == '/' || nodeAddr[0] == '.'
}
for i, serverInfo := range serversInfo {
cpuLoad := cpuLoads[i]
memUsage := memUsages[i]
// Print the error if exists and jump to the next server
if serverInfo.Error != "" {
infoMessages = append(infoMessages, infoMessage{
Service: "on",
Addr: serverInfo.Addr,
Err: serverInfo.Error,
})
continue
}
// Construct the backend status
storageInfoStat := backendStatus{}
for index, mountPath := range storageInfo.MountPaths {
if foundMatchingPath(mountPath, serverInfo.Addr) {
storageInfoStat.Used += storageInfo.Used[index]
storageInfoStat.Available += storageInfo.Available[index]
storageInfoStat.Total += storageInfo.Total[index]
}
}
if storageInfo.Backend.Type == madmin.Erasure {
storageInfoStat.Backend = xlBackend{
Type: erasureType,
OnlineDisks: filterPerNode(serverInfo.Addr, storageInfo.Backend.OnlineDisks),
OfflineDisks: filterPerNode(serverInfo.Addr, storageInfo.Backend.OfflineDisks),
StandardSCData: storageInfo.Backend.StandardSCData,
StandardSCParity: storageInfo.Backend.StandardSCParity,
RRSCData: storageInfo.Backend.RRSCData,
RRSCParity: storageInfo.Backend.RRSCParity,
Sets: storageInfo.Backend.Sets,
}
} else {
storageInfoStat.Backend = fsBackend{
Type: fsType,
}
}
infoMessages = append(infoMessages, (infoMessage{
Service: "on",
Addr: serverInfo.Addr,
Err: serverInfo.Error,
ServerInfo: &ServerInfo{
ConnStats: serverInfo.Data.ConnStats,
Properties: serverInfo.Data.Properties,
CPULoad: cpuLoad,
MemUsage: memUsage,
},
StorageInfo: storageInfoStat,
}))
}
sort.Sort(&sortInfoWrapper{infoMessages})
for _, s := range infoMessages {
printMsg(s)
}
return nil
}
type sortInfoWrapper struct {
infos []infoMessage
}
func (s *sortInfoWrapper) Len() int {
return len(s.infos)
}
func (s *sortInfoWrapper) Swap(i, j int) {
if s.infos != nil {
s.infos[i], s.infos[j] = s.infos[j], s.infos[i]
}
}
func (s *sortInfoWrapper) Less(i, j int) bool {
if s.infos != nil {
return s.infos[i].Addr < s.infos[j].Addr
}
return false
}
+197 -9
View File
@@ -17,7 +17,20 @@
package cmd
import (
"errors"
"fmt"
"reflect"
"strconv"
"time"
humanize "github.com/dustin/go-humanize"
"github.com/dustin/go-humanize/english"
"github.com/fatih/color"
"github.com/minio/cli"
json "github.com/minio/mc/pkg/colorjson"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/pkg/probe"
"github.com/minio/minio/pkg/madmin"
)
var adminInfoCmd = cli.Command{
@@ -26,17 +39,192 @@ var adminInfoCmd = cli.Command{
Action: mainAdminInfo,
Before: setGlobalsFromContext,
Flags: globalFlags,
Subcommands: []cli.Command{
adminInfoServer,
adminInfoCPU,
adminInfoMem,
},
HideHelpCommand: true,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Get server information of the 'play' MinIO server.
{{.Prompt}} {{.HelpName}} play/
`,
}
// mainAdminConfig is the handle for "mc admin config" command.
// Wrap "Info" message together with fields "Status" and "Error"
type clusterStruct struct {
Status string `json:"status"`
Error string `json:"error,omitempty"`
Info madmin.InfoMessage `json:"info,omitempty"`
}
// String provides colorized info messages.
func (u clusterStruct) String() (msg string) {
// If nothing has been collected, error out
if u.Info.Servers == nil {
fatal(probe.NewError(errors.New("Cannot get service status")), "")
}
// Initialization
var totalOnlineDisksCluster int
var totalOfflineDisksCluster int
// Dot represents server status, online (green) or offline (red)
dot := "●"
// Color palette initialization
console.SetColor("Info", color.New(color.FgGreen, color.Bold))
console.SetColor("InfoFail", color.New(color.FgRed, color.Bold))
// MinIO server type default
backendType := "Unknown"
// Loop through each server and put together info for each one
for _, srv := range u.Info.Servers {
// Check if MinIO server is offline ("Mode" field),
// If offline, error out
if u.Info.Mode == "offline" {
// "PrintB" is color blue in console library package
msg += fmt.Sprintf("%s %s\n", console.Colorize("InfoFail", dot), console.Colorize("PrintB", srv.Endpoint))
msg += fmt.Sprintf(" Uptime: %s\n", console.Colorize("InfoFail", "offline"))
return
}
// Check cluster level "Status" field for error
if u.Status == "error" {
fatal(probe.NewError(errors.New(u.Error)), "Cannot get service status")
}
// Set the type of MinIO server ("FS", "Erasure", "Unknown")
v := reflect.ValueOf(u.Info.Backend)
if v.Kind() == reflect.Map {
for _, key := range v.MapKeys() {
val := v.MapIndex(key)
switch t := val.Interface().(type) {
case string:
backendType = t
}
}
}
// Print server title
msg += fmt.Sprintf("%s %s\n", console.Colorize("Info", dot), console.Colorize("PrintB", srv.Endpoint))
// Uptime
msg += fmt.Sprintf(" Uptime: %s\n", console.Colorize("Info",
humanize.RelTime(time.Now(), time.Now().Add(time.Duration(srv.Uptime)*time.Second), "", "")))
// Version
version := srv.Version
if srv.Version == "DEVELOPMENT.GOGET" {
version = "<development>"
}
msg += fmt.Sprintf(" Version: %s\n", version)
// Network info, only available for non-FS types
var connectionAlive int
totalNodes := strconv.Itoa(len(srv.Network))
if srv.Network != nil {
for _, v := range srv.Network {
if v == "online" {
connectionAlive++
}
}
displayNwInfo := strconv.Itoa(connectionAlive) + "/" + totalNodes
msg += fmt.Sprintf(" Network: %s %s\n", displayNwInfo, console.Colorize("Info", "OK "))
}
// Choose and display information depending on the type of a server
// FS server non-FS server
// ============================== ===================================
// ● <ip>:<port> ● <ip>:<port>
// Uptime: xxx Uptime: xxx
// Version: xxx Version: xxx
// Network: X/Y OK Network: X/Y OK
//
// U Used, B Buckets, O Objects Drives: N/N OK
//
// U Used, B Buckets, O Objects
// N drives online, K drives offline
//
if backendType != "FS" {
// Info about drives on a server, only available for non-FS types
var OffDisks int
var OnDisks int
var dispNoOfDisks string
for _, disk := range srv.Disks {
if disk.State == "ok" {
OnDisks++
} else {
OffDisks++
}
}
totalDisksPerServer := OnDisks + OffDisks
totalOnlineDisksCluster += OnDisks
totalOfflineDisksCluster += OffDisks
dispNoOfDisks = strconv.Itoa(OnDisks) + "/" + strconv.Itoa(totalDisksPerServer)
msg += fmt.Sprintf(" Drives: %s %s\n", dispNoOfDisks, console.Colorize("Info", "OK "))
}
msg += "\n"
}
// Summary on used space, total no of buckets and
// total no of objects at the Cluster level
usedTotal := humanize.IBytes(uint64(u.Info.Usage.Size))
msg += fmt.Sprintf("%s Used, %s, %s", usedTotal,
english.Plural(u.Info.Buckets.Count, "Bucket", ""),
english.Plural(u.Info.Objects.Count, "Object", ""))
if backendType != "FS" {
// Summary on total no of online and total
// number of offline disks at the Cluster level
msg += fmt.Sprintf("\n%s online, %s offline",
english.Plural(totalOnlineDisksCluster, "drive", ""),
english.Plural(totalOfflineDisksCluster, "drive", ""))
}
return
}
// JSON jsonifies service status message.
func (u clusterStruct) JSON() string {
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
return string(statusJSONBytes)
}
// checkAdminInfoSyntax - validate arguments passed by a user
func checkAdminInfoSyntax(ctx *cli.Context) {
if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
cli.ShowCommandHelpAndExit(ctx, "info", 1) // last argument is exit code
}
}
func mainAdminInfo(ctx *cli.Context) error {
cli.ShowCommandHelp(ctx, ctx.Args().First())
checkAdminInfoSyntax(ctx)
// Get the alias parameter from cli
args := ctx.Args()
aliasedURL := args.Get(0)
// Create a new MinIO Admin Client
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")
var clusterInfo clusterStruct
// Fetch info of all servers (cluster or single server)
admInfo, e := client.ServerInfo()
if e != nil {
clusterInfo.Status = "error"
clusterInfo.Error = e.Error()
} else {
clusterInfo.Status = "success"
clusterInfo.Error = ""
}
clusterInfo.Info = admInfo
printMsg(clusterStruct(clusterInfo))
return nil
// Sub-commands like "server", "cpu", "mem" have their own main.
}
+1 -1
View File
@@ -15,7 +15,7 @@ require (
github.com/mattn/go-isatty v0.0.7
github.com/mattn/go-runewidth v0.0.5 // indirect
github.com/minio/cli v1.22.0
github.com/minio/minio v0.0.0-20191205124742-d8e3de0cae46
github.com/minio/minio v0.0.0-20191212015602-d266b3a06604
github.com/minio/minio-go/v6 v6.0.45-0.20191209092716-97b0a62ed75d
github.com/minio/sha256-simd v0.1.1
github.com/mitchellh/go-homedir v1.1.0
+16
View File
@@ -33,6 +33,8 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8
github.com/SAP/go-hdb v0.14.0/go.mod h1:7fdQLVC2lER3urZLjZCm0AuMQfApof92n3aylBPEkMo=
github.com/SermoDigital/jose v0.9.1/go.mod h1:ARgCUhI1MHQH+ONky/PAtmVHQrP5JlGY0F3poXOp/fA=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/sarama v1.24.1 h1:svn9vfN3R1Hz21WR2Gj0VW9ehaDGkiOS+VqlIcZOkMI=
github.com/Shopify/sarama v1.24.1/go.mod h1:fGP8eQ6PugKEI0iUETYYtnP6d1pH/bdDMTel1X5ajsU=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
@@ -149,6 +151,8 @@ github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/frankban/quicktest v1.4.1/go.mod h1:36zfPVQyHxymz4cH7wlDmVwDrJuljRB60qkgn7rorfQ=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fullsailor/pkcs7 v0.0.0-20180613152042-8306686428a5/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA=
github.com/gammazero/deque v0.0.0-20190130191400-2afb3858e9c7/go.mod h1:GeIq9qoE43YdGnDXURnmKTnGg15pQz4mYkXSTChbneI=
@@ -203,6 +207,7 @@ github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
@@ -350,6 +355,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/klauspost/compress v1.3.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.5.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.8.3 h1:CkLseiEYMM/fRb0RIg9mXB+Iwgmle+U9KGFu+JCO4Ec=
github.com/klauspost/compress v1.8.3/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.8.3/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
@@ -443,6 +449,8 @@ github.com/minio/minio v0.0.0-20190927193314-1c5b05c130fa/go.mod h1:47wx8w7yKTFA
github.com/minio/minio v0.0.0-20191001201215-ff5bf519522f/go.mod h1:+vpJpzImdz4NCQto3r6/vF/24jWeEs5i3lsDfRmEcl4=
github.com/minio/minio v0.0.0-20191205124742-d8e3de0cae46 h1:6Oyny/iVD88fCrp3g4WbBjQJRdnzPZZO8aYI8tdONkY=
github.com/minio/minio v0.0.0-20191205124742-d8e3de0cae46/go.mod h1:3bY3lz9Uby83qOp5RsnPu4JJwiskVK088E7F4CRSdxI=
github.com/minio/minio v0.0.0-20191212015602-d266b3a06604 h1:yAGvlmBRoK2F0xcAsQZ/yVd/gX/ZJHMX1xNXSPKskiM=
github.com/minio/minio v0.0.0-20191212015602-d266b3a06604/go.mod h1:KL1MXxEmFjP6z0Sj4810GLRW9X01wrnQoIQCtFRl4PM=
github.com/minio/minio-go v0.0.0-20190227180923-59af836a7e6d h1:gptD0/Hnam7h4Iq9D/33fscRpHfzOOUqUbH2nPw9HcU=
github.com/minio/minio-go v0.0.0-20190227180923-59af836a7e6d/go.mod h1:/haSOWG8hQNx2+JOfLJ9GKp61EAmgPwRVw/Sac0NzaM=
github.com/minio/minio-go v0.0.0-20190313212832-5d20267d970d/go.mod h1:/haSOWG8hQNx2+JOfLJ9GKp61EAmgPwRVw/Sac0NzaM=
@@ -551,6 +559,8 @@ github.com/pborman/getopt v0.0.0-20180729010549-6fdd0a2c7117/go.mod h1:85jBQOZwp
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pierrec/lz4 v2.2.6+incompatible h1:6aCX4/YZ9v8q69hTyiR7dNLnTA3fgtKHVVW5BCd5Znw=
github.com/pierrec/lz4 v2.2.6+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -671,6 +681,8 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY
github.com/valyala/fastjson v1.4.1/go.mod h1:nV6MsjxL2IMJQUoHDIrjEI7oLyeqK6aBD7EFWPsvP8o=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a h1:0R4NLDRDZX6JcmhJgXi5E4b8Wg84ihbmUKp/GvSPEzc=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
@@ -710,6 +722,7 @@ golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo=
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -785,6 +798,7 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190304154630-e844e0132e93/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190318195719-6c81ef8f67ca/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -885,6 +899,8 @@ gopkg.in/jcmturner/goidentity.v3 v3.0.0 h1:1duIyWiTaYvVx3YX2CYtpJbUFd7/UuPYCfgXt
gopkg.in/jcmturner/goidentity.v3 v3.0.0/go.mod h1:oG2kH0IvSYNIu80dVAyu/yoefjq1mNfM5bm88whjWx4=
gopkg.in/jcmturner/goidentity.v3 v3.0.0/go.mod h1:oG2kH0IvSYNIu80dVAyu/yoefjq1mNfM5bm88whjWx4=
gopkg.in/jcmturner/gokrb5.v5 v5.3.0/go.mod h1:oQz8Wc5GsctOTgCVyKad1Vw4TCWz5G6gfIQr88RPv4k=
gopkg.in/jcmturner/gokrb5.v7 v7.2.3 h1:hHMV/yKPwMnJhPuPx7pH2Uw/3Qyf+thJYlisUc44010=
gopkg.in/jcmturner/gokrb5.v7 v7.2.3/go.mod h1:l8VISx+WGYp+Fp7KRbsiUuXTTOnxIc3Tuvyavf11/WM=
gopkg.in/jcmturner/rpc.v0 v0.0.2/go.mod h1:NzMq6cRzR9lipgw7WxRBHNx5N8SifBuaCQsOT1kWY/E=
gopkg.in/jcmturner/rpc.v1 v1.1.0 h1:QHIUxTX1ISuAv9dD2wJ9HWQVuWDX/Zc0PfeC2tjc4rU=
gopkg.in/jcmturner/rpc.v1 v1.1.0/go.mod h1:YIdkC4XfD6GXbzje11McwsDuOlZQSb9W4vfLvuNnlv8=