github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/metrics-v3-cluster-erasure-set.go (about)

     1  // Copyright (c) 2015-2024 MinIO, Inc.
     2  //
     3  // This file is part of MinIO Object Storage stack
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package cmd
    19  
    20  import (
    21  	"context"
    22  	"strconv"
    23  )
    24  
    25  const (
    26  	erasureSetOverallWriteQuorum = "overall_write_quorum"
    27  	erasureSetOverallHealth      = "overall_health"
    28  	erasureSetReadQuorum         = "read_quorum"
    29  	erasureSetWriteQuorum        = "write_quorum"
    30  	erasureSetOnlineDrivesCount  = "online_drives_count"
    31  	erasureSetHealingDrivesCount = "healing_drives_count"
    32  	erasureSetHealth             = "health"
    33  )
    34  
    35  const (
    36  	poolIDL = "pool_id"
    37  	setIDL  = "set_id"
    38  )
    39  
    40  var (
    41  	erasureSetOverallWriteQuorumMD = NewGaugeMD(erasureSetOverallWriteQuorum,
    42  		"Overall write quorum across pools and sets")
    43  	erasureSetOverallHealthMD = NewGaugeMD(erasureSetOverallHealth,
    44  		"Overall health across pools and sets (1=healthy, 0=unhealthy)")
    45  	erasureSetReadQuorumMD = NewGaugeMD(erasureSetReadQuorum,
    46  		"Read quorum for the erasure set in a pool", poolIDL, setIDL)
    47  	erasureSetWriteQuorumMD = NewGaugeMD(erasureSetWriteQuorum,
    48  		"Write quorum for the erasure set in a pool", poolIDL, setIDL)
    49  	erasureSetOnlineDrivesCountMD = NewGaugeMD(erasureSetOnlineDrivesCount,
    50  		"Count of online drives in the erasure set in a pool", poolIDL, setIDL)
    51  	erasureSetHealingDrivesCountMD = NewGaugeMD(erasureSetHealingDrivesCount,
    52  		"Count of healing drives in the erasure set in a pool", poolIDL, setIDL)
    53  	erasureSetHealthMD = NewGaugeMD(erasureSetHealth,
    54  		"Health of the erasure set in a pool (1=healthy, 0=unhealthy)",
    55  		poolIDL, setIDL)
    56  )
    57  
    58  func b2f(v bool) float64 {
    59  	if v {
    60  		return 1
    61  	}
    62  	return 0
    63  }
    64  
    65  // loadClusterErasureSetMetrics - `MetricsLoaderFn` for cluster storage erasure
    66  // set metrics.
    67  func loadClusterErasureSetMetrics(ctx context.Context, m MetricValues, c *metricsCache) error {
    68  	result, _ := c.esetHealthResult.Get()
    69  
    70  	m.Set(erasureSetOverallWriteQuorum, float64(result.WriteQuorum))
    71  	m.Set(erasureSetOverallHealth, b2f(result.Healthy))
    72  
    73  	for _, h := range result.ESHealth {
    74  		poolLV := strconv.Itoa(h.PoolID)
    75  		setLV := strconv.Itoa(h.SetID)
    76  		m.Set(erasureSetReadQuorum, float64(h.ReadQuorum),
    77  			poolIDL, poolLV, setIDL, setLV)
    78  		m.Set(erasureSetWriteQuorum, float64(h.WriteQuorum),
    79  			poolIDL, poolLV, setIDL, setLV)
    80  		m.Set(erasureSetOnlineDrivesCount, float64(h.HealthyDrives),
    81  			poolIDL, poolLV, setIDL, setLV)
    82  		m.Set(erasureSetHealingDrivesCount, float64(h.HealingDrives),
    83  			poolIDL, poolLV, setIDL, setLV)
    84  		m.Set(erasureSetHealth, b2f(h.Healthy),
    85  			poolIDL, poolLV, setIDL, setLV)
    86  	}
    87  
    88  	return nil
    89  }