Class: PrometheusExporter::Server::GoodJobCollector

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

Constant Summary collapse

MAX_METRIC_AGE =
30
GOOD_JOB_GAUGES =
{
  scheduled: "Total number of scheduled GoodJob jobs.",
  retried: "Total number of retried GoodJob jobs.",
  queued: "Total number of queued GoodJob jobs.",
  running: "Total number of running GoodJob jobs.",
  finished: "Total number of finished GoodJob jobs.",
  succeeded: "Total number of succeeded GoodJob jobs.",
  discarded: "Total number of discarded GoodJob jobs."
}

Instance Method Summary collapse

Constructor Details

#initializeGoodJobCollector

Returns a new instance of GoodJobCollector.



16
17
18
19
# File 'lib/prometheus_exporter/server/good_job_collector.rb', line 16

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

Instance Method Details

#collect(object) ⇒ Object



44
45
46
# File 'lib/prometheus_exporter/server/good_job_collector.rb', line 44

def collect(object)
  @good_job_metrics << object
end

#metricsObject



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

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

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

    GOOD_JOB_GAUGES.map do |name, help|
      value = metric[name.to_s]

      if value
        gauge = gauges[name] ||= PrometheusExporter::Metric::Gauge.new("good_job_#{name}", help)
        gauge.observe(value, labels)
      end
    end
  end

  gauges.values
end

#typeObject



21
22
23
# File 'lib/prometheus_exporter/server/good_job_collector.rb', line 21

def type
  "good_job"
end