Sha256: 838594478fbeaa927e94ed421dce45efa069df71242cf84b9384787e5e871e25
Contents?: true
Size: 1.15 KB
Versions: 8
Compression:
Stored size: 1.15 KB
Contents
# frozen_string_literal: true module PrometheusExporter::Server class SidekiqProcessCollector < PrometheusExporter::Server::TypeCollector MAX_SIDEKIQ_METRIC_AGE = 60 SIDEKIQ_PROCESS_GAUGES = { 'busy' => 'Number of running jobs', 'concurrency' => 'Maximum concurrency', }.freeze attr_reader :sidekiq_metrics, :gauges def initialize @sidekiq_metrics = [] @gauges = {} end def type 'sidekiq_process' end def metrics sidekiq_metrics.map do |metric| labels = metric.fetch('labels', {}) SIDEKIQ_PROCESS_GAUGES.map do |name, help| if (value = metric[name]) gauge = gauges[name] ||= PrometheusExporter::Metric::Gauge.new("sidekiq_process_#{name}", help) gauge.observe(value, labels) end end end gauges.values end def collect(object) now = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) process = object['process'] process["created_at"] = now sidekiq_metrics.delete_if { |metric| metric['created_at'] + MAX_SIDEKIQ_METRIC_AGE < now } sidekiq_metrics << process end end end
Version data entries
8 entries across 8 versions & 1 rubygems