Skip to content

Commit

Permalink
fix: Allow selectively turn off prometheus metrics and/or stats… (#1532)
Browse files Browse the repository at this point in the history
fix: Allow selectively turn off prometheus metrics and/or stats poller
  • Loading branch information
ondrej-fabry authored Oct 21, 2019
2 parents 69d622d + 0e0cefb commit 6413dbe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
2 changes: 2 additions & 0 deletions plugins/telemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
3 changes: 3 additions & 0 deletions plugins/telemetry/telemetry.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ polling-interval: 30s
# If set to true, telemetry plugin is disabled.
disabled: false

# If set to true, prometheus in telemetry plugin is disabled.
prometheus-disabled: false

# Skip collecting some of the metrics.
# runtime, memory, buffers, nodes, interfaces
#skipped: [nodes]
54 changes: 32 additions & 22 deletions plugins/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -90,29 +91,38 @@ 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
}
}

// Setup stats poller
p.statsPollerServer.log = p.Log.NewLogger("stats-poller")
if err := p.setupStatsPoller(); err != nil {
return err
Expand All @@ -128,7 +138,7 @@ func (p *Plugin) Init() error {
// 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
}

Expand Down

0 comments on commit 6413dbe

Please sign in to comment.