class Phantom::Collector

Public Class Methods

get_running_instances() click to toggle source
# File lib/phantom/collector.rb, line 11
def get_running_instances
  lines = running_phantoms_shell_output.split("\n")
  parse_processes lines
end
missing_ports() click to toggle source
# File lib/phantom/collector.rb, line 16
def missing_ports
  required_ports - get_running_instances.map(&:port)
end
on_port(port) click to toggle source
# File lib/phantom/collector.rb, line 7
def on_port(port)
  get_running_instances.find {|p| p.port == port}
end
required_ports() click to toggle source
# File lib/phantom/collector.rb, line 20
def required_ports
  (Cfg.phantom_base_port..(Cfg.phantom_base_port+Cfg.phantom_processes_number-1)).to_a
end

Private Class Methods

log_error(processes, lines) click to toggle source
# File lib/phantom/collector.rb, line 41
def log_error(processes, lines)
  $logger.error "Collector got bad process!"
  $logger.error "Processes were #{processes}"
  $logger.error "lines were: #{lines}"
end
parse_processes(lines) click to toggle source
# File lib/phantom/collector.rb, line 26
def parse_processes(lines)
  processes = lines.map {|l| Phantom::Process.from_string(l) }
  bad_processes = processes.select {|p| !required_ports.include?(p.port)}
  log_error(bad_processes, lines) if bad_processes.any?
  processes.select {|p| required_ports.include?(p.port)}
end
running_phantoms_shell_command() click to toggle source
# File lib/phantom/collector.rb, line 37
def running_phantoms_shell_command
  "ps -e -www -o pid,rss,command | grep '#{Cfg.phantom_command}' | grep -v sh | grep -v grep"
end
running_phantoms_shell_output() click to toggle source
# File lib/phantom/collector.rb, line 33
def running_phantoms_shell_output
  `#{running_phantoms_shell_command}`
end