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

fix: Allow selectively turn off prometheus metrics and/or stats… #1532

Merged
merged 3 commits into from
Oct 21, 2019
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
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"`
VladoLavor marked this conversation as resolved.
Show resolved Hide resolved
// 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