Skip to content

Commit

Permalink
Allow turn off prometheus metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
  • Loading branch information
VladoLavor committed Oct 21, 2019
1 parent 69d622d commit 4d96b54
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 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, stats poller in telemetry plugin is disabled.
prometheus-disabled: false

# Skip collecting some of the metrics.
# runtime, memory, buffers, nodes, interfaces
#skipped: [nodes]
61 changes: 35 additions & 26 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,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
}

Expand Down

0 comments on commit 4d96b54

Please sign in to comment.