Class: PrometheusExporter::Instrumentation::Unicorn
- Inherits:
-
Object
- Object
- PrometheusExporter::Instrumentation::Unicorn
- Defined in:
- lib/prometheus_exporter/instrumentation/unicorn.rb
Overview
collects stats from unicorn
Class Method Summary collapse
Instance Method Summary collapse
- #collect ⇒ Object
- #collect_unicorn_stats(metric) ⇒ Object
-
#initialize(pid_file:, listener_address:) ⇒ Unicorn
constructor
A new instance of Unicorn.
Constructor Details
#initialize(pid_file:, listener_address:) ⇒ Unicorn
Returns a new instance of Unicorn.
29 30 31 32 33 |
# File 'lib/prometheus_exporter/instrumentation/unicorn.rb', line 29 def initialize(pid_file:, listener_address:) @pid_file = pid_file @listener_address = listener_address @tcp = listener_address =~ /\A.+:\d+\z/ end |
Class Method Details
.start(pid_file:, listener_address:, client: nil, frequency: 30) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/prometheus_exporter/instrumentation/unicorn.rb', line 12 def self.start(pid_file:, listener_address:, client: nil, frequency: 30) unicorn_collector = new(pid_file: pid_file, listener_address: listener_address) client ||= PrometheusExporter::Client.default Thread.new do loop do begin metric = unicorn_collector.collect client.send_json metric rescue StandardError => e client.logger.error("Prometheus Exporter Failed To Collect Unicorn Stats #{e}") ensure sleep frequency end end end end |
Instance Method Details
#collect ⇒ Object
35 36 37 38 39 40 |
# File 'lib/prometheus_exporter/instrumentation/unicorn.rb', line 35 def collect metric = {} metric[:type] = 'unicorn' collect_unicorn_stats(metric) metric end |
#collect_unicorn_stats(metric) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/prometheus_exporter/instrumentation/unicorn.rb', line 42 def collect_unicorn_stats(metric) stats = listener_address_stats metric[:active_workers] = stats.active metric[:request_backlog] = stats.queued metric[:workers] = worker_process_count end |