Sha256: 2042c46fca055f79368c1ed7385e9dc49d70b325aed036d9a2f97b0a86b6dcc5

Contents?: true

Size: 1.41 KB

Versions: 19

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module PrometheusExporter::Server
  class HutchCollector < TypeCollector
    def initialize
      @hutch_jobs_total = nil
      @hutch_job_duration_seconds = nil
      @hutch_jobs_total = nil
      @hutch_failed_jobs_total = nil
    end

    def type
      "hutch"
    end

    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_hutch_metrics
      @hutch_job_duration_seconds.observe(obj["duration"], labels)
      @hutch_jobs_total.observe(1, labels)
      @hutch_failed_jobs_total.observe(1, labels) if !obj["success"]
    end

    def metrics
      if @hutch_jobs_total
        [@hutch_job_duration_seconds, @hutch_jobs_total, @hutch_failed_jobs_total]
      else
        []
      end
    end

    protected

    def ensure_hutch_metrics
      if !@hutch_jobs_total

        @hutch_job_duration_seconds = PrometheusExporter::Metric::Counter.new(
          "hutch_job_duration_seconds", "Total time spent in hutch jobs.")

        @hutch_jobs_total = PrometheusExporter::Metric::Counter.new(
          "hutch_jobs_total", "Total number of hutch jobs executed.")

        @hutch_failed_jobs_total = PrometheusExporter::Metric::Counter.new(
          "hutch_failed_jobs_total", "Total number failed hutch jobs executed.")
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
prometheus_exporter-2.1.1 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-2.1.0 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-2.0.8 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-2.0.7 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-2.0.6 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-2.0.5 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-2.0.4 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-2.0.3 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-2.0.2 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-2.0.1 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-2.0.0 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-1.0.1 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-1.0.0 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.8.1 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.8.0 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.7.0 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.6.0 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.5.3 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.5.2 lib/prometheus_exporter/server/hutch_collector.rb