Class: PrometheusExporter::Server::DelayedJobCollector

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

Instance Method Summary collapse

Constructor Details

#initializeDelayedJobCollector

Returns a new instance of DelayedJobCollector.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/prometheus_exporter/server/delayed_job_collector.rb', line 5

def initialize
  @delayed_jobs_total = nil
  @delayed_job_duration_seconds = nil
  @delayed_job_latency_seconds_total = nil
  @delayed_jobs_total = nil
  @delayed_failed_jobs_total = nil
  @delayed_jobs_max_attempts_reached_total = nil
  @delayed_job_duration_seconds_summary = nil
  @delayed_job_attempts_summary = nil
  @delayed_jobs_enqueued = nil
  @delayed_jobs_pending = nil
end

Instance Method Details

#collect(obj) ⇒ Object



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

def collect(obj)
  custom_labels = obj['custom_labels'] || {}
  gauge_labels = { queue_name: obj['queue_name'] }.merge(custom_labels)
  counter_labels = gauge_labels.merge(job_name: obj['name'])

  ensure_delayed_job_metrics
  @delayed_job_duration_seconds.observe(obj["duration"], counter_labels)
  @delayed_job_latency_seconds_total.observe(obj["latency"], counter_labels)
  @delayed_jobs_total.observe(1, counter_labels)
  @delayed_failed_jobs_total.observe(1, counter_labels) if !obj["success"]
  @delayed_jobs_max_attempts_reached_total.observe(1, counter_labels) if obj["attempts"] >= obj["max_attempts"]
  @delayed_job_duration_seconds_summary.observe(obj["duration"], counter_labels)
  @delayed_job_duration_seconds_summary.observe(obj["duration"], counter_labels.merge(status: "success")) if obj["success"]
  @delayed_job_duration_seconds_summary.observe(obj["duration"], counter_labels.merge(status: "failed"))  if !obj["success"]
  @delayed_job_attempts_summary.observe(obj["attempts"], counter_labels) if obj["success"]
  @delayed_jobs_enqueued.observe(obj["enqueued"], gauge_labels)
  @delayed_jobs_pending.observe(obj["pending"], gauge_labels)
end

#metricsObject



41
42
43
44
45
46
47
48
49
# File 'lib/prometheus_exporter/server/delayed_job_collector.rb', line 41

def metrics
  if @delayed_jobs_total
    [@delayed_job_duration_seconds, @delayed_job_latency_seconds_total, @delayed_jobs_total, @delayed_failed_jobs_total,
     @delayed_jobs_max_attempts_reached_total, @delayed_job_duration_seconds_summary, @delayed_job_attempts_summary,
     @delayed_jobs_enqueued, @delayed_jobs_pending]
  else
    []
  end
end

#typeObject



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

def type
  "delayed_job"
end