Class: PrometheusExporter::Server::SidekiqStatsCollector

Inherits:
TypeCollector
  • Object
show all
Defined in:
lib/prometheus_exporter/server/sidekiq_stats_collector.rb

Constant Summary collapse

MAX_METRIC_AGE =
60
SIDEKIQ_STATS_GAUGES =
{
  'dead_size' => 'Size of dead the queue',
  'enqueued' => 'Number of enqueued jobs',
  'failed' => 'Number of failed jobs',
  'processed' => 'Total number of processed jobs',
  'processes_size' => 'Number of processes',
  'retry_size' => 'Size of the retries queue',
  'scheduled_size' => 'Size of the scheduled queue',
  'workers_size' => 'Number of jobs actively being processed',
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSidekiqStatsCollector

Returns a new instance of SidekiqStatsCollector.



20
21
22
23
# File 'lib/prometheus_exporter/server/sidekiq_stats_collector.rb', line 20

def initialize
  @sidekiq_metrics = MetricsContainer.new(ttl: MAX_METRIC_AGE)
  @gauges = {}
end

Instance Attribute Details

#gaugesObject (readonly)

Returns the value of attribute gauges.



18
19
20
# File 'lib/prometheus_exporter/server/sidekiq_stats_collector.rb', line 18

def gauges
  @gauges
end

#sidekiq_metricsObject (readonly)

Returns the value of attribute sidekiq_metrics.



18
19
20
# File 'lib/prometheus_exporter/server/sidekiq_stats_collector.rb', line 18

def sidekiq_metrics
  @sidekiq_metrics
end

Instance Method Details

#collect(object) ⇒ Object



44
45
46
# File 'lib/prometheus_exporter/server/sidekiq_stats_collector.rb', line 44

def collect(object)
  @sidekiq_metrics << object
end

#metricsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/prometheus_exporter/server/sidekiq_stats_collector.rb', line 29

def metrics
  SIDEKIQ_STATS_GAUGES.each_key { |name| gauges[name]&.reset! }

  sidekiq_metrics.map do |metric|
    SIDEKIQ_STATS_GAUGES.map do |name, help|
      if (value = metric['stats'][name])
        gauge = gauges[name] ||= PrometheusExporter::Metric::Gauge.new("sidekiq_stats_#{name}", help)
        gauge.observe(value)
      end
    end
  end

  gauges.values
end

#typeObject



25
26
27
# File 'lib/prometheus_exporter/server/sidekiq_stats_collector.rb', line 25

def type
  'sidekiq_stats'
end