github.com/Hnampk/fabric@v2.1.1+incompatible/gossip/metrics/metrics.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package metrics
     8  
     9  import "github.com/hyperledger/fabric/common/metrics"
    10  
    11  // GossipMetrics encapsulates all of gossip metrics
    12  type GossipMetrics struct {
    13  	StateMetrics      *StateMetrics
    14  	ElectionMetrics   *ElectionMetrics
    15  	CommMetrics       *CommMetrics
    16  	MembershipMetrics *MembershipMetrics
    17  	PrivdataMetrics   *PrivdataMetrics
    18  }
    19  
    20  func NewGossipMetrics(p metrics.Provider) *GossipMetrics {
    21  	return &GossipMetrics{
    22  		StateMetrics:      newStateMetrics(p),
    23  		ElectionMetrics:   newElectionMetrics(p),
    24  		CommMetrics:       newCommMetrics(p),
    25  		MembershipMetrics: newMembershipMetrics(p),
    26  		PrivdataMetrics:   newPrivdataMetrics(p),
    27  	}
    28  }
    29  
    30  // StateMetrics encapsulates gossip state related metrics
    31  type StateMetrics struct {
    32  	Height            metrics.Gauge
    33  	CommitDuration    metrics.Histogram
    34  	PayloadBufferSize metrics.Gauge
    35  }
    36  
    37  func newStateMetrics(p metrics.Provider) *StateMetrics {
    38  	return &StateMetrics{
    39  		Height:            p.NewGauge(HeightOpts),
    40  		CommitDuration:    p.NewHistogram(CommitDurationOpts),
    41  		PayloadBufferSize: p.NewGauge(PayloadBufferSizeOpts),
    42  	}
    43  }
    44  
    45  var (
    46  	HeightOpts = metrics.GaugeOpts{
    47  		Namespace:    "gossip",
    48  		Subsystem:    "state",
    49  		Name:         "height",
    50  		Help:         "Current ledger height",
    51  		LabelNames:   []string{"channel"},
    52  		StatsdFormat: "%{#fqname}.%{channel}",
    53  	}
    54  
    55  	CommitDurationOpts = metrics.HistogramOpts{
    56  		Namespace:    "gossip",
    57  		Subsystem:    "state",
    58  		Name:         "commit_duration",
    59  		Help:         "Time it takes to commit a block in seconds",
    60  		LabelNames:   []string{"channel"},
    61  		StatsdFormat: "%{#fqname}.%{channel}",
    62  	}
    63  
    64  	PayloadBufferSizeOpts = metrics.GaugeOpts{
    65  		Namespace:    "gossip",
    66  		Subsystem:    "payload_buffer",
    67  		Name:         "size",
    68  		Help:         "Size of the payload buffer",
    69  		LabelNames:   []string{"channel"},
    70  		StatsdFormat: "%{#fqname}.%{channel}",
    71  	}
    72  )
    73  
    74  // ElectionMetrics encapsulates gossip leader election related metrics
    75  type ElectionMetrics struct {
    76  	Declaration metrics.Gauge
    77  }
    78  
    79  func newElectionMetrics(p metrics.Provider) *ElectionMetrics {
    80  	return &ElectionMetrics{
    81  		Declaration: p.NewGauge(LeaderDeclerationOpts),
    82  	}
    83  }
    84  
    85  var (
    86  	LeaderDeclerationOpts = metrics.GaugeOpts{
    87  		Namespace:    "gossip",
    88  		Subsystem:    "leader_election",
    89  		Name:         "leader",
    90  		Help:         "Peer is leader (1) or follower (0)",
    91  		LabelNames:   []string{"channel"},
    92  		StatsdFormat: "%{#fqname}.%{channel}",
    93  	}
    94  )
    95  
    96  // CommMetrics encapsulates gossip communication related metrics
    97  type CommMetrics struct {
    98  	SentMessages     metrics.Counter
    99  	BufferOverflow   metrics.Counter
   100  	ReceivedMessages metrics.Counter
   101  }
   102  
   103  func newCommMetrics(p metrics.Provider) *CommMetrics {
   104  	return &CommMetrics{
   105  		SentMessages:     p.NewCounter(SentMessagesOpts),
   106  		BufferOverflow:   p.NewCounter(BufferOverflowOpts),
   107  		ReceivedMessages: p.NewCounter(ReceivedMessagesOpts),
   108  	}
   109  }
   110  
   111  var (
   112  	SentMessagesOpts = metrics.CounterOpts{
   113  		Namespace:    "gossip",
   114  		Subsystem:    "comm",
   115  		Name:         "messages_sent",
   116  		Help:         "Number of messages sent",
   117  		StatsdFormat: "%{#fqname}",
   118  	}
   119  
   120  	BufferOverflowOpts = metrics.CounterOpts{
   121  		Namespace:    "gossip",
   122  		Subsystem:    "comm",
   123  		Name:         "overflow_count",
   124  		Help:         "Number of outgoing queue buffer overflows",
   125  		StatsdFormat: "%{#fqname}",
   126  	}
   127  
   128  	ReceivedMessagesOpts = metrics.CounterOpts{
   129  		Namespace:    "gossip",
   130  		Subsystem:    "comm",
   131  		Name:         "messages_received",
   132  		Help:         "Number of messages received",
   133  		StatsdFormat: "%{#fqname}",
   134  	}
   135  )
   136  
   137  // MembershipMetrics encapsulates gossip channel membership related metrics
   138  type MembershipMetrics struct {
   139  	Total metrics.Gauge
   140  }
   141  
   142  func newMembershipMetrics(p metrics.Provider) *MembershipMetrics {
   143  	return &MembershipMetrics{
   144  		Total: p.NewGauge(TotalOpts),
   145  	}
   146  }
   147  
   148  var (
   149  	TotalOpts = metrics.GaugeOpts{
   150  		Namespace:    "gossip",
   151  		Subsystem:    "membership",
   152  		Name:         "total_peers_known",
   153  		Help:         "Total known peers",
   154  		LabelNames:   []string{"channel"},
   155  		StatsdFormat: "%{#fqname}.%{channel}",
   156  	}
   157  )
   158  
   159  // PrivdataMetrics encapsulates gossip private data related metrics
   160  type PrivdataMetrics struct {
   161  	ValidationDuration             metrics.Histogram
   162  	ListMissingPrivateDataDuration metrics.Histogram
   163  	FetchDuration                  metrics.Histogram
   164  	CommitPrivateDataDuration      metrics.Histogram
   165  	PurgeDuration                  metrics.Histogram
   166  	SendDuration                   metrics.Histogram
   167  	ReconciliationDuration         metrics.Histogram
   168  	PullDuration                   metrics.Histogram
   169  	RetrieveDuration               metrics.Histogram
   170  }
   171  
   172  func newPrivdataMetrics(p metrics.Provider) *PrivdataMetrics {
   173  	return &PrivdataMetrics{
   174  		ValidationDuration:             p.NewHistogram(ValidationDurationOpts),
   175  		ListMissingPrivateDataDuration: p.NewHistogram(ListMissingPrivateDataDurationOpts),
   176  		FetchDuration:                  p.NewHistogram(FetchDurationOpts),
   177  		CommitPrivateDataDuration:      p.NewHistogram(CommitPrivateDataDurationOpts),
   178  		PurgeDuration:                  p.NewHistogram(PurgeDurationOpts),
   179  		SendDuration:                   p.NewHistogram(SendDurationOpts),
   180  		ReconciliationDuration:         p.NewHistogram(ReconciliationDurationOpts),
   181  		PullDuration:                   p.NewHistogram(PullDurationOpts),
   182  		RetrieveDuration:               p.NewHistogram(RetrieveDurationOpts),
   183  	}
   184  }
   185  
   186  var (
   187  	ValidationDurationOpts = metrics.HistogramOpts{
   188  		Namespace:    "gossip",
   189  		Subsystem:    "privdata",
   190  		Name:         "validation_duration",
   191  		Help:         "Time it takes to validate a block (in seconds)",
   192  		LabelNames:   []string{"channel"},
   193  		StatsdFormat: "%{#fqname}.%{channel}",
   194  	}
   195  
   196  	ListMissingPrivateDataDurationOpts = metrics.HistogramOpts{
   197  		Namespace:    "gossip",
   198  		Subsystem:    "privdata",
   199  		Name:         "list_missing_duration",
   200  		Help:         "Time it takes to list the missing private data (in seconds)",
   201  		LabelNames:   []string{"channel"},
   202  		StatsdFormat: "%{#fqname}.%{channel}",
   203  	}
   204  
   205  	FetchDurationOpts = metrics.HistogramOpts{
   206  		Namespace:    "gossip",
   207  		Subsystem:    "privdata",
   208  		Name:         "fetch_duration",
   209  		Help:         "Time it takes to fetch missing private data from peers (in seconds)",
   210  		LabelNames:   []string{"channel"},
   211  		StatsdFormat: "%{#fqname}.%{channel}",
   212  	}
   213  
   214  	CommitPrivateDataDurationOpts = metrics.HistogramOpts{
   215  		Namespace:    "gossip",
   216  		Subsystem:    "privdata",
   217  		Name:         "commit_block_duration",
   218  		Help:         "Time it takes to commit private data and the corresponding block (in seconds)",
   219  		LabelNames:   []string{"channel"},
   220  		StatsdFormat: "%{#fqname}.%{channel}",
   221  	}
   222  
   223  	PurgeDurationOpts = metrics.HistogramOpts{
   224  		Namespace:    "gossip",
   225  		Subsystem:    "privdata",
   226  		Name:         "purge_duration",
   227  		Help:         "Time it takes to purge private data (in seconds)",
   228  		LabelNames:   []string{"channel"},
   229  		StatsdFormat: "%{#fqname}.%{channel}",
   230  	}
   231  
   232  	SendDurationOpts = metrics.HistogramOpts{
   233  		Namespace:    "gossip",
   234  		Subsystem:    "privdata",
   235  		Name:         "send_duration",
   236  		Help:         "Time it takes to send a missing private data element (in seconds)",
   237  		LabelNames:   []string{"channel"},
   238  		StatsdFormat: "%{#fqname}.%{channel}",
   239  	}
   240  
   241  	ReconciliationDurationOpts = metrics.HistogramOpts{
   242  		Namespace:    "gossip",
   243  		Subsystem:    "privdata",
   244  		Name:         "reconciliation_duration",
   245  		Help:         "Time it takes for reconciliation to complete (in seconds)",
   246  		LabelNames:   []string{"channel"},
   247  		StatsdFormat: "%{#fqname}.%{channel}",
   248  	}
   249  
   250  	PullDurationOpts = metrics.HistogramOpts{
   251  		Namespace:    "gossip",
   252  		Subsystem:    "privdata",
   253  		Name:         "pull_duration",
   254  		Help:         "Time it takes to pull a missing private data element (in seconds)",
   255  		LabelNames:   []string{"channel"},
   256  		StatsdFormat: "%{#fqname}.%{channel}",
   257  	}
   258  
   259  	RetrieveDurationOpts = metrics.HistogramOpts{
   260  		Namespace:    "gossip",
   261  		Subsystem:    "privdata",
   262  		Name:         "retrieve_duration",
   263  		Help:         "Time it takes to retrieve missing private data elements from the ledger (in seconds)",
   264  		LabelNames:   []string{"channel"},
   265  		StatsdFormat: "%{#fqname}.%{channel}",
   266  	}
   267  )