Class: PrometheusExporter::Server::UnicornCollector

Inherits:
TypeCollector
  • Object
show all
Defined in:
lib/prometheus_exporter/server/unicorn_collector.rb

Constant Summary collapse

MAX_METRIC_AGE =
60
UNICORN_GAUGES =
{
  workers: 'Number of unicorn workers.',
  active_workers: 'Number of active unicorn workers',
  request_backlog: 'Number of requests waiting to be processed by a unicorn worker.'
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeUnicornCollector

Returns a new instance of UnicornCollector.



15
16
17
# File 'lib/prometheus_exporter/server/unicorn_collector.rb', line 15

def initialize
  @unicorn_metrics = MetricsContainer.new(ttl: MAX_METRIC_AGE)
end

Instance Method Details

#collect(obj) ⇒ Object



43
44
45
# File 'lib/prometheus_exporter/server/unicorn_collector.rb', line 43

def collect(obj)
  @unicorn_metrics << obj
end

#metricsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/prometheus_exporter/server/unicorn_collector.rb', line 23

def metrics
  return [] if @unicorn_metrics.length.zero?

  metrics = {}

  @unicorn_metrics.map do |m|
    labels = m["custom_labels"] || {}

    UNICORN_GAUGES.map do |k, help|
      k = k.to_s
      if (v = m[k])
        g = metrics[k] ||= PrometheusExporter::Metric::Gauge.new("unicorn_#{k}", help)
        g.observe(v, labels)
      end
    end
  end

  metrics.values
end

#typeObject



19
20
21
# File 'lib/prometheus_exporter/server/unicorn_collector.rb', line 19

def type
  'unicorn'
end