github.com/anjalikarhana/fabric@v2.1.1+incompatible/common/ledger/blkstorage/fsblkstorage/metrics.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package fsblkstorage
     8  
     9  import (
    10  	"time"
    11  
    12  	"github.com/hyperledger/fabric/common/metrics"
    13  )
    14  
    15  type stats struct {
    16  	blockchainHeight       metrics.Gauge
    17  	blockstorageCommitTime metrics.Histogram
    18  }
    19  
    20  func newStats(metricsProvider metrics.Provider) *stats {
    21  	stats := &stats{}
    22  	stats.blockchainHeight = metricsProvider.NewGauge(blockchainHeightOpts)
    23  	stats.blockstorageCommitTime = metricsProvider.NewHistogram(blockstorageCommitTimeOpts)
    24  	return stats
    25  }
    26  
    27  // ledgerStats defines block metrics that are common for both orderer and peer
    28  type ledgerStats struct {
    29  	stats    *stats
    30  	ledgerid string
    31  }
    32  
    33  func (s *stats) ledgerStats(ledgerid string) *ledgerStats {
    34  	return &ledgerStats{
    35  		s, ledgerid,
    36  	}
    37  }
    38  
    39  func (s *ledgerStats) updateBlockchainHeight(height uint64) {
    40  	// casting uint64 to float64 guarantees precision for the numbers upto 9,007,199,254,740,992 (1<<53)
    41  	// since, we are not expecting the blockchains of this scale anytime soon, we go ahead with this for now.
    42  	s.stats.blockchainHeight.With("channel", s.ledgerid).Set(float64(height))
    43  }
    44  
    45  func (s *ledgerStats) updateBlockstorageCommitTime(timeTaken time.Duration) {
    46  	s.stats.blockstorageCommitTime.With("channel", s.ledgerid).Observe(timeTaken.Seconds())
    47  }
    48  
    49  var (
    50  	blockchainHeightOpts = metrics.GaugeOpts{
    51  		Namespace:    "ledger",
    52  		Subsystem:    "",
    53  		Name:         "blockchain_height",
    54  		Help:         "Height of the chain in blocks.",
    55  		LabelNames:   []string{"channel"},
    56  		StatsdFormat: "%{#fqname}.%{channel}",
    57  	}
    58  
    59  	blockstorageCommitTimeOpts = metrics.HistogramOpts{
    60  		Namespace:    "ledger",
    61  		Subsystem:    "",
    62  		Name:         "blockstorage_commit_time",
    63  		Help:         "Time taken in seconds for committing the block to storage.",
    64  		LabelNames:   []string{"channel"},
    65  		StatsdFormat: "%{#fqname}.%{channel}",
    66  		Buckets:      []float64{0.005, 0.01, 0.015, 0.05, 0.1, 1, 10},
    67  	}
    68  )