Class: PrometheusExporter::Server::SidekiqQueueCollector
- Inherits:
-
TypeCollector
- Object
- TypeCollector
- PrometheusExporter::Server::SidekiqQueueCollector
- Defined in:
- lib/prometheus_exporter/server/sidekiq_queue_collector.rb
Constant Summary collapse
- MAX_SIDEKIQ_METRIC_AGE =
60
- SIDEKIQ_QUEUE_GAUGES =
{ 'backlog' => 'Size of the sidekiq queue.', 'latency_seconds' => 'Latency of the sidekiq queue.', }.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 ⇒ SidekiqQueueCollector
constructor
A new instance of SidekiqQueueCollector.
- #metrics ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize ⇒ SidekiqQueueCollector
Returns a new instance of SidekiqQueueCollector.
13 14 15 16 |
# File 'lib/prometheus_exporter/server/sidekiq_queue_collector.rb', line 13 def initialize @sidekiq_metrics = MetricsContainer.new @gauges = {} end |
Instance Attribute Details
#gauges ⇒ Object (readonly)
Returns the value of attribute gauges.
11 12 13 |
# File 'lib/prometheus_exporter/server/sidekiq_queue_collector.rb', line 11 def gauges @gauges end |
#sidekiq_metrics ⇒ Object (readonly)
Returns the value of attribute sidekiq_metrics.
11 12 13 |
# File 'lib/prometheus_exporter/server/sidekiq_queue_collector.rb', line 11 def sidekiq_metrics @sidekiq_metrics end |
Instance Method Details
#collect(object) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/prometheus_exporter/server/sidekiq_queue_collector.rb', line 38 def collect(object) object['queues'].each do |queue| queue["labels"].merge!(object['custom_labels']) if object['custom_labels'] @sidekiq_metrics << queue end end |
#metrics ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/prometheus_exporter/server/sidekiq_queue_collector.rb', line 22 def metrics SIDEKIQ_QUEUE_GAUGES.each_key { |name| gauges[name]&.reset! } sidekiq_metrics.map do |metric| labels = metric.fetch("labels", {}) SIDEKIQ_QUEUE_GAUGES.map do |name, help| if (value = metric[name]) gauge = gauges[name] ||= PrometheusExporter::Metric::Gauge.new("sidekiq_queue_#{name}", help) gauge.observe(value, labels) end end end gauges.values end |
#type ⇒ Object
18 19 20 |
# File 'lib/prometheus_exporter/server/sidekiq_queue_collector.rb', line 18 def type 'sidekiq_queue' end |