From 80aecfddff835b410d8cfb7f00bc898a67b3f642 Mon Sep 17 00:00:00 2001 From: Praveen raj Mani Date: Wed, 23 Oct 2019 21:17:38 +0530 Subject: [PATCH] Adapt new changes in StorageInfo (#2889) --- cmd/admin-info-server.go | 77 +++++++++++++++++++++++++--------------- go.mod | 2 +- go.sum | 4 +-- 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/cmd/admin-info-server.go b/cmd/admin-info-server.go index 683b1af6..188b3719 100644 --- a/cmd/admin-info-server.go +++ b/cmd/admin-info-server.go @@ -99,22 +99,29 @@ type backendStatus struct { // ServerInfo holds the whole server information that will be // returned by ServerInfo API. type ServerInfo struct { - StorageInfo backendStatus `json:"storage"` - ConnStats madmin.ServerConnStats `json:"network"` - Properties madmin.ServerProperties `json:"server"` - CPULoad madmin.ServerCPULoadInfo `json:"cpu,omitempty"` - MemUsage madmin.ServerMemUsageInfo `json:"mem,omitempty"` + 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"` + 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 := "●" @@ -168,7 +175,7 @@ func (u infoMessage) String() (msg string) { msg += fmt.Sprintf(" Storage: Used %s, Free %s", humanize.IBytes(u.StorageInfo.Used), humanize.IBytes(u.StorageInfo.Available)) - if v, ok := u.ServerInfo.StorageInfo.Backend.(xlBackend); ok { + if v, ok := u.StorageInfo.Backend.(xlBackend); ok { upBackends := 0 downBackends := 0 for _, set := range v.Sets { @@ -278,6 +285,14 @@ func mainAdminServerInfo(ctx *cli.Context) error { // 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() @@ -309,25 +324,29 @@ func mainAdminServerInfo(ctx *cli.Context) error { } // Construct the backend status - storageInfo := backendStatus{ - Used: serverInfo.Data.StorageInfo.Used, - Available: serverInfo.Data.StorageInfo.Available, - Total: serverInfo.Data.StorageInfo.Total, + storageInfoStat := backendStatus{} + + for index, mountPath := range storageInfo.MountPaths { + if strings.Contains(mountPath, serverInfo.Addr) || serverInfo.Addr[0] == '/' || serverInfo.Addr[0] == '.' { + storageInfoStat.Used += storageInfo.Used[index] + storageInfoStat.Available += storageInfo.Available[index] + storageInfoStat.Total += storageInfo.Total[index] + } } - if serverInfo.Data.StorageInfo.Backend.Type == madmin.Erasure { - storageInfo.Backend = xlBackend{ + if storageInfo.Backend.Type == madmin.Erasure { + storageInfoStat.Backend = xlBackend{ Type: erasureType, - OnlineDisks: serverInfo.Data.StorageInfo.Backend.OnlineDisks, - OfflineDisks: serverInfo.Data.StorageInfo.Backend.OfflineDisks, - StandardSCData: serverInfo.Data.StorageInfo.Backend.StandardSCData, - StandardSCParity: serverInfo.Data.StorageInfo.Backend.StandardSCParity, - RRSCData: serverInfo.Data.StorageInfo.Backend.RRSCData, - RRSCParity: serverInfo.Data.StorageInfo.Backend.RRSCParity, - Sets: serverInfo.Data.StorageInfo.Backend.Sets, + 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 { - storageInfo.Backend = fsBackend{ + storageInfoStat.Backend = fsBackend{ Type: fsType, } } @@ -337,12 +356,12 @@ func mainAdminServerInfo(ctx *cli.Context) error { Addr: serverInfo.Addr, Err: serverInfo.Error, ServerInfo: &ServerInfo{ - StorageInfo: storageInfo, - ConnStats: serverInfo.Data.ConnStats, - Properties: serverInfo.Data.Properties, - CPULoad: cpuLoad, - MemUsage: memUsage, + ConnStats: serverInfo.Data.ConnStats, + Properties: serverInfo.Data.Properties, + CPULoad: cpuLoad, + MemUsage: memUsage, }, + StorageInfo: storageInfoStat, })) } diff --git a/go.mod b/go.mod index a4421185..cb294f62 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/mattn/go-colorable v0.1.1 github.com/mattn/go-isatty v0.0.7 github.com/minio/cli v1.22.0 - github.com/minio/minio v0.0.0-20191016175257-c4e2af8ca34d + github.com/minio/minio v0.0.0-20191023040114-8836d57e3c9d github.com/minio/minio-go/v6 v6.0.39 github.com/minio/sha256-simd v0.1.1 github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index 1af233a6..ba1bd6e2 100644 --- a/go.sum +++ b/go.sum @@ -430,8 +430,8 @@ github.com/minio/minio v0.0.0-20190325204105-0250f7de678b/go.mod h1:6ODmvb06uOpN github.com/minio/minio v0.0.0-20190510004154-ac3b59645e92/go.mod h1:yFbQSwuA61mB/SDurPvsaSydqDyJdfAlBYpMiEe1lz8= github.com/minio/minio v0.0.0-20190903181048-8a71b0ec5a72 h1:TMytDyYdKnVxNJhkISFRsw9SVoHIlSMIJFk3y/l9nik= github.com/minio/minio v0.0.0-20190903181048-8a71b0ec5a72/go.mod h1:H8OUaOxwJIALXHlfMpk2ESvk81dW+F7tSnrZi7rln/k= -github.com/minio/minio v0.0.0-20191016175257-c4e2af8ca34d h1:UaKu+15Teg95H6vQ6A8YEa27GZJbaHwLlVNu/MHhn0o= -github.com/minio/minio v0.0.0-20191016175257-c4e2af8ca34d/go.mod h1:26iXReDUAl0TJD5d4OIUoccQKrdE2/Oie6XRPjZN5gk= +github.com/minio/minio v0.0.0-20191023040114-8836d57e3c9d h1:gNdVSSXBQFz7JnsZPy13HJKdXR1JLGKm6QMMhGDBZzg= +github.com/minio/minio v0.0.0-20191023040114-8836d57e3c9d/go.mod h1:26iXReDUAl0TJD5d4OIUoccQKrdE2/Oie6XRPjZN5gk= 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=