Class: PrometheusExporter::Server::ShoryukenCollector

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

Instance Method Summary collapse

Constructor Details

#initializeShoryukenCollector

Returns a new instance of ShoryukenCollector.



5
6
7
8
9
10
11
# File 'lib/prometheus_exporter/server/shoryuken_collector.rb', line 5

def initialize
  @shoryuken_jobs_total = nil
  @shoryuken_job_duration_seconds = nil
  @shoryuken_jobs_total = nil
  @shoryuken_restarted_jobs_total = nil
  @shoryuken_failed_jobs_total = nil
end

Instance Method Details

#collect(obj) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/prometheus_exporter/server/shoryuken_collector.rb', line 17

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

  ensure_shoryuken_metrics
  @shoryuken_job_duration_seconds.observe(obj["duration"], labels)
  @shoryuken_jobs_total.observe(1, labels)
  @shoryuken_restarted_jobs_total.observe(1, labels) if obj["shutdown"]
  @shoryuken_failed_jobs_total.observe(1, labels) if !obj["success"] && !obj["shutdown"]
end

#metricsObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/prometheus_exporter/server/shoryuken_collector.rb', line 29

def metrics
  if @shoryuken_jobs_total
    [
      @shoryuken_job_duration_seconds,
      @shoryuken_jobs_total,
      @shoryuken_restarted_jobs_total,
      @shoryuken_failed_jobs_total,
    ]
  else
    []
  end
end

#typeObject



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

def type
  "shoryuken"
end