add total usable capacity, free and used to DataUsageInfo() (#18921)

This commit is contained in:
Harshavardhana 2024-01-30 17:49:37 -08:00 committed by GitHub
parent f25cbdf43c
commit 057192913c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View file

@ -796,7 +796,7 @@ func (a adminAPIHandlers) MetricsHandler(w http.ResponseWriter, r *http.Request)
} }
} }
// DataUsageInfoHandler - GET /minio/admin/v3/datausage // DataUsageInfoHandler - GET /minio/admin/v3/datausage?capacity={true}
// ---------- // ----------
// Get server/cluster data usage info // Get server/cluster data usage info
func (a adminAPIHandlers) DataUsageInfoHandler(w http.ResponseWriter, r *http.Request) { func (a adminAPIHandlers) DataUsageInfoHandler(w http.ResponseWriter, r *http.Request) {
@ -819,6 +819,16 @@ func (a adminAPIHandlers) DataUsageInfoHandler(w http.ResponseWriter, r *http.Re
return return
} }
// Get capacity info when asked.
if r.Form.Get("capacity") == "true" {
sinfo := objectAPI.StorageInfo(ctx, false)
dataUsageInfo.TotalCapacity = GetTotalUsableCapacity(sinfo.Disks, sinfo)
dataUsageInfo.TotalFreeCapacity = GetTotalUsableCapacityFree(sinfo.Disks, sinfo)
if dataUsageInfo.TotalCapacity > dataUsageInfo.TotalFreeCapacity {
dataUsageInfo.TotalUsedCapacity = dataUsageInfo.TotalCapacity - dataUsageInfo.TotalFreeCapacity
}
}
writeSuccessResponseJSON(w, dataUsageInfoJSON) writeSuccessResponseJSON(w, dataUsageInfoJSON)
} }
@ -1633,7 +1643,7 @@ func (a adminAPIHandlers) ObjectSpeedTestHandler(w http.ResponseWriter, r *http.
duration = time.Second * 10 duration = time.Second * 10
} }
storageInfo := objectAPI.StorageInfo(ctx, true) storageInfo := objectAPI.StorageInfo(ctx, false)
sufficientCapacity, canAutotune, capacityErrMsg := validateObjPerfOptions(ctx, storageInfo, concurrent, size, autotune) sufficientCapacity, canAutotune, capacityErrMsg := validateObjPerfOptions(ctx, storageInfo, concurrent, size, autotune)
if !sufficientCapacity { if !sufficientCapacity {
@ -3051,7 +3061,7 @@ func getClusterMetaInfo(ctx context.Context) []byte {
ci.Info.NoOfServers = totalNodeCount() ci.Info.NoOfServers = totalNodeCount()
ci.Info.MinioVersion = Version ci.Info.MinioVersion = Version
si := objectAPI.StorageInfo(ctx, true) si := objectAPI.StorageInfo(ctx, false)
ci.Info.NoOfDrives = len(si.Disks) ci.Info.NoOfDrives = len(si.Disks)
for _, disk := range si.Disks { for _, disk := range si.Disks {

View file

@ -71,6 +71,10 @@ type BucketUsageInfo struct {
// DataUsageInfo represents data usage stats of the underlying Object API // DataUsageInfo represents data usage stats of the underlying Object API
type DataUsageInfo struct { type DataUsageInfo struct {
TotalCapacity uint64 `json:"capacity,omitempty"`
TotalUsedCapacity uint64 `json:"usedCapacity,omitempty"`
TotalFreeCapacity uint64 `json:"freeCapacity,omitempty"`
// LastUpdate is the timestamp of when the data usage info was last updated. // LastUpdate is the timestamp of when the data usage info was last updated.
// This does not indicate a full scan. // This does not indicate a full scan.
LastUpdate time.Time `json:"lastUpdate"` LastUpdate time.Time `json:"lastUpdate"`
@ -87,6 +91,7 @@ type DataUsageInfo struct {
// Objects total size across all buckets // Objects total size across all buckets
ObjectsTotalSize uint64 `json:"objectsTotalSize"` ObjectsTotalSize uint64 `json:"objectsTotalSize"`
ReplicationInfo map[string]BucketTargetUsageInfo `json:"objectsReplicationInfo"` ReplicationInfo map[string]BucketTargetUsageInfo `json:"objectsReplicationInfo"`
// Total number of buckets in this cluster // Total number of buckets in this cluster
BucketsCount uint64 `json:"bucketsCount"` BucketsCount uint64 `json:"bucketsCount"`