Class: PrometheusExporter::Server::SidekiqProcessCollector
- Inherits:
-
TypeCollector
- Object
- TypeCollector
- PrometheusExporter::Server::SidekiqProcessCollector
- Defined in:
- lib/prometheus_exporter/server/sidekiq_process_collector.rb
Constant Summary collapse
- MAX_SIDEKIQ_METRIC_AGE =
60
- SIDEKIQ_PROCESS_GAUGES =
{ 'busy' => 'Number of running jobs', 'concurrency' => 'Maximum concurrency', }.freeze
Instance Attribute Summary collapse
-
#gauges ⇒ Object
readonly
Returns the value of attribute gauges.
-
#sidekiq_metrics ⇒ Object
readonly
Returns the value of attribute sidekiq_metrics.
Instance Method Summary collapse
- #collect(object) ⇒ Object
-
#initialize ⇒ SidekiqProcessCollector
constructor
A new instance of SidekiqProcessCollector.
- #metrics ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize ⇒ SidekiqProcessCollector
Returns a new instance of SidekiqProcessCollector.
14 15 16 17 |
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 14 def initialize @sidekiq_metrics = [] @gauges = {} end |
Instance Attribute Details
#gauges ⇒ Object (readonly)
Returns the value of attribute gauges.
12 13 14 |
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 12 def gauges @gauges end |
#sidekiq_metrics ⇒ Object (readonly)
Returns the value of attribute sidekiq_metrics.
12 13 14 |
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 12 def sidekiq_metrics @sidekiq_metrics end |
Instance Method Details
#collect(object) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 37 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 |
#metrics ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 23 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 |
#type ⇒ Object
19 20 21 |
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 19 def type 'sidekiq_process' end |