diff --git a/.gitignore b/.gitignore index f317911..1471528 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ main bin/ GeoLite2-*.mmdb .idea/* +*.log diff --git a/cmd/root.go b/cmd/root.go index 9862576..dcd7b1c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -35,6 +35,7 @@ func init() { logLevel string requestTimeout time.Duration disableCentralHarvesterCollection bool + logBlockTimes bool ) cobra.OnInitialize(initConfig) @@ -46,6 +47,7 @@ func init() { 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") + rootCmd.PersistentFlags().BoolVar(&logBlockTimes, "log-block-times", false, "Enables logging of block (pre)validation times to log files.") cobra.CheckErr(viper.BindPFlag("hostname", rootCmd.PersistentFlags().Lookup("hostname"))) cobra.CheckErr(viper.BindPFlag("metrics-port", rootCmd.PersistentFlags().Lookup("metrics-port"))) @@ -53,6 +55,7 @@ func init() { 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"))) + cobra.CheckErr(viper.BindPFlag("log-block-times", rootCmd.PersistentFlags().Lookup("log-block-times"))) } // initConfig reads in config file and ENV variables if set. diff --git a/internal/metrics/fullnode.go b/internal/metrics/fullnode.go index 69d14a0..6d9e77c 100644 --- a/internal/metrics/fullnode.go +++ b/internal/metrics/fullnode.go @@ -12,6 +12,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" @@ -316,11 +317,13 @@ func (s *FullNodeServiceMetrics) Block(resp *types.WebsocketResponse) { s.preValidationTime.Set(block.PreValidationTime) s.validationTime.Set(block.ValidationTime) - if err = utils.LogToFile("preValidationTime.log", fmt.Sprintf("%f", block.PreValidationTime)); err != nil { - log.Error(err.Error()) - } - if err = utils.LogToFile("validationTime.log", fmt.Sprintf("%f", block.ValidationTime)); err != nil { - log.Error(err.Error()) + if viper.GetBool("log-block-times") { + if err = utils.LogToFile("preValidationTime.log", fmt.Sprintf("%f", block.PreValidationTime)); err != nil { + log.Error(err.Error()) + } + if err = utils.LogToFile("validationTime.log", fmt.Sprintf("%f", block.ValidationTime)); err != nil { + log.Error(err.Error()) + } } if block.TransactionBlock {