lib/sidekiq_prometheus.rb in sidekiq_prometheus-1.8.2 vs lib/sidekiq_prometheus.rb in sidekiq_prometheus-1.8.3
- old
+ new
@@ -1,17 +1,17 @@
# frozen_string_literal: true
-require 'benchmark'
-require 'rack'
-require 'prometheus/client'
-require 'prometheus/middleware/exporter'
-require 'sidekiq'
-require 'sidekiq/api'
-require 'webrick'
+require "benchmark"
+require "rack"
+require "prometheus/client"
+require "prometheus/middleware/exporter"
+require "sidekiq"
+require "sidekiq/api"
+require "webrick"
begin
- require 'sidekiq/ent'
+ require "sidekiq/ent"
rescue LoadError
end
module SidekiqPrometheus
class << self
@@ -75,11 +75,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_host = "localhost"
self.metrics_port = 9359
self.metrics_server_logger_enabled = true
self.custom_labels = {}
self.custom_metrics = []
@@ -113,11 +113,11 @@
##
# Helper method for +global_metrics_enabled+ configuration setting
# Requires +Sidekiq::Enterprise+ as it uses the leader election functionality
# @return [Boolean] defaults to true if +Sidekiq::Enterprise+ is available
def global_metrics_enabled?
- Object.const_defined?('Sidekiq::Enterprise') && global_metrics_enabled
+ Object.const_defined?("Sidekiq::Enterprise") && global_metrics_enabled
end
##
# Helper method for +periodic_metrics_enabled+ configuration setting
# Requires +Sidekiq::Enterprise+ as it uses the leader election functionality
@@ -147,12 +147,12 @@
def [](metric)
registry.get(metric.to_sym)
end
class << self
- alias configure! configure
- alias get []
+ alias_method :configure!, :configure
+ alias_method :get, :[]
end
##
# Prometheus client metric registry
# @return [Prometheus::Client::Registry]
@@ -164,11 +164,11 @@
# Register custom metrics
# Internal method called by +setup+. This method should not be called from application code in most cases.
def register_custom_metrics
return if custom_metrics.empty?
- raise SidekiqPrometheus::Error, 'custom_metrics is not an array.' unless custom_metrics.is_a?(Array)
+ raise SidekiqPrometheus::Error, "custom_metrics is not an array." unless custom_metrics.is_a?(Array)
SidekiqPrometheus::Metrics.register_metrics(custom_metrics)
end
##
@@ -176,11 +176,10 @@
def setup
return false if @setup_complete
SidekiqPrometheus::Metrics.register_sidekiq_job_metrics
SidekiqPrometheus::Metrics.register_sidekiq_gc_metric if gc_metrics_enabled?
SidekiqPrometheus::Metrics.register_sidekiq_worker_gc_metrics if gc_metrics_enabled? && periodic_metrics_enabled?
- SidekiqPrometheus::Metrics.register_sidekiq_global_metrics if global_metrics_enabled? && periodic_metrics_enabled?
register_custom_metrics
sidekiq_setup
self.setup_complete = true
@@ -193,16 +192,16 @@
config.server_middleware do |chain|
chain.add SidekiqPrometheus::JobMetrics
end
if periodic_metrics_enabled?
- config.on(:startup) { SidekiqPrometheus::PeriodicMetrics.reporter(config).start }
+ config.on(:startup) { SidekiqPrometheus::PeriodicMetrics.reporter(config).start }
config.on(:shutdown) { SidekiqPrometheus::PeriodicMetrics.reporter(config).stop }
end
if metrics_server_enabled?
- config.on(:startup) { SidekiqPrometheus.metrics_server }
+ config.on(:startup) { SidekiqPrometheus.metrics_server }
config.on(:shutdown) { SidekiqPrometheus.metrics_server.kill }
end
end
end
@@ -211,31 +210,31 @@
# Will listen on SidekiqPrometheus.metrics_host and
# SidekiqPrometheus.metrics_port
def metrics_server
opts = {
Port: SidekiqPrometheus.metrics_port,
- Host: SidekiqPrometheus.metrics_host,
+ Host: SidekiqPrometheus.metrics_host
}
unless metrics_server_logger_enabled?
- opts[:Logger] = WEBrick::Log.new('/dev/null')
+ 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' }, []] }
+ run ->(_) { [301, {"Location" => "/metrics"}, []] }
},
**opts
)
end
end
end
class SidekiqPrometheus::Error < StandardError; end
-require 'sidekiq_prometheus/job_metrics'
-require 'sidekiq_prometheus/metrics'
-require 'sidekiq_prometheus/periodic_metrics'
-require 'sidekiq_prometheus/version'
+require "sidekiq_prometheus/job_metrics"
+require "sidekiq_prometheus/metrics"
+require "sidekiq_prometheus/periodic_metrics"
+require "sidekiq_prometheus/version"