Class: PrometheusExporter::Server::SidekiqProcessCollector

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

Constant Summary collapse

MAX_METRIC_AGE =
60
SIDEKIQ_PROCESS_GAUGES =
{
  'busy' => 'Number of running jobs',
  'concurrency' => 'Maximum concurrency',
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSidekiqProcessCollector

Returns a new instance of SidekiqProcessCollector.



14
15
16
17
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 14

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

Instance Attribute Details

#gaugesObject (readonly)

Returns the value of attribute gauges.



12
13
14
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 12

def gauges
  @gauges
end

#sidekiq_metricsObject (readonly)

Returns the value of attribute sidekiq_metrics.



12
13
14
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 12

def sidekiq_metrics
  @sidekiq_metrics
end

Instance Method Details

#collect(object) ⇒ Object



39
40
41
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 39

def collect(object)
  @sidekiq_metrics << object["process"]
end

#metricsObject



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

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

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

  gauges.values
end

#typeObject



19
20
21
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 19

def type
  'sidekiq_process'
end