Class: PumaStats

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

Overview

Wrap puma’s stats in a safe API

Instance Method Summary collapse

Constructor Details

#initialize(stats) ⇒ PumaStats

Returns a new instance of PumaStats.



14
15
16
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 14

def initialize(stats)
  @stats = stats
end

Instance Method Details

#backlogObject



42
43
44
45
46
47
48
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 42

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



26
27
28
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 26

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

#clustered?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 18

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

#max_threadsObject



58
59
60
61
62
63
64
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 58

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

#old_workersObject



30
31
32
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 30

def old_workers
  @stats.fetch(:old_workers, 0)
end

#pool_capacityObject



50
51
52
53
54
55
56
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 50

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

#requests_countObject



66
67
68
69
70
71
72
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 66

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

#runningObject



34
35
36
37
38
39
40
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 34

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



22
23
24
# File 'lib/puma/plugin/nexus_puma_statsd.rb', line 22

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