lib/sidekiq_prometheus.rb in sidekiq_prometheus-1.5.0 vs lib/sidekiq_prometheus.rb in sidekiq_prometheus-1.6.0
- old
+ new
@@ -55,10 +55,13 @@
attr_accessor :metrics_host
# @return [Integer] Port on which the metrics server will listen. Default: 9357
attr_accessor :metrics_port
+ # @return [Boolean] When set to false will silence the metric server access logs. Default: true
+ attr_accessor :metrics_server_logger_enabled
+
# Override the default Prometheus::Client
# @return [Prometheus::Client]
attr_writer :client
# Orverride the default Prometheus Metric Registry
@@ -74,10 +77,11 @@
self.global_metrics_enabled = true
self.periodic_reporting_interval = 30
self.metrics_server_enabled = true
self.metrics_host = 'localhost'
self.metrics_port = 9359
+ self.metrics_server_logger_enabled = true
self.custom_labels = {}
self.custom_metrics = []
module_function
@@ -128,10 +132,17 @@
def metrics_server_enabled?
metrics_server_enabled
end
##
+ # Helper method for +metrics_server_logger_enabled+ configuration setting
+ # @return [Boolean] defaults to true
+ def metrics_server_logger_enabled?
+ metrics_server_logger_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)
@@ -198,17 +209,26 @@
##
# Start a new Prometheus exporter in a new thread.
# Will listen on SidekiqPrometheus.metrics_host and
# SidekiqPrometheus.metrics_port
def metrics_server
+ opts = {
+ Port: SidekiqPrometheus.metrics_port,
+ Host: SidekiqPrometheus.metrics_host,
+ }
+
+ unless metrics_server_logger_enabled?
+ opts[:Logger] = WEBrick::Log.new('/dev/null')
+ opts[:AccessLog] = []
+ end
+
@_metrics_server ||= Thread.new do
Rack::Handler::WEBrick.run(
Rack::Builder.new {
use Prometheus::Middleware::Exporter, registry: SidekiqPrometheus.registry
run ->(_) { [301, { 'Location' => '/metrics' }, []] }
},
- Port: SidekiqPrometheus.metrics_port,
- Host: SidekiqPrometheus.metrics_host,
+ **opts
)
end
end
end