Class: PrometheusExporter::Server::SidekiqQueueCollector

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

Constant Summary collapse

MAX_METRIC_AGE =
60
SIDEKIQ_QUEUE_GAUGES =
{
  "backlog" => "Size of the sidekiq queue.",
  "latency_seconds" => "Latency of the sidekiq queue.",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSidekiqQueueCollector

Returns a new instance of SidekiqQueueCollector.



13
14
15
16
# File 'lib/prometheus_exporter/server/sidekiq_queue_collector.rb', line 13

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

Instance Attribute Details

#gaugesObject (readonly)

Returns the value of attribute gauges.



11
12
13
# File 'lib/prometheus_exporter/server/sidekiq_queue_collector.rb', line 11

def gauges
  @gauges
end

#sidekiq_metricsObject (readonly)

Returns the value of attribute sidekiq_metrics.



11
12
13
# File 'lib/prometheus_exporter/server/sidekiq_queue_collector.rb', line 11

def sidekiq_metrics
  @sidekiq_metrics
end

Instance Method Details

#collect(object) ⇒ Object



39
40
41
42
43
44
# File 'lib/prometheus_exporter/server/sidekiq_queue_collector.rb', line 39

def collect(object)
  object["queues"].each do |queue|
    queue["labels"].merge!(object["custom_labels"]) if object["custom_labels"]
    @sidekiq_metrics << queue
  end
end

#metricsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/prometheus_exporter/server/sidekiq_queue_collector.rb', line 22

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

  sidekiq_metrics.map do |metric|
    labels = metric.fetch("labels", {})
    SIDEKIQ_QUEUE_GAUGES.map do |name, help|
      if (value = metric[name])
        gauge =
          gauges[name] ||= PrometheusExporter::Metric::Gauge.new("sidekiq_queue_#{name}", help)
        gauge.observe(value, labels)
      end
    end
  end

  gauges.values
end

#typeObject



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

def type
  "sidekiq_queue"
end