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_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 = MetricsContainer.new(ttl: MAX_METRIC_AGE) @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
43 44 45 |
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 43 def collect(object) @sidekiq_metrics << object["process"] end |
#metrics ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/prometheus_exporter/server/sidekiq_process_collector.rb', line 23 def metrics SIDEKIQ_PROCESS_GAUGES.each_key { |name| gauges[name]&.reset! } 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 |