Class: PrometheusExporter::Server::ResqueCollector

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

Constant Summary collapse

MAX_METRIC_AGE =
30
RESQUE_GAUGES =
{
  processed_jobs: "Total number of processed Resque jobs.",
  failed_jobs: "Total number of failed Resque jobs.",
  pending_jobs: "Total number of pending Resque jobs.",
  queues: "Total number of Resque queues.",
  workers: "Total number of Resque workers running.",
  working: "Total number of Resque workers working."
}

Instance Method Summary collapse

Constructor Details

#initializeResqueCollector

Returns a new instance of ResqueCollector.



15
16
17
18
# File 'lib/prometheus_exporter/server/resque_collector.rb', line 15

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

Instance Method Details

#collect(object) ⇒ Object



42
43
44
# File 'lib/prometheus_exporter/server/resque_collector.rb', line 42

def collect(object)
  @resque_metrics << object
end

#metricsObject



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

def metrics
  return [] if resque_metrics.length == 0

  resque_metrics.map do |metric|
    labels = metric.fetch("custom_labels", {})

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

  gauges.values
end

#typeObject



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

def type
  "resque"
end