Sha256: e203579051a10c34812c0f8eb1af90ec1f2ebbf5022377da753f6dca139449c1

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

module PrometheusExporter::Server
  class HutchCollector < TypeCollector

    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

10 entries across 10 versions & 1 rubygems

Version Path
prometheus_exporter-0.4.10 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.4.9 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.4.8 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.4.7 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.4.6 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.4.5 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.4.4 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.4.3 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.4.2 lib/prometheus_exporter/server/hutch_collector.rb
prometheus_exporter-0.4.1 lib/prometheus_exporter/server/hutch_collector.rb