Class: PrometheusExporter::Server::DelayedJobCollector

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

Instance Method Summary collapse

Instance Method Details

#collect(obj) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/prometheus_exporter/server/delayed_job_collector.rb', line 10

def collect(obj)
  default_labels = { job_name: obj['name'] }
  custom_labels = obj['custom_labels']
  labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels)

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

#metricsObject



28
29
30
31
32
33
34
35
36
# File 'lib/prometheus_exporter/server/delayed_job_collector.rb', line 28

def metrics
  if @delayed_jobs_total
    [@delayed_job_duration_seconds, @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



6
7
8
# File 'lib/prometheus_exporter/server/delayed_job_collector.rb', line 6

def type
  "delayed_job"
end