Class: PumaStats

Inherits:
Object
  • Object
show all
Defined in:
lib/puma/plugin/statsd.rb

Overview

Wrap puma’s stats in a safe API

Instance Method Summary collapse

Constructor Details

#initialize(stats) ⇒ PumaStats



36
37
38
# File 'lib/puma/plugin/statsd.rb', line 36

def initialize(stats)
  @stats = stats
end

Instance Method Details

#backlogObject



60
61
62
63
64
65
66
# File 'lib/puma/plugin/statsd.rb', line 60

def backlog
  if clustered?
    @stats[:worker_status].map { |s| s[:last_status].fetch(:backlog, 0) }.inject(0, &:+)
  else
    @stats.fetch(:backlog, 0)
  end
end

#booted_workersObject



48
49
50
# File 'lib/puma/plugin/statsd.rb', line 48

def booted_workers
  @stats.fetch(:booted_workers, 1)
end

#clustered?Boolean



40
41
42
# File 'lib/puma/plugin/statsd.rb', line 40

def clustered?
  @stats.has_key?(:workers)
end

#max_threadsObject



76
77
78
79
80
81
82
# File 'lib/puma/plugin/statsd.rb', line 76

def max_threads
  if clustered?
    @stats[:worker_status].map { |s| s[:last_status].fetch(:max_threads, 0) }.inject(0, &:+)
  else
    @stats.fetch(:max_threads, 0)
  end
end

#pool_capacityObject



68
69
70
71
72
73
74
# File 'lib/puma/plugin/statsd.rb', line 68

def pool_capacity
  if clustered?
    @stats[:worker_status].map { |s| s[:last_status].fetch(:pool_capacity, 0) }.inject(0, &:+)
  else
    @stats.fetch(:pool_capacity, 0)
  end
end

#runningObject



52
53
54
55
56
57
58
# File 'lib/puma/plugin/statsd.rb', line 52

def running
  if clustered?
    @stats[:worker_status].map { |s| s[:last_status].fetch(:running, 0) }.inject(0, &:+)
  else
    @stats.fetch(:running, 0)
  end
end

#workersObject



44
45
46
# File 'lib/puma/plugin/statsd.rb', line 44

def workers
  @stats.fetch(:workers, 1)
end