github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/metrics/machine_account.go (about)

     1  package metrics
     2  
     3  import (
     4  	"github.com/onflow/flow-go/model/flow"
     5  
     6  	"github.com/prometheus/client_golang/prometheus"
     7  )
     8  
     9  // MachineAccountCollector implements metric collection for machine accounts.
    10  type MachineAccountCollector struct {
    11  	accountBalance        prometheus.Gauge
    12  	recommendedMinBalance prometheus.Gauge
    13  	misconfigured         prometheus.Gauge
    14  }
    15  
    16  func NewMachineAccountCollector(registerer prometheus.Registerer, machineAccountAddress flow.Address) *MachineAccountCollector {
    17  	accountBalance := prometheus.NewGauge(prometheus.GaugeOpts{
    18  		Namespace:   namespaceMachineAcct,
    19  		Name:        "balance",
    20  		Help:        "the last observed balance of this node's machine account, in units of FLOW",
    21  		ConstLabels: map[string]string{LabelAccountAddress: machineAccountAddress.String()},
    22  	})
    23  	recommendedMinBalance := prometheus.NewGauge(prometheus.GaugeOpts{
    24  		Namespace:   namespaceMachineAcct,
    25  		Name:        "recommended_min_balance",
    26  		Help:        "the recommended minimum balance for this node role; refill the account when the balance reaches this threshold",
    27  		ConstLabels: map[string]string{LabelAccountAddress: machineAccountAddress.String()},
    28  	})
    29  	misconfigured := prometheus.NewGauge(prometheus.GaugeOpts{
    30  		Namespace:   namespaceMachineAcct,
    31  		Name:        "is_misconfigured",
    32  		Help:        "reported as a non-zero value when a misconfiguration is detected; check logs for further details",
    33  		ConstLabels: map[string]string{LabelAccountAddress: machineAccountAddress.String()},
    34  	})
    35  	registerer.MustRegister(accountBalance, recommendedMinBalance, misconfigured)
    36  
    37  	collector := &MachineAccountCollector{
    38  		accountBalance:        accountBalance,
    39  		recommendedMinBalance: recommendedMinBalance,
    40  		misconfigured:         misconfigured,
    41  	}
    42  	return collector
    43  }
    44  
    45  func (m MachineAccountCollector) AccountBalance(bal float64) {
    46  	m.accountBalance.Set(bal)
    47  }
    48  
    49  func (m MachineAccountCollector) RecommendedMinBalance(bal float64) {
    50  	m.recommendedMinBalance.Set(bal)
    51  }
    52  
    53  func (m MachineAccountCollector) IsMisconfigured(misconfigured bool) {
    54  	if misconfigured {
    55  		m.misconfigured.Set(1)
    56  	} else {
    57  		m.misconfigured.Set(0)
    58  	}
    59  }