storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/notification-summary.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2020 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   *
    16   */
    17  
    18  package cmd
    19  
    20  import (
    21  	"storj.io/minio/pkg/madmin"
    22  )
    23  
    24  // GetTotalCapacity gets the total capacity in the cluster.
    25  func GetTotalCapacity(diskInfo []madmin.Disk) (capacity uint64) {
    26  
    27  	for _, disk := range diskInfo {
    28  		capacity += disk.TotalSpace
    29  	}
    30  	return
    31  }
    32  
    33  // GetTotalUsableCapacity gets the total usable capacity in the cluster.
    34  // This value is not an accurate representation of total usable in a multi-tenant deployment.
    35  func GetTotalUsableCapacity(diskInfo []madmin.Disk, s StorageInfo) (capacity float64) {
    36  	raw := GetTotalCapacity(diskInfo)
    37  	var approxDataBlocks float64
    38  	var actualDisks float64
    39  	for _, scData := range s.Backend.StandardSCData {
    40  		approxDataBlocks += float64(scData)
    41  		actualDisks += float64(scData + s.Backend.StandardSCParity)
    42  	}
    43  	ratio := approxDataBlocks / actualDisks
    44  	return float64(raw) * ratio
    45  }
    46  
    47  // GetTotalCapacityFree gets the total capacity free in the cluster.
    48  func GetTotalCapacityFree(diskInfo []madmin.Disk) (capacity uint64) {
    49  	for _, d := range diskInfo {
    50  		capacity += d.AvailableSpace
    51  	}
    52  	return
    53  }
    54  
    55  // GetTotalUsableCapacityFree gets the total usable capacity free in the cluster.
    56  // This value is not an accurate representation of total free in a multi-tenant deployment.
    57  func GetTotalUsableCapacityFree(diskInfo []madmin.Disk, s StorageInfo) (capacity float64) {
    58  	raw := GetTotalCapacityFree(diskInfo)
    59  	var approxDataBlocks float64
    60  	var actualDisks float64
    61  	for _, scData := range s.Backend.StandardSCData {
    62  		approxDataBlocks += float64(scData)
    63  		actualDisks += float64(scData + s.Backend.StandardSCParity)
    64  	}
    65  	ratio := approxDataBlocks / actualDisks
    66  	return float64(raw) * ratio
    67  }