class Epi::Daemon::Responders::Status

noinspection RubyStringKeysInHashInspection

Public Instance Methods

run() click to toggle source
# File lib/epi/daemon/responders/status.rb, line 9
def run
  Jobs.beat!
  YAML.dump stats
end

Private Instance Methods

job(j) click to toggle source
# File lib/epi/daemon/responders/status.rb, line 29
def job(j)
  all = processes(j.pids).merge processes(j.dying_pids, 'dying')
  all.count > 0 ? all : 'paused'
end
jobs() click to toggle source
# File lib/epi/daemon/responders/status.rb, line 24
def jobs
  all = Jobs.map { |id, j| ["#{j.job_description.name} [#{id}]", job(j)] }.to_h
  all.count > 0 ? all : 'none'
end
process(pid) click to toggle source
# File lib/epi/daemon/responders/status.rb, line 42
def process(pid)
  rp = ProcessStatus[pid]
  {
      'Since' => rp.started_at.strftime('%c'),
      'CPU' => '%0.1f%' % rp.cpu_percentage,
      'Memory' => '%0.1f%' % rp.memory_percentage
  }
end
processes(pids, state = nil) click to toggle source
# File lib/epi/daemon/responders/status.rb, line 34
def processes(pids, state = nil)
  pids.values.map do |pid|
    name = 'PID ' << pid.to_s
    name << " [#{state}]" if state
    [name, process(pid)]
  end.to_h
end
stats() click to toggle source
# File lib/epi/daemon/responders/status.rb, line 16
def stats
  {
      'Running as' => `whoami`.chomp,
      'Since' => Daemon.start_time.strftime('%c'),
      'Jobs' => jobs
  }
end