Skip to content

Commit

Permalink
Allow disabling collection of harvester data via the farmer
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender committed Nov 30, 2023
1 parent b384833 commit 6fd7e47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ func Execute() {

func init() {
var (
hostname string
metricsPort int
maxmindDBPath string
logLevel string
requestTimeout time.Duration
hostname string
metricsPort int
maxmindDBPath string
logLevel string
requestTimeout time.Duration
disableCentralHarvesterCollection bool
)

cobra.OnInitialize(initConfig)
Expand All @@ -44,12 +45,14 @@ func init() {
rootCmd.PersistentFlags().StringVar(&maxmindDBPath, "maxmind-db-path", "", "Path to the maxmind database file")
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "How verbose the logs should be. panic, fatal, error, warn, info, debug, trace")
rootCmd.PersistentFlags().DurationVar(&requestTimeout, "rpc-timeout", 10*time.Second, "How long RPC requests will wait before timing out")
rootCmd.PersistentFlags().BoolVar(&disableCentralHarvesterCollection, "disable-central-harvester-collection", false, "Disables collection of harvester information via the farmer. Useful for very large farms where this request is very expensive, or cases where chia-exporter is already installed on all harvesters")

cobra.CheckErr(viper.BindPFlag("hostname", rootCmd.PersistentFlags().Lookup("hostname")))
cobra.CheckErr(viper.BindPFlag("metrics-port", rootCmd.PersistentFlags().Lookup("metrics-port")))
cobra.CheckErr(viper.BindPFlag("maxmind-db-path", rootCmd.PersistentFlags().Lookup("maxmind-db-path")))
cobra.CheckErr(viper.BindPFlag("log-level", rootCmd.PersistentFlags().Lookup("log-level")))
cobra.CheckErr(viper.BindPFlag("rpc-timeout", rootCmd.PersistentFlags().Lookup("rpc-timeout")))
cobra.CheckErr(viper.BindPFlag("disable-central-harvester-collection", rootCmd.PersistentFlags().Lookup("disable-central-harvester-collection")))
}

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

wrappedPrometheus "github.com/chia-network/go-modules/pkg/prometheus"

Expand Down Expand Up @@ -139,6 +140,10 @@ func (s *FarmerServiceMetrics) GetConnections(resp *types.WebsocketResponse) {

// GetHarvesters loads data about harvesters connected to the farmer
func (s *FarmerServiceMetrics) GetHarvesters() {
if viper.GetBool("disable-central-harvester-collection") {
log.Debug("Skipping get_harvesters. Centralized collection disabled by config")
return
}
if s.gettingHarvesters {
log.Debug("Skipping get_harvesters since another request is already in flight")
return
Expand All @@ -148,6 +153,7 @@ func (s *FarmerServiceMetrics) GetHarvesters() {
s.gettingHarvesters = false
}()

log.Debug("Calling get_harvesters via the farmer")
harvesters, _, err := s.metrics.httpClient.FarmerService.GetHarvesters(&rpc.FarmerGetHarvestersOptions{})
if err != nil {
log.Errorf("farmer: Error getting harvesters: %s\n", err.Error())
Expand Down

0 comments on commit 6fd7e47

Please sign in to comment.