Skip to content

Commit

Permalink
Merge pull request #20 from Chia-Network/block-counts-default
Browse files Browse the repository at this point in the history
Pull block counts by default again
  • Loading branch information
cmmarslender authored Mar 22, 2022
2 parents 985019c + 3598d7f commit fa2046c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
5 changes: 0 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@ func init() {
var (
metricsPort int
maxmindDBPath string

// Optional Metrics
enableBlockCounts bool
)

cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.chia-exporter.yaml)")

rootCmd.PersistentFlags().IntVar(&metricsPort, "metrics-port", 9914, "The port the metrics server binds to")
rootCmd.PersistentFlags().StringVar(&maxmindDBPath, "maxmind-db-path", "", "Path to the maxmind database file")
rootCmd.PersistentFlags().BoolVar(&enableBlockCounts, "enable-block-counts", false, "Enables block count metrics. This tends to increase the reads on the disk, so is optional, and disabled by default.")

viper.BindPFlag("metrics-port", rootCmd.PersistentFlags().Lookup("metrics-port"))
viper.BindPFlag("maxmind-db-path", rootCmd.PersistentFlags().Lookup("maxmind-db-path"))
viper.BindPFlag("enable-block-counts", rootCmd.PersistentFlags().Lookup("enable-block-counts"))
}

// initConfig reads in config file and ENV variables if set.
Expand Down
13 changes: 2 additions & 11 deletions internal/metrics/fullnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/chia-network/go-chia-libs/pkg/rpc"
"github.com/chia-network/go-chia-libs/pkg/types"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/viper"

wrappedPrometheus "github.com/chia-network/chia-exporter/internal/prometheus"
"github.com/chia-network/chia-exporter/internal/utils"
Expand Down Expand Up @@ -89,7 +88,7 @@ func (s *FullNodeServiceMetrics) InitMetrics() {
func (s *FullNodeServiceMetrics) InitialData() {
// Ask for some initial data so we dont have to wait as long
utils.LogErr(s.metrics.client.FullNodeService.GetBlockchainState()) // Also calls get_connections once we get the response
s.RequestBlockCountMetrics()
utils.LogErr(s.metrics.client.FullNodeService.GetBlockCountMetrics())
}

// Disconnected clears/unregisters metrics when the connection drops
Expand Down Expand Up @@ -130,7 +129,7 @@ func (s *FullNodeServiceMetrics) ReceiveResponse(resp *types.WebsocketResponse)
case "block":
s.Block(resp)
// Ask for block count metrics when we get a new block
s.RequestBlockCountMetrics()
utils.LogErr(s.metrics.client.FullNodeService.GetBlockCountMetrics())
case "get_connections":
s.GetConnections(resp)
case "get_block_count_metrics":
Expand All @@ -140,14 +139,6 @@ func (s *FullNodeServiceMetrics) ReceiveResponse(resp *types.WebsocketResponse)
}
}

// RequestBlockCountMetrics Asks the full node for block count metrics
// This call can be expensive, so is optional
func (s *FullNodeServiceMetrics) RequestBlockCountMetrics() {
if viper.GetBool("enable-block-counts") {
utils.LogErr(s.metrics.client.FullNodeService.GetBlockCountMetrics())
}
}

// GetBlockchainState handler for get_blockchain_state events
func (s *FullNodeServiceMetrics) GetBlockchainState(resp *types.WebsocketResponse) {
state := &types.WebsocketBlockchainState{}
Expand Down
10 changes: 1 addition & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ To use a config file, create a new yaml file and place any configuration options
metrics-port: 9914
```
## Optional Metrics
There are a number of metrics that are opt-in due to external dependencies or because of a higher performance requirement to support them.
### Block Count Metrics
Counts of uncompact and compact blocks results in a database query that does a pretty big read from disk, so can be taxing on lower powered systems, and is disabled by default. To enable this metric, pass `--enable-block-counts`

### Country Data
## Country Data
When running alongside the crawler, the exporter can optionally export metrics indicating how many peers have been discovered in each country, based on IP address. To enable this functionality, you will need to download the MaxMind GeoLite2 Country database and provide the path to the MaxMind database to the exporter application. The path can be provided with a command line flag `--maxmind-db-path /path/to/GeoLite2-Country.mmdb`, an entry in the config yaml file `maxmind-db-path: /path/to/GeoLite2-Country.mmdb`, or an environment variable `CHIA_EXPORTER_MAXMIND_DB_PATH=/path/to/GeoLite2-Country.mmdb`. To gain access to the MaxMind DB, you can [register here](https://www.maxmind.com/en/geolite2/signup).

0 comments on commit fa2046c

Please sign in to comment.