github.com/true-sqn/fabric@v2.1.1+incompatible/orderer/consensus/etcdraft/metrics.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package etcdraft
     8  
     9  import "github.com/hyperledger/fabric/common/metrics"
    10  
    11  var (
    12  	clusterSizeOpts = metrics.GaugeOpts{
    13  		Namespace:    "consensus",
    14  		Subsystem:    "etcdraft",
    15  		Name:         "cluster_size",
    16  		Help:         "Number of nodes in this channel.",
    17  		LabelNames:   []string{"channel"},
    18  		StatsdFormat: "%{#fqname}.%{channel}",
    19  	}
    20  	isLeaderOpts = metrics.GaugeOpts{
    21  		Namespace:    "consensus",
    22  		Subsystem:    "etcdraft",
    23  		Name:         "is_leader",
    24  		Help:         "The leadership status of the current node: 1 if it is the leader else 0.",
    25  		LabelNames:   []string{"channel"},
    26  		StatsdFormat: "%{#fqname}.%{channel}",
    27  	}
    28  	ActiveNodesOpts = metrics.GaugeOpts{
    29  		Namespace:    "consensus",
    30  		Subsystem:    "etcdraft",
    31  		Name:         "active_nodes",
    32  		Help:         "Number of active nodes in this channel.",
    33  		LabelNames:   []string{"channel"},
    34  		StatsdFormat: "%{#fqname}.%{channel}",
    35  	}
    36  	committedBlockNumberOpts = metrics.GaugeOpts{
    37  		Namespace:    "consensus",
    38  		Subsystem:    "etcdraft",
    39  		Name:         "committed_block_number",
    40  		Help:         "The block number of the latest block committed.",
    41  		LabelNames:   []string{"channel"},
    42  		StatsdFormat: "%{#fqname}.%{channel}",
    43  	}
    44  	snapshotBlockNumberOpts = metrics.GaugeOpts{
    45  		Namespace:    "consensus",
    46  		Subsystem:    "etcdraft",
    47  		Name:         "snapshot_block_number",
    48  		Help:         "The block number of the latest snapshot.",
    49  		LabelNames:   []string{"channel"},
    50  		StatsdFormat: "%{#fqname}.%{channel}",
    51  	}
    52  	leaderChangesOpts = metrics.CounterOpts{
    53  		Namespace:    "consensus",
    54  		Subsystem:    "etcdraft",
    55  		Name:         "leader_changes",
    56  		Help:         "The number of leader changes since process start.",
    57  		LabelNames:   []string{"channel"},
    58  		StatsdFormat: "%{#fqname}.%{channel}",
    59  	}
    60  	proposalFailuresOpts = metrics.CounterOpts{
    61  		Namespace:    "consensus",
    62  		Subsystem:    "etcdraft",
    63  		Name:         "proposal_failures",
    64  		Help:         "The number of proposal failures.",
    65  		LabelNames:   []string{"channel"},
    66  		StatsdFormat: "%{#fqname}.%{channel}",
    67  	}
    68  	dataPersistDurationOpts = metrics.HistogramOpts{
    69  		Namespace:    "consensus",
    70  		Subsystem:    "etcdraft",
    71  		Name:         "data_persist_duration",
    72  		Help:         "The time taken for etcd/raft data to be persisted in storage (in seconds).",
    73  		LabelNames:   []string{"channel"},
    74  		StatsdFormat: "%{#fqname}.%{channel}",
    75  	}
    76  	normalProposalsReceivedOpts = metrics.CounterOpts{
    77  		Namespace:    "consensus",
    78  		Subsystem:    "etcdraft",
    79  		Name:         "normal_proposals_received",
    80  		Help:         "The total number of proposals received for normal type transactions.",
    81  		LabelNames:   []string{"channel"},
    82  		StatsdFormat: "%{#fqname}.%{channel}",
    83  	}
    84  	configProposalsReceivedOpts = metrics.CounterOpts{
    85  		Namespace:    "consensus",
    86  		Subsystem:    "etcdraft",
    87  		Name:         "config_proposals_received",
    88  		Help:         "The total number of proposals received for config type transactions.",
    89  		LabelNames:   []string{"channel"},
    90  		StatsdFormat: "%{#fqname}.%{channel}",
    91  	}
    92  )
    93  
    94  type Metrics struct {
    95  	ClusterSize             metrics.Gauge
    96  	IsLeader                metrics.Gauge
    97  	ActiveNodes             metrics.Gauge
    98  	CommittedBlockNumber    metrics.Gauge
    99  	SnapshotBlockNumber     metrics.Gauge
   100  	LeaderChanges           metrics.Counter
   101  	ProposalFailures        metrics.Counter
   102  	DataPersistDuration     metrics.Histogram
   103  	NormalProposalsReceived metrics.Counter
   104  	ConfigProposalsReceived metrics.Counter
   105  }
   106  
   107  func NewMetrics(p metrics.Provider) *Metrics {
   108  	return &Metrics{
   109  		ClusterSize:             p.NewGauge(clusterSizeOpts),
   110  		IsLeader:                p.NewGauge(isLeaderOpts),
   111  		ActiveNodes:             p.NewGauge(ActiveNodesOpts),
   112  		CommittedBlockNumber:    p.NewGauge(committedBlockNumberOpts),
   113  		SnapshotBlockNumber:     p.NewGauge(snapshotBlockNumberOpts),
   114  		LeaderChanges:           p.NewCounter(leaderChangesOpts),
   115  		ProposalFailures:        p.NewCounter(proposalFailuresOpts),
   116  		DataPersistDuration:     p.NewHistogram(dataPersistDurationOpts),
   117  		NormalProposalsReceived: p.NewCounter(normalProposalsReceivedOpts),
   118  		ConfigProposalsReceived: p.NewCounter(configProposalsReceivedOpts),
   119  	}
   120  }