From e4bb3566a0101c978f8930086355b1edf64f619e Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 19 Jun 2018 11:27:58 +0400 Subject: [PATCH] move metrics constructors to a separate package --- consensus/metrics.go | 27 +++++--- mempool/metrics.go | 1 + metrics/prometheus/prometheus.go | 102 +++++++++++++++++++++++++++++++ node/node.go | 84 +------------------------ p2p/metrics.go | 2 +- 5 files changed, 126 insertions(+), 90 deletions(-) create mode 100644 metrics/prometheus/prometheus.go diff --git a/consensus/metrics.go b/consensus/metrics.go index 9a5f701f2..7e1e23374 100644 --- a/consensus/metrics.go +++ b/consensus/metrics.go @@ -6,24 +6,35 @@ import ( ) // Metrics contains metrics exposed by this package. -// see MetricsProvider for descriptions. type Metrics struct { + // Height of the chain. Height metrics.Gauge + // Number of rounds. Rounds metrics.Gauge - Validators metrics.Gauge - ValidatorsPower metrics.Gauge - MissingValidators metrics.Gauge - MissingValidatorsPower metrics.Gauge - ByzantineValidators metrics.Gauge + // Number of validators. + Validators metrics.Gauge + // Total power of all validators. + ValidatorsPower metrics.Gauge + // Number of validators who did not sign. + MissingValidators metrics.Gauge + // Total power of the missing validators. + MissingValidatorsPower metrics.Gauge + // Number of validators who tried to double sign. + ByzantineValidators metrics.Gauge + // Total power of the byzantine validators. ByzantineValidatorsPower metrics.Gauge + // Time between this and the last block. BlockIntervalSeconds metrics.Histogram - NumTxs metrics.Gauge + // Number of transactions. + NumTxs metrics.Gauge + // Size of the block. BlockSizeBytes metrics.Gauge - TotalTxs metrics.Gauge + // Total number of transactions. + TotalTxs metrics.Gauge } // NopMetrics returns no-op Metrics. diff --git a/mempool/metrics.go b/mempool/metrics.go index 9c40a254f..7c3cc967b 100644 --- a/mempool/metrics.go +++ b/mempool/metrics.go @@ -8,6 +8,7 @@ import ( // Metrics contains metrics exposed by this package. // see MetricsProvider for descriptions. type Metrics struct { + // Size of the mempool. Size metrics.Gauge } diff --git a/metrics/prometheus/prometheus.go b/metrics/prometheus/prometheus.go new file mode 100644 index 000000000..7691efaee --- /dev/null +++ b/metrics/prometheus/prometheus.go @@ -0,0 +1,102 @@ +package prometheus + +import ( + prometheus "github.com/go-kit/kit/metrics/prometheus" + stdprometheus "github.com/prometheus/client_golang/prometheus" + + cs "github.com/tendermint/tendermint/consensus" + mempl "github.com/tendermint/tendermint/mempool" + "github.com/tendermint/tendermint/p2p" +) + +// Consensus returns consensus Metrics build using Prometheus client library. +func Consensus() *cs.Metrics { + return &cs.Metrics{ + Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "height", + Help: "Height of the chain.", + }, []string{}), + Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "rounds", + Help: "Number of rounds.", + }, []string{}), + + Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "validators", + Help: "Number of validators.", + }, []string{}), + ValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "validators_power", + Help: "Total power of all validators.", + }, []string{}), + MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "missing_validators", + Help: "Number of validators who did not sign.", + }, []string{}), + MissingValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "missing_validators_power", + Help: "Total power of the missing validators.", + }, []string{}), + ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "byzantine_validators", + Help: "Number of validators who tried to double sign.", + }, []string{}), + ByzantineValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "byzantine_validators_power", + Help: "Total power of the byzantine validators.", + }, []string{}), + + BlockIntervalSeconds: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ + Subsystem: "consensus", + Name: "block_interval_seconds", + Help: "Time between this and the last block.", + Buckets: []float64{1, 2.5, 5, 10, 60}, + }, []string{}), + + NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "num_txs", + Help: "Number of transactions.", + }, []string{}), + BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "block_size_bytes", + Help: "Size of the block.", + }, []string{}), + TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "consensus", + Name: "total_txs", + Help: "Total number of transactions.", + }, []string{}), + } +} + +// P2P returns p2p Metrics build using Prometheus client library. +func P2P() *p2p.Metrics { + return &p2p.Metrics{ + Peers: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "p2p", + Name: "peers", + Help: "Number of peers.", + }, []string{}), + } +} + +// Mempool returns mempool Metrics build using Prometheus client library. +func Mempool() *mempl.Metrics { + return &mempl.Metrics{ + Size: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Subsystem: "mempool", + Name: "size", + Help: "Size of the mempool (number of uncommitted transactions).", + }, []string{}), + } +} diff --git a/node/node.go b/node/node.go index 768570a22..0f55683b0 100644 --- a/node/node.go +++ b/node/node.go @@ -8,8 +8,6 @@ import ( "net" "net/http" - prometheus "github.com/go-kit/kit/metrics/prometheus" - stdprometheus "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" abci "github.com/tendermint/abci/types" @@ -24,6 +22,7 @@ import ( cs "github.com/tendermint/tendermint/consensus" "github.com/tendermint/tendermint/evidence" mempl "github.com/tendermint/tendermint/mempool" + prometrics "github.com/tendermint/tendermint/metrics/prometheus" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p/pex" "github.com/tendermint/tendermint/privval" @@ -91,90 +90,13 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) { ) } -// MetricsProvider returns a consensus and p2p Metrics. +// MetricsProvider returns a consensus, p2p and mempool Metrics. type MetricsProvider func() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics) // DefaultMetricsProvider returns consensus, p2p and mempool Metrics build // using Prometheus client library. func DefaultMetricsProvider() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics) { - return &cs.Metrics{ - Height: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "consensus", - Name: "height", - Help: "Height of the chain.", - }, []string{}), - Rounds: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "consensus", - Name: "rounds", - Help: "Number of rounds.", - }, []string{}), - - Validators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "consensus", - Name: "validators", - Help: "Number of validators.", - }, []string{}), - ValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "consensus", - Name: "validators_power", - Help: "Total power of all validators.", - }, []string{}), - MissingValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "consensus", - Name: "missing_validators", - Help: "Number of validators who did not sign.", - }, []string{}), - MissingValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "consensus", - Name: "missing_validators_power", - Help: "Total power of the missing validators.", - }, []string{}), - ByzantineValidators: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "consensus", - Name: "byzantine_validators", - Help: "Number of validators who tried to double sign.", - }, []string{}), - ByzantineValidatorsPower: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "consensus", - Name: "byzantine_validators_power", - Help: "Total power of the byzantine validators.", - }, []string{}), - - BlockIntervalSeconds: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{ - Subsystem: "consensus", - Name: "block_interval_seconds", - Help: "Time between this and the last block.", - Buckets: []float64{1, 2.5, 5, 10, 60}, - }, []string{}), - - NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "consensus", - Name: "num_txs", - Help: "Number of transactions.", - }, []string{}), - BlockSizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "consensus", - Name: "block_size_bytes", - Help: "Size of the block.", - }, []string{}), - TotalTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "consensus", - Name: "total_txs", - Help: "Total number of transactions.", - }, []string{}), - }, &p2p.Metrics{ - Peers: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "p2p", - Name: "peers", - Help: "Number of peers.", - }, []string{}), - }, &mempl.Metrics{ - Size: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ - Subsystem: "mempool", - Name: "size", - Help: "Size of the mempool (number of uncommitted transactions).", - }, []string{}), - } + return prometrics.Consensus(), prometrics.P2P(), prometrics.Mempool() } // NopMetricsProvider returns consensus, p2p and mempool Metrics as no-op. diff --git a/p2p/metrics.go b/p2p/metrics.go index 37efe443c..2e3eff147 100644 --- a/p2p/metrics.go +++ b/p2p/metrics.go @@ -6,8 +6,8 @@ import ( ) // Metrics contains metrics exposed by this package. -// see MetricsProvider for descriptions. type Metrics struct { + // Number of peers. Peers metrics.Gauge }