diff --git a/plugins/telemetry/config.go b/plugins/telemetry/config.go index f3796e51f9..0d98cac146 100644 --- a/plugins/telemetry/config.go +++ b/plugins/telemetry/config.go @@ -29,6 +29,8 @@ type Config struct { PollingInterval time.Duration `json:"polling-interval"` // Allows to disable plugin Disabled bool `json:"disabled"` + // Allows to export prometheus in telemetry plugin + PrometheusDisabled bool `json:"prometheus-disabled"` // Skip collecting some of the metrics: // runtime, memory, buffers, nodes, interfaces Skipped []string `json:"skipped"` diff --git a/plugins/telemetry/telemetry.conf b/plugins/telemetry/telemetry.conf index 873cd07a0d..efffee3cdf 100644 --- a/plugins/telemetry/telemetry.conf +++ b/plugins/telemetry/telemetry.conf @@ -4,6 +4,9 @@ polling-interval: 30s # If set to true, telemetry plugin is disabled. disabled: false +# If set to true, stats poller in telemetry plugin is disabled. +prometheus-disabled: false + # Skip collecting some of the metrics. # runtime, memory, buffers, nodes, interfaces #skipped: [nodes] diff --git a/plugins/telemetry/telemetry.go b/plugins/telemetry/telemetry.go index e9f149dd44..b6754c82ee 100644 --- a/plugins/telemetry/telemetry.go +++ b/plugins/telemetry/telemetry.go @@ -55,9 +55,10 @@ type Plugin struct { prometheusMetrics // From config file - updatePeriod time.Duration - disabled bool - skipped map[string]bool + updatePeriod time.Duration + disabled bool + prometheusDisabled bool + skipped map[string]bool wg sync.WaitGroup quit chan struct{} @@ -90,45 +91,53 @@ func (p *Plugin) Init() error { p.disabled = true return nil } - // This prevents setting the update period to less than 5 seconds, - // which can have significant performance hit. - if config.PollingInterval > minimumUpdatePeriod { - p.updatePeriod = config.PollingInterval - p.Log.Infof("polling period changed to %v", p.updatePeriod) - } else if config.PollingInterval > 0 { - p.Log.Warnf("polling period has to be at least %s, using default: %v", - minimumUpdatePeriod, defaultUpdatePeriod) + // Disable prometheus metrics if set by config + if config.PrometheusDisabled { + p.Log.Info("Prometheus metrics disabled via config file") + p.prometheusDisabled = true + } else { + // This prevents setting the update period to less than 5 seconds, + // which can have significant performance hit. + if config.PollingInterval > minimumUpdatePeriod { + p.updatePeriod = config.PollingInterval + p.Log.Infof("polling period changed to %v", p.updatePeriod) + } else if config.PollingInterval > 0 { + p.Log.Warnf("polling period has to be at least %s, using default: %v", + minimumUpdatePeriod, defaultUpdatePeriod) + } + // Store map of skipped metrics + for _, skip := range config.Skipped { + p.skipped[skip] = true + } } - // Store map of skipped metrics - for _, skip := range config.Skipped { - p.skipped[skip] = true - } - } - // This serves as fallback if the config was not found or if the value is not set in config. - if p.updatePeriod == 0 { - p.updatePeriod = defaultUpdatePeriod } - if err := p.registerPrometheus(); err != nil { - return err + // Register prometheus + if !p.prometheusDisabled { + if p.updatePeriod == 0 { + p.updatePeriod = defaultUpdatePeriod + } + if err := p.registerPrometheus(); err != nil { + return err + } + if p.HTTPHandlers != nil { + p.HTTPHandlers.RegisterHTTPHandler("/metrics/{metric}", metricsHandler, "GET") + } } + // Setup stats poller p.statsPollerServer.log = p.Log.NewLogger("stats-poller") if err := p.setupStatsPoller(); err != nil { return err } - if p.HTTPHandlers != nil { - p.HTTPHandlers.RegisterHTTPHandler("/metrics/{metric}", metricsHandler, "GET") - } - return nil } // AfterInit executes after initializion of Telemetry Plugin func (p *Plugin) AfterInit() error { // Do not start polling if telemetry is disabled - if p.disabled { + if p.disabled || p.prometheusDisabled { return nil }