diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 2814b569f..1e1f46b89 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -1776,7 +1776,43 @@ func (a adminAPIHandlers) KMSKeyStatusHandler(w http.ResponseWriter, r *http.Req writeSuccessResponseJSON(w, resp) } -func getServerInfo(ctx context.Context, r *http.Request) madmin.InfoMessage { +func getPoolsInfo(ctx context.Context, allDisks []madmin.Disk) (map[int]map[int]madmin.ErasureSetInfo, error) { + objectAPI := newObjectLayerFn() + if objectAPI == nil { + return nil, errServerNotInitialized + } + + z, _ := objectAPI.(*erasureServerPools) + + poolsInfo := make(map[int]map[int]madmin.ErasureSetInfo) + for _, d := range allDisks { + poolInfo, ok := poolsInfo[d.PoolIndex] + if !ok { + poolInfo = make(map[int]madmin.ErasureSetInfo) + } + erasureSet, ok := poolInfo[d.SetIndex] + if !ok { + erasureSet.ID = d.SetIndex + cache := dataUsageCache{} + if err := cache.load(ctx, z.serverPools[d.PoolIndex].sets[d.SetIndex], dataUsageCacheName); err == nil { + dataUsageInfo := cache.dui(dataUsageRoot, nil) + erasureSet.ObjectsCount = dataUsageInfo.ObjectsTotalCount + erasureSet.VersionsCount = dataUsageInfo.VersionsTotalCount + erasureSet.Usage = dataUsageInfo.ObjectsTotalSize + } + } + erasureSet.RawCapacity += d.TotalSpace + erasureSet.RawUsage += d.UsedSpace + if d.Healing { + erasureSet.HealDisks = 1 + } + poolInfo[d.SetIndex] = erasureSet + poolsInfo[d.PoolIndex] = poolInfo + } + return poolsInfo, nil +} + +func getServerInfo(ctx context.Context, poolsInfoEnabled bool, r *http.Request) madmin.InfoMessage { kmsStat := fetchKMSStatus() ldap := madmin.LDAP{} @@ -1805,7 +1841,9 @@ func getServerInfo(ctx context.Context, r *http.Request) madmin.InfoMessage { assignPoolNumbers(servers) + var poolsInfo map[int]map[int]madmin.ErasureSetInfo var backend interface{} + mode := madmin.ItemInitializing buckets := madmin.Buckets{} @@ -1832,25 +1870,23 @@ func getServerInfo(ctx context.Context, r *http.Request) madmin.InfoMessage { // Fetching the backend information backendInfo := objectAPI.BackendInfo() - if backendInfo.Type == madmin.Erasure { - // Calculate the number of online/offline disks of all nodes - var allDisks []madmin.Disk - for _, s := range servers { - allDisks = append(allDisks, s.Disks...) - } - onlineDisks, offlineDisks := getOnlineOfflineDisksStats(allDisks) + // Calculate the number of online/offline disks of all nodes + var allDisks []madmin.Disk + for _, s := range servers { + allDisks = append(allDisks, s.Disks...) + } + onlineDisks, offlineDisks := getOnlineOfflineDisksStats(allDisks) - backend = madmin.ErasureBackend{ - Type: madmin.ErasureType, - OnlineDisks: onlineDisks.Sum(), - OfflineDisks: offlineDisks.Sum(), - StandardSCParity: backendInfo.StandardSCParity, - RRSCParity: backendInfo.RRSCParity, - } - } else { - backend = madmin.FSBackend{ - Type: madmin.FsType, - } + backend = madmin.ErasureBackend{ + Type: madmin.ErasureType, + OnlineDisks: onlineDisks.Sum(), + OfflineDisks: offlineDisks.Sum(), + StandardSCParity: backendInfo.StandardSCParity, + RRSCParity: backendInfo.RRSCParity, + } + + if poolsInfoEnabled { + poolsInfo, _ = getPoolsInfo(ctx, allDisks) } } @@ -1876,6 +1912,7 @@ func getServerInfo(ctx context.Context, r *http.Request) madmin.InfoMessage { Services: services, Backend: backend, Servers: servers, + Pools: poolsInfo, } } @@ -2182,7 +2219,7 @@ func fetchHealthInfo(healthCtx context.Context, objectAPI ObjectLayer, query *ur getAndWriteSysConfig() if query.Get("minioinfo") == "true" { - infoMessage := getServerInfo(healthCtx, nil) + infoMessage := getServerInfo(healthCtx, false, nil) servers := make([]madmin.ServerInfo, 0, len(infoMessage.Servers)) for _, server := range infoMessage.Servers { anonEndpoint := anonAddr(server.Endpoint) @@ -2357,7 +2394,7 @@ func (a adminAPIHandlers) ServerInfoHandler(w http.ResponseWriter, r *http.Reque } // Marshal API response - jsonBytes, err := json.Marshal(getServerInfo(ctx, r)) + jsonBytes, err := json.Marshal(getServerInfo(ctx, true, r)) if err != nil { writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL) return diff --git a/go.mod b/go.mod index 1fc88b2cd..d154e4131 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( github.com/minio/dperf v0.4.2 github.com/minio/highwayhash v1.0.2 github.com/minio/kes v0.22.3 - github.com/minio/madmin-go/v2 v2.0.9 + github.com/minio/madmin-go/v2 v2.0.11 github.com/minio/minio-go/v7 v7.0.47 github.com/minio/mux v1.9.0 github.com/minio/pkg v1.6.1 diff --git a/go.sum b/go.sum index 2a3a6b544..43e97ae0c 100644 --- a/go.sum +++ b/go.sum @@ -775,8 +775,8 @@ github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLT github.com/minio/kes v0.22.3 h1:aSPW9uCMVaLax5POxvoQJxCU4MNo/KzMXA7WfmC/lRw= github.com/minio/kes v0.22.3/go.mod h1:wnhmdwWX2rpurNPKn3yDFImg2wuc7j3e+IU5rVkR9UY= github.com/minio/madmin-go v1.6.6/go.mod h1:ATvkBOLiP3av4D++2v1UEHC/QzsGtgXD5kYvvRYzdKs= -github.com/minio/madmin-go/v2 v2.0.9 h1:wv1e4ZTH1L1SaHs/jaI3uW2AHYQw77T2hgarfPo1j3U= -github.com/minio/madmin-go/v2 v2.0.9/go.mod h1:5aFi/VLWBHC2DEFfGIlUmAeJhaF4ZAjuYpEWZFU14Zw= +github.com/minio/madmin-go/v2 v2.0.11 h1:Ct905UAMJ43EAwKCi8xy5PzWPWyYL5YCQ441E9LYXTA= +github.com/minio/madmin-go/v2 v2.0.11/go.mod h1:5aFi/VLWBHC2DEFfGIlUmAeJhaF4ZAjuYpEWZFU14Zw= github.com/minio/mc v0.0.0-20230203133213-3aebb3362b18 h1:Di71Ums7dD5vA3VK/loOqb/QttQjvCV/1/DF77w1XqA= github.com/minio/mc v0.0.0-20230203133213-3aebb3362b18/go.mod h1:j3BgTu1LshBzna9Wf8il7WAyw9IQabMu+EcrDUaNZ2k= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=