Class: PrometheusExporter::Instrumentation::Puma
- Inherits:
-
Object
- Object
- PrometheusExporter::Instrumentation::Puma
- Defined in:
- lib/prometheus_exporter/instrumentation/puma.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.start(client: nil, frequency: 30) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/prometheus_exporter/instrumentation/puma.rb', line 6 def self.start(client: nil, frequency: 30) puma_collector = new client ||= PrometheusExporter::Client.default Thread.new do while true begin metric = puma_collector.collect client.send_json metric rescue => e STDERR.puts("Prometheus Exporter Failed To Collect Puma Stats #{e}") ensure sleep frequency end end end end |
Instance Method Details
#collect ⇒ Object
23 24 25 26 27 28 |
# File 'lib/prometheus_exporter/instrumentation/puma.rb', line 23 def collect metric = {} metric[:type] = "puma" collect_puma_stats(metric) metric end |
#collect_puma_stats(metric) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/prometheus_exporter/instrumentation/puma.rb', line 30 def collect_puma_stats(metric) stats = JSON.parse(::Puma.stats) if stats.key? 'workers' metric[:phase] = stats["phase"] metric[:workers_total] = stats["workers"] metric[:booted_workers_total] = stats["booted_workers"] metric[:old_workers_total] = stats["old_workers"] stats["worker_status"].each do |worker| next if worker["last_status"].empty? collect_worker_status(metric, worker["last_status"]) end else collect_worker_status(metric, stats) end end |