lib/sidekiq_prometheus.rb in sidekiq_prometheus-1.1.0 vs lib/sidekiq_prometheus.rb in sidekiq_prometheus-1.2.0

- old
+ new

@@ -45,10 +45,13 @@ attr_accessor :periodic_metrics_enabled # @return [Integer] Interval in seconds to record metrics. Default: 30 attr_accessor :periodic_reporting_interval + # @return [Boolean] Setting to control enabling/disabling the metrics server. Default: true + attr_accessor :metrics_server_enabled + # @return [String] Host on which the metrics server will listen. Default: localhost attr_accessor :metrics_host # @return [Integer] Port on which the metrics server will listen. Default: 9357 attr_accessor :metrics_port @@ -67,10 +70,11 @@ self.gc_metrics_enabled = true self.periodic_metrics_enabled = true self.global_metrics_enabled = true self.periodic_reporting_interval = 30 + self.metrics_server_enabled = true self.metrics_host = 'localhost' self.metrics_port = 9359 self.custom_labels = {} self.custom_metrics = [] @@ -116,10 +120,17 @@ def periodic_metrics_enabled? periodic_metrics_enabled end ## + # Helper method for +metrics_server_enabled+ configuration setting + # @return [Boolean] defaults to true + def metrics_server_enabled? + metrics_server_enabled + end + + ## # Get a metric from the registry # @param metric [Symbol] name of metric to fetch # @return [Prometheus::Client::Metric] def [](metric) registry.get(metric.to_sym) @@ -174,11 +185,13 @@ if periodic_metrics_enabled? config.on(:startup) { SidekiqPrometheus::PeriodicMetrics.reporter.start } config.on(:shutdown) { SidekiqPrometheus::PeriodicMetrics.reporter.stop } end - config.on(:startup) { SidekiqPrometheus.metrics_server } - config.on(:shutdown) { SidekiqPrometheus.metrics_server.kill } + if metrics_server_enabled? + config.on(:startup) { SidekiqPrometheus.metrics_server } + config.on(:shutdown) { SidekiqPrometheus.metrics_server.kill } + end end end ## # Start a new Prometheus exporter in a new thread.