Browse Source

add config option

pull/1737/head
Anton Kaliaev 7 years ago
parent
commit
1bdff076ad
No known key found for this signature in database GPG Key ID: 7B6881D965918214
4 changed files with 37 additions and 6 deletions
  1. +5
    -0
      CHANGELOG.md
  2. +7
    -2
      config/config.go
  3. +4
    -0
      config/toml.go
  4. +21
    -4
      node/node.go

+ 5
- 0
CHANGELOG.md View File

@ -1,5 +1,10 @@
# Changelog
## TBD
FEATURES:
- [node] added metrics (served under /metrics using a Prometheus client; disabled by default)
## 0.20.1
BUG FIXES:


+ 7
- 2
config/config.go View File

@ -142,6 +142,10 @@ type BaseConfig struct {
// Database directory
DBPath string `mapstructure:"db_dir"`
// When true, metrics are served under `/metrics` using a Prometheus client
// Check out the documentation for the list of available metrics.
Monitoring bool `mapstructure:"monitoring"`
}
// DefaultBaseConfig returns a default base configuration for a Tendermint node
@ -159,6 +163,7 @@ func DefaultBaseConfig() BaseConfig {
FilterPeers: false,
DBBackend: "leveldb",
DBPath: "data",
Monitoring: false,
}
}
@ -411,7 +416,7 @@ func (cfg *MempoolConfig) WalDir() string {
//-----------------------------------------------------------------------------
// ConsensusConfig
// ConsensusConfig defines the confuguration for the Tendermint consensus service,
// ConsensusConfig defines the configuration for the Tendermint consensus service,
// including timeouts and details about the WAL and the block structure.
type ConsensusConfig struct {
RootDir string `mapstructure:"home"`
@ -536,7 +541,7 @@ func (cfg *ConsensusConfig) SetWalFile(walFile string) {
//-----------------------------------------------------------------------------
// TxIndexConfig
// TxIndexConfig defines the confuguration for the transaction
// TxIndexConfig defines the configuration for the transaction
// indexer, including tags to index.
type TxIndexConfig struct {
// What indexer to use for transactions


+ 4
- 0
config/toml.go View File

@ -107,6 +107,10 @@ prof_laddr = "{{ .BaseConfig.ProfListenAddress }}"
# so the app can decide if we should keep the connection or not
filter_peers = {{ .BaseConfig.FilterPeers }}
# When true, metrics are served under /metrics using a Prometheus client
# Check out the documentation for the list of available metrics.
monitoring = {{ .BaseConfig.Monitoring }}
##### advanced configuration options #####
##### rpc server configuration options #####


+ 21
- 4
node/node.go View File

@ -93,8 +93,8 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
// MetricsProvider returns a consensus and p2p Metrics.
type MetricsProvider func() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics)
// DefaultMetricsProvider returns a consensus and p2p Metrics build using
// Prometheus client library.
// 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{
@ -176,6 +176,11 @@ func DefaultMetricsProvider() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics) {
}
}
// NopMetricsProvider returns consensus, p2p and mempool Metrics as no-op.
func NopMetricsProvider() (*cs.Metrics, *p2p.Metrics, *mempl.Metrics) {
return cs.NopMetrics(), p2p.NopMetrics(), mempl.NopMetrics()
}
//------------------------------------------------------------------------------
// Node is the highest level interface to a full Tendermint node.
@ -300,7 +305,17 @@ func NewNode(config *cfg.Config,
consensusLogger.Info("This node is not a validator", "addr", privValidator.GetAddress(), "pubKey", privValidator.GetPubKey())
}
csMetrics, p2pMetrics, memplMetrics := metricsProvider()
// metrics
var (
csMetrics *cs.Metrics
p2pMetrics *p2p.Metrics
memplMetrics *mempl.Metrics
)
if config.BaseConfig.Monitoring {
csMetrics, p2pMetrics, memplMetrics = metricsProvider()
} else {
csMetrics, p2pMetrics, memplMetrics = NopMetricsProvider()
}
// Make MempoolReactor
mempoolLogger := logger.With("module", "mempool")
@ -600,7 +615,9 @@ func (n *Node) startRPC() ([]net.Listener, error) {
wm := rpcserver.NewWebsocketManager(rpccore.Routes, coreCodec, rpcserver.EventSubscriber(n.eventBus))
wm.SetLogger(rpcLogger.With("protocol", "websocket"))
mux.HandleFunc("/websocket", wm.WebsocketHandler)
mux.Handle("/metrics", promhttp.Handler())
if n.config.BaseConfig.Monitoring {
mux.Handle("/metrics", promhttp.Handler())
}
rpcserver.RegisterRPCFuncs(mux, rpccore.Routes, coreCodec, rpcLogger)
listener, err := rpcserver.StartHTTPServer(listenAddr, mux, rpcLogger)
if err != nil {


Loading…
Cancel
Save