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