Module: Phronomy::Metrics

Defined in:
lib/phronomy/metrics.rb

Overview

Task-centric observability snapshot (Issue #276, extended in #307).

Collects live metrics from the shared Runtime components (BlockingAdapterPool, EventLoop, and Runtime task registry) and returns them as a plain Hash so they can be forwarded to any monitoring backend (Prometheus, OpenTelemetry, StatsD, etc.).

All metrics are read at the moment Metrics.snapshot is called; no persistent state is held here.

Examples:

Exporting to a metrics endpoint

data = Phronomy::Metrics.snapshot
# => { blocking_pool_active: 2, active_agent_tasks: 1, ... }

Class Method Summary collapse

Class Method Details

.snapshotHash{Symbol => Numeric}

Returns a Hash of current observability metrics.

Returns:

  • (Hash{Symbol => Numeric})


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/phronomy/metrics.rb', line 22

def self.snapshot
  pool = Runtime.instance.blocking_io
  el = EventLoop.instance
  task_snap = Runtime.instance.task_snapshot

  {
    blocking_pool_active: pool.active_count,
    blocking_pool_queue_length: pool.queue_depth,
    blocking_pool_abandoned_total: pool.abandoned_count,
    blocking_pool_size: pool.pool_size,
    event_loop_lag_last_ms: (el.last_lag_seconds * 1000).round(3),
    event_loop_lag_max_ms: (el.max_lag_seconds * 1000).round(3),
    event_loop_lag_average_ms: (el.average_lag_seconds * 1000).round(3)
  }.merge(task_snap)
end