Sha256: a71676aeb0a2e4b389ec3e54466ed9da84f0601f702b8a9a2ff6cc81a4846475
Contents?: true
Size: 1.41 KB
Versions: 2
Compression:
Stored size: 1.41 KB
Contents
# frozen_string_literal: true module PrometheusExporter::Server class ResqueCollector < TypeCollector MAX_RESQUE_METRIC_AGE = 30 RESQUE_GAUGES = { processed_jobs_total: "Total number of processed Resque jobs.", failed_jobs_total: "Total number of failed Resque jobs.", pending_jobs_total: "Total number of pending Resque jobs.", queues_total: "Total number of Resque queues.", workers_total: "Total number of Resque workers running.", working_total: "Total number of Resque workers working." } def initialize @resque_metrics = [] @gauges = {} end def type "resque" end def metrics return [] if resque_metrics.length == 0 resque_metrics.map do |metric| labels = metric.fetch("custom_labels", {}) RESQUE_GAUGES.map do |name, help| name = name.to_s if value = metric[name] gauge = gauges[name] ||= PrometheusExporter::Metric::Gauge.new("resque_#{name}", help) gauge.observe(value, labels) end end end gauges.values end def collect(object) now = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) object["created_at"] = now resque_metrics.delete_if { |metric| metric["created_at"] + MAX_RESQUE_METRIC_AGE < now } resque_metrics << object end private attr_reader :resque_metrics, :gauges end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
prometheus_exporter-0.8.1 | lib/prometheus_exporter/server/resque_collector.rb |
prometheus_exporter-0.8.0 | lib/prometheus_exporter/server/resque_collector.rb |