Class: PrometheusExporter::Server::PumaCollector
- Inherits:
-
TypeCollector
- Object
- TypeCollector
- PrometheusExporter::Server::PumaCollector
- Defined in:
- lib/prometheus_exporter/server/puma_collector.rb
Constant Summary collapse
- MAX_PUMA_METRIC_AGE =
30
- PUMA_GAUGES =
{ workers_total: "Number of puma workers.", booted_workers_total: "Number of puma workers booted.", old_workers_total: "Number of old puma workers.", running_threads_total: "Number of puma threads currently running.", request_backlog_total: "Number of requests waiting to be processed by a puma thread.", thread_pool_capacity_total: "Number of puma threads available at current scale.", max_threads_total: "Number of puma threads at available at max scale.", }
Instance Method Summary collapse
- #collect(obj) ⇒ Object
-
#initialize ⇒ PumaCollector
constructor
A new instance of PumaCollector.
- #metrics ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize ⇒ PumaCollector
Returns a new instance of PumaCollector.
16 17 18 |
# File 'lib/prometheus_exporter/server/puma_collector.rb', line 16 def initialize @puma_metrics = [] end |
Instance Method Details
#collect(obj) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/prometheus_exporter/server/puma_collector.rb', line 50 def collect(obj) now = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) obj["created_at"] = now @puma_metrics.delete_if { |m| m["created_at"] + MAX_PUMA_METRIC_AGE < now } @puma_metrics << obj end |
#metrics ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/prometheus_exporter/server/puma_collector.rb', line 24 def metrics return [] if @puma_metrics.length == 0 metrics = {} @puma_metrics.map do |m| labels = {} if m["phase"] labels.merge!(phase: m["phase"]) end if m["custom_labels"] labels.merge!(m["custom_labels"]) end PUMA_GAUGES.map do |k, help| k = k.to_s if v = m[k] g = metrics[k] ||= PrometheusExporter::Metric::Gauge.new("puma_#{k}", help) g.observe(v, labels) end end end metrics.values end |
#type ⇒ Object
20 21 22 |
# File 'lib/prometheus_exporter/server/puma_collector.rb', line 20 def type "puma" end |