Class: RoundhouseUi::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/roundhouse_ui/metrics.rb

Overview

Derived, single-snapshot metrics computed from data we already read (Sidekiq::Stats + the live ProcessSet). No storage and no deltas — these are instantaneous. Rate-based metrics (jobs/sec, velocity) are computed client-side from the dashboard's poll stream; per-class durations need the collector (a separate, opt-in piece).

Instance Method Summary collapse

Constructor Details

#initialize(stats: Sidekiq::Stats.new, processes: Sidekiq::ProcessSet.new) ⇒ Metrics

Returns a new instance of Metrics.



10
11
12
13
# File 'lib/roundhouse_ui/metrics.rb', line 10

def initialize(stats: Sidekiq::Stats.new, processes: Sidekiq::ProcessSet.new)
  @stats = stats
  @processes = processes
end

Instance Method Details

#backlogObject

Everything waiting to run: live queues + scheduled + retrying.



39
40
41
# File 'lib/roundhouse_ui/metrics.rb', line 39

def backlog
  @stats.enqueued + @stats.scheduled_size + @stats.retry_size
end

#busyObject

Worker threads currently running a job.



21
22
23
# File 'lib/roundhouse_ui/metrics.rb', line 21

def busy
  @stats.workers_size
end

#concurrencyObject

Total worker threads across the live fleet.



16
17
18
# File 'lib/roundhouse_ui/metrics.rb', line 16

def concurrency
  @concurrency ||= @processes.sum { |process| process["concurrency"].to_i }
end

#failure_ratioObject

Share of processed jobs that failed, lifetime. Coarse (Sidekiq keeps only cumulative counters); the live failure rate is computed client-side.



45
46
47
48
49
# File 'lib/roundhouse_ui/metrics.rb', line 45

def failure_ratio
  return 0.0 if @stats.processed.zero?

  @stats.failed.to_f / @stats.processed
end

#headroomObject

Idle worker threads.



34
35
36
# File 'lib/roundhouse_ui/metrics.rb', line 34

def headroom
  [ concurrency - busy, 0 ].max
end

#utilizationObject

Fraction of worker threads in use (0.0–1.0), or nil when no capacity is reporting in (no processes up) — so the view can show "—" instead of 0%.



27
28
29
30
31
# File 'lib/roundhouse_ui/metrics.rb', line 27

def utilization
  return nil if concurrency.zero?

  busy.to_f / concurrency
end