Sha256: a0374c2f8b30d0d497cf8e28178dd25bd825f165c204328999462382ee313366

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

module PrometheusExporter::Server
  class SidekiqCollector < TypeCollector

    def type
      "sidekiq"
    end

    def collect(obj)
      ensure_sidekiq_metrics
      @sidekiq_job_duration_seconds.observe(obj["duration"], job_name: obj["name"])
      @sidekiq_job_count.observe(1, job_name: obj["name"])
      @sidekiq_failed_job_count.observe(1, job_name: obj["name"]) if !obj["success"]
    end

    def metrics
      if @sidekiq_job_count
        [@sidekiq_job_duration_seconds, @sidekiq_job_count, @sidekiq_failed_job_count]
      else
        []
      end
    end

    protected

    def ensure_sidekiq_metrics
      if !@sidekiq_job_count

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

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
prometheus_exporter-0.1.16 lib/prometheus_exporter/server/sidekiq_collector.rb
prometheus_exporter-0.1.15 lib/prometheus_exporter/server/sidekiq_collector.rb
prometheus_exporter-0.1.14 lib/prometheus_exporter/server/sidekiq_collector.rb
prometheus_exporter-0.1.13 lib/prometheus_exporter/server/sidekiq_collector.rb
prometheus_exporter-0.1.12 lib/prometheus_exporter/server/sidekiq_collector.rb