Sha256: 760bf0a9928b83ce957930ba33a02a1b4a5735fa9ca7867e3d22a1c3f30e518b

Contents?: true

Size: 1.81 KB

Versions: 103

Compression:

Stored size: 1.81 KB

Contents

require 'optparse'

if RUBY_PLATFORM =~ /(:?mswin|mingw)/ then abort("Inspector is only for Unix") end

OPTIONS = {
  :pid_path => File.expand_path(RAILS_ROOT + '/tmp/pids'),
  :pattern  => "dispatch.*.pid",
  :ps       => "ps -o pid,state,user,start,time,pcpu,vsz,majflt,command -p %s"
}

class Inspector
  def self.inspect(pid_path, pattern)
    new(pid_path, pattern).inspect
  end

  def initialize(pid_path, pattern)
    @pid_path, @pattern = pid_path, pattern
  end

  def inspect
    header = `#{OPTIONS[:ps] % 1}`.split("\n")[0] + "\n"
    lines  = pids.collect { |pid| `#{OPTIONS[:ps] % pid}`.split("\n")[1] }
    
    puts(header + lines.join("\n"))
  end

  private
    def pids
      pid_files.collect do |pid_file|
        File.read(pid_file).to_i
      end
    end

    def pid_files
      Dir.glob(@pid_path + "/" + @pattern)
    end
end


ARGV.options do |opts|
  opts.banner = "Usage: inspector [options]"

  opts.separator ""

  opts.on <<-EOF
  Description:
    Displays system information about Rails dispatchers (or other processes that use pid files) through
    the ps command.

  Examples:
    inspector                                             # default ps on all tmp/pids/dispatch.*.pid files
    inspector -s 'ps -o user,start,majflt,pcpu,vsz -p %s' # custom ps, %s is where the pid is interleaved
  EOF

  opts.on("  Options:")

  opts.on("-s", "--ps=command", "default: #{OPTIONS[:ps]}", String)           { |v| OPTIONS[:ps] = v }
  opts.on("-p", "--pidpath=path", "default: #{OPTIONS[:pid_path]}", String)   { |v| OPTIONS[:pid_path] = v }
  opts.on("-r", "--pattern=pattern", "default: #{OPTIONS[:pattern]}", String) { |v| OPTIONS[:pattern] = v }

  opts.separator ""

  opts.on("-h", "--help", "Show this help message.") { puts opts; exit }

  opts.parse!
end

Inspector.inspect(OPTIONS[:pid_path], OPTIONS[:pattern])

Version data entries

103 entries across 103 versions & 11 rubygems

Version Path
radiant-0.7.2 vendor/rails/railties/lib/commands/process/inspector.rb
vibes-bj-1.2.2 spec/rails_root/vendor/rails/railties/lib/commands/process/inspector.rb
vibes-bj-1.2.1 spec/rails_root/vendor/rails/railties/lib/commands/process/inspector.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/railties/lib/commands/process/inspector.rb
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/rails/railties/lib/commands/process/inspector.rb
jstorimer-deep-test-1.4.0 sample_rails_project/vendor/rails/railties/lib/commands/process/inspector.rb
jstorimer-deep-test-1.3.0 sample_rails_project/vendor/rails/railties/lib/commands/process/inspector.rb
jstorimer-deep-test-1.2.0 sample_rails_project/vendor/rails/railties/lib/commands/process/inspector.rb
jstorimer-deep-test-1.1.0 sample_rails_project/vendor/rails/railties/lib/commands/process/inspector.rb
jstorimer-deep-test-1.0.0 sample_rails_project/vendor/rails/railties/lib/commands/process/inspector.rb
jstorimer-deep-test-0.2.0 sample_rails_project/vendor/rails/railties/lib/commands/process/inspector.rb
jstorimer-deep-test-0.1.0 sample_rails_project/vendor/rails/railties/lib/commands/process/inspector.rb
rails-2.2.3 lib/commands/process/inspector.rb
antfarm-0.3.0 rails/vendor/rails/railties/lib/commands/process/inspector.rb
antfarm-0.4.0 rails/vendor/rails/railties/lib/commands/process/inspector.rb
authorails-1.0.0 lib/commands/process/inspector.rb
backlog-0.0.0 vendor/rails/railties/lib/commands/process/inspector.rb
backlog-0.0.1 vendor/rails/railties/lib/commands/process/inspector.rb
backlog-0.0.2 vendor/rails/railties/lib/commands/process/inspector.rb
backlog-0.0.4 vendor/rails/railties/lib/commands/process/inspector.rb