Class: Puma::Plugin::Systemd::Status

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

Overview

Take puma’s stats and construct a sensible status line for Systemd

Instance Method Summary collapse

Constructor Details

#initialize(stats) ⇒ Status

Returns a new instance of Status.



231
232
233
# File 'lib/puma/plugin/systemd.rb', line 231

def initialize(stats)
  @stats = stats
end

Instance Method Details

#backlogObject



255
256
257
258
259
260
261
# File 'lib/puma/plugin/systemd.rb', line 255

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



243
244
245
# File 'lib/puma/plugin/systemd.rb', line 243

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

#clustered?Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/puma/plugin/systemd.rb', line 235

def clustered?
  @stats.has_key? "workers"
end

#runningObject



247
248
249
250
251
252
253
# File 'lib/puma/plugin/systemd.rb', line 247

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

#to_sObject



263
264
265
266
267
268
269
# File 'lib/puma/plugin/systemd.rb', line 263

def to_s
  if clustered?
    "puma #{Puma::Const::VERSION} cluster: #{booted_workers}/#{workers} workers: #{running} threads, #{backlog} backlog"
  else
    "puma #{Puma::Const::VERSION}: #{running} threads, #{backlog} backlog"
  end
end

#workersObject



239
240
241
# File 'lib/puma/plugin/systemd.rb', line 239

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