63 Star 183 Fork 3

Gitee 极速下载/hyperledger-fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
metrics.go 4.19 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package kvledger
import (
"time"
"github.com/hyperledger/fabric/common/metrics"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/txmgr"
)
type stats struct {
blockchainHeight metrics.Gauge
blockProcessingTime metrics.Histogram
blockstorageCommitTime metrics.Histogram
statedbCommitTime metrics.Histogram
transactionsCount metrics.Counter
}
func newStats(metricsProvider metrics.Provider) *stats {
stats := &stats{}
stats.blockchainHeight = metricsProvider.NewGauge(blockchainHeightOpts)
stats.blockProcessingTime = metricsProvider.NewHistogram(blockProcessingTimeOpts)
stats.blockstorageCommitTime = metricsProvider.NewHistogram(blockstorageCommitTimeOpts)
stats.statedbCommitTime = metricsProvider.NewHistogram(statedbCommitTimeOpts)
stats.transactionsCount = metricsProvider.NewCounter(transactionCountOpts)
return stats
}
type ledgerStats struct {
stats *stats
ledgerid string
}
func (s *stats) ledgerStats(ledgerid string) *ledgerStats {
return &ledgerStats{
s, ledgerid,
}
}
func (s *ledgerStats) updateBlockchainHeight(height uint64) {
// casting uint64 to float64 guarentees precision for the numbers upto 9,007,199,254,740,992 (1<<53)
// since, we are not expecting the blockchains of this scale anytime soon, we go ahead with this for now.
s.stats.blockchainHeight.With("channel", s.ledgerid).Set(float64(height))
}
func (s *ledgerStats) updateBlockProcessingTime(timeTaken time.Duration) {
s.stats.blockProcessingTime.With("channel", s.ledgerid).Observe(timeTaken.Seconds())
}
func (s *ledgerStats) updateBlockstorageCommitTime(timeTaken time.Duration) {
s.stats.blockstorageCommitTime.With("channel", s.ledgerid).Observe(timeTaken.Seconds())
}
func (s *ledgerStats) updateStatedbCommitTime(timeTaken time.Duration) {
s.stats.statedbCommitTime.With("channel", s.ledgerid).Observe(timeTaken.Seconds())
}
func (s *ledgerStats) updateTransactionsStats(
txstatsInfo []*txmgr.TxStatInfo,
) {
for _, txstat := range txstatsInfo {
transactionTypeStr := "unknown"
if txstat.TxType != -1 {
transactionTypeStr = txstat.TxType.String()
}
chaincodeName := "unknown"
if txstat.ChaincodeID != nil {
chaincodeName = txstat.ChaincodeID.Name + ":" + txstat.ChaincodeID.Version
}
s.stats.transactionsCount.With(
"channel", s.ledgerid,
"transaction_type", transactionTypeStr,
"chaincode", chaincodeName,
"validation_code", txstat.ValidationCode.String(),
).Add(1)
}
}
var (
blockchainHeightOpts = metrics.GaugeOpts{
Namespace: "ledger",
Subsystem: "",
Name: "blockchain_height",
Help: "Height of the chain in blocks.",
LabelNames: []string{"channel"},
StatsdFormat: "%{#fqname}.%{channel}",
}
blockProcessingTimeOpts = metrics.HistogramOpts{
Namespace: "ledger",
Subsystem: "",
Name: "block_processing_time",
Help: "Time taken in seconds for ledger block processing.",
LabelNames: []string{"channel"},
StatsdFormat: "%{#fqname}.%{channel}",
Buckets: []float64{0.005, 0.01, 0.015, 0.05, 0.1, 1, 10},
}
blockstorageCommitTimeOpts = metrics.HistogramOpts{
Namespace: "ledger",
Subsystem: "",
Name: "blockstorage_commit_time",
Help: "Time taken in seconds for committing the block and private data to storage.",
LabelNames: []string{"channel"},
StatsdFormat: "%{#fqname}.%{channel}",
Buckets: []float64{0.005, 0.01, 0.015, 0.05, 0.1, 1, 10},
}
statedbCommitTimeOpts = metrics.HistogramOpts{
Namespace: "ledger",
Subsystem: "",
Name: "statedb_commit_time",
Help: "Time taken in seconds for committing block changes to state db.",
LabelNames: []string{"channel"},
StatsdFormat: "%{#fqname}.%{channel}",
Buckets: []float64{0.005, 0.01, 0.015, 0.05, 0.1, 1, 10},
}
transactionCountOpts = metrics.CounterOpts{
Namespace: "ledger",
Subsystem: "",
Name: "transaction_count",
Help: "Number of transactions processed.",
LabelNames: []string{"channel", "transaction_type", "chaincode", "validation_code"},
StatsdFormat: "%{#fqname}.%{channel}.%{transaction_type}.%{chaincode}.%{validation_code}",
}
)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/hyperledger-fabric.git
git@gitee.com:mirrors/hyperledger-fabric.git
mirrors
hyperledger-fabric
hyperledger-fabric
v1.4.0

搜索帮助