Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling collection of harvester data via the farmer #124

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading