diff --git a/cmd/exporters/influxdb/influxdb.go b/cmd/exporters/influxdb/influxdb.go index 35bf0c742..49144fa54 100644 --- a/cmd/exporters/influxdb/influxdb.go +++ b/cmd/exporters/influxdb/influxdb.go @@ -8,7 +8,6 @@ import ( "bytes" "fmt" "github.com/netapp/harvest/v2/cmd/poller/exporter" - "github.com/netapp/harvest/v2/pkg/color" "github.com/netapp/harvest/v2/pkg/errs" "github.com/netapp/harvest/v2/pkg/matrix" "github.com/netapp/harvest/v2/pkg/requests" @@ -165,12 +164,8 @@ func (e *InfluxDB) Export(data *matrix.Matrix) (exporter.Stats, error) { if err = e.Metadata.LazyAddValueInt64("time", "render", time.Since(s).Microseconds()); err != nil { e.Logger.Error().Err(err).Msg("metadata render time") } - // in debug mode, don't actually export but write to log - if e.Options.Debug { - e.Logger.Debug().Msg("simulating export since in debug mode") - for _, m := range metrics { - e.Logger.Debug().Msgf("M= [%s%s%s]", color.Blue, m, color.End) - } + // in test mode, don't emit metrics + if e.Options.IsTest { return stats, nil // otherwise, to the actual export: send to the DB } else if err = e.Emit(metrics); err != nil { diff --git a/cmd/exporters/influxdb/influxdb_test.go b/cmd/exporters/influxdb/influxdb_test.go index 05cb80ceb..7e423184a 100644 --- a/cmd/exporters/influxdb/influxdb_test.go +++ b/cmd/exporters/influxdb/influxdb_test.go @@ -13,7 +13,7 @@ import ( func setupInfluxDB(t *testing.T, exporterName string) *InfluxDB { opts := options.New() - opts.Debug = true + opts.IsTest = true _, err := conf.LoadHarvestConfig("../../tools/doctor/testdata/testConfig.yml") if err != nil { diff --git a/cmd/exporters/prometheus/prometheus.go b/cmd/exporters/prometheus/prometheus.go index bc3e9ba3d..36f15d211 100644 --- a/cmd/exporters/prometheus/prometheus.go +++ b/cmd/exporters/prometheus/prometheus.go @@ -90,11 +90,6 @@ func (p *Prometheus) Init() error { p.globalPrefix = globalPrefix } - if p.Options.Debug { - p.Logger.Debug().Msg("initialized without HTTP server since in debug mode") - return nil - } - // add HELP and TYPE tags to exported metrics if requested if p.Params.ShouldAddMetaTags != nil && *p.Params.ShouldAddMetaTags { p.addMetaTags = true @@ -225,15 +220,6 @@ func (p *Prometheus) Export(data *matrix.Matrix) (exporter.Stats, error) { // fix render time for metadata d := time.Since(start) - // simulate export in debug mode - if p.Options.Debug { - p.Logger.Debug().Msg("no export since in debug mode") - for _, m := range metrics { - p.Logger.Debug().Msgf("M= %s", string(m)) - } - return stats, nil - } - // store metrics in cache key := data.UUID + "." + data.Object + "." + data.Identifier diff --git a/cmd/harvest/harvest.go b/cmd/harvest/harvest.go index 766070297..c86989c84 100644 --- a/cmd/harvest/harvest.go +++ b/cmd/harvest/harvest.go @@ -5,7 +5,11 @@ NetApp Harvest : the swiss-army-knife for datacenter monitoring Authors: - Georg Mey & Vachagan Gratian + Chris Grindstaff + Georg Mey + Hardik Leuva + Rahul Gupta + Vachagan Gratian Contact: @@ -538,7 +542,7 @@ Feedback "debug", "d", false, - "debug mode collects data, but no HTTP daemons and no writes to DBs", + "enable debug logging (same as -loglevel 1). If both debug and loglevel are specified, loglevel wins", ) startCmd.PersistentFlags().BoolVarP( &opts.verbose, @@ -559,7 +563,7 @@ Feedback "foreground", "f", false, - "start poller in foreground (only one poller, implies debug mode)", + "start single poller in foreground", ) startCmd.PersistentFlags().BoolVar( &opts.daemon, @@ -607,6 +611,8 @@ Feedback "only start these objects (overrides collector config)", ) _ = startCmd.PersistentFlags().MarkHidden("logtofile") + _ = startCmd.PersistentFlags().MarkHidden("verbose") + _ = startCmd.PersistentFlags().MarkHidden("trace") } // The management commands: start|status|stop|restart|kill diff --git a/cmd/poller/options/options.go b/cmd/poller/options/options.go index 7a2ce31cb..0979238f9 100644 --- a/cmd/poller/options/options.go +++ b/cmd/poller/options/options.go @@ -22,7 +22,7 @@ import ( type Options struct { Poller string // name of the Poller Daemon bool // if true, Poller is started as daemon - Debug bool // if true, Poller is started in debug mode, which means data will not be exported + Debug bool // if true, Poller is started with debug logging (same as -loglevel 1) PromPort int // HTTP port that is assigned to Poller and can be used by the Prometheus exporter Config string // filepath of Harvest config (defaults to "harvest.yml") can be relative or absolute path HomePath string // path to harvest home (usually "/opt/harvest") @@ -67,12 +67,10 @@ func (o *Options) MarshalZerologObject(e *zerolog.Event) { e.Str("config", o.Config) e.Str("confPath", o.ConfPath) e.Bool("daemon", o.Daemon) - e.Bool("debug", o.Debug) e.Int("profiling", o.Profiling) e.Int("promPort", o.PromPort) e.Str("homePath", o.HomePath) e.Str("logPath", o.LogPath) - e.Str("logPath", o.LogPath) e.Str("hostname", o.Hostname) e.Bool("asup", o.Asup) } @@ -86,6 +84,11 @@ func (o *Options) SetDefaults() *Options { o.LogPath = conf.GetHarvestLogPath() o.SetConfPath(o.ConfPath) + // If both debug and loglevel are set, loglevel wins + if o.Debug && o.LogLevel == 2 { + o.LogLevel = 1 + } + return o } diff --git a/cmd/poller/poller.go b/cmd/poller/poller.go index dcb8a02c9..aa0291dea 100644 --- a/cmd/poller/poller.go +++ b/cmd/poller/poller.go @@ -1321,7 +1321,7 @@ func init() { var flags = pollerCmd.Flags() flags.StringVarP(&opts.Poller, "poller", "p", "", "Poller name as defined in config") - flags.BoolVarP(&opts.Debug, "debug", "d", false, "Debug mode, no data will be exported") + flags.BoolVarP(&opts.Debug, "debug", "d", false, "Enable debug logging (same as -loglevel 1). If both debug and loglevel are specified, loglevel wins") flags.BoolVar(&opts.Daemon, "daemon", false, "Start as daemon") flags.IntVarP(&opts.LogLevel, "loglevel", "l", 2, "Logging level (0=trace, 1=debug, 2=info, 3=warning, 4=error, 5=critical)") flags.BoolVar(&opts.LogToFile, "logtofile", false, "When running in the foreground, log to file instead of stdout") diff --git a/docs/help/troubleshooting.md b/docs/help/troubleshooting.md index e5d41236a..7baa9bdfb 100644 --- a/docs/help/troubleshooting.md +++ b/docs/help/troubleshooting.md @@ -58,14 +58,23 @@ harvest.yml ## How do I start Harvest in debug mode? -Use the `--debug` flag when starting a poller. In debug mode, the poller will only collect metrics, but not write to databases. Another useful flag is `--foreground`, in which case all log messages are written to the terminal. Note that you can only start one poller in foreground mode. - -Finally, you can use `--loglevel=1` or `--verbose`, if you want to see a lot of log messages. For even more, you can use `--loglevel=0` or `--trace`. +Use the `--debug` flag when starting a poller to enable debug logging (`--debug` is shorthand for `--loglevel 1`). +Another useful flag is `--foreground`, which causes all log messages to be written to the terminal. +Note that you can only start one poller in foreground mode. + +The amount of logged information can be controlled with the `--loglevel` flag followed by an integer value. +The integer values are as follows: +- 0: Trace +- 1: Debug +- 2: Info (default) +- 3: Warning +- 4: Error +- 5: Critical Examples: ``` -bin/harvest start $POLLER_NAME --foreground --debug --loglevel=0 +bin/harvest start $POLLER_NAME --foreground --debug or bin/harvest start $POLLER_NAME --loglevel=1 --collectors Zapi --objects Qtree ```