diff --git a/cmd/root.go b/cmd/root.go index f6e42e2..9862576 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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) @@ -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. diff --git a/internal/metrics/farmer.go b/internal/metrics/farmer.go index b9a9b16..e76043a 100644 --- a/internal/metrics/farmer.go +++ b/internal/metrics/farmer.go @@ -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" @@ -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 @@ -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())