Class: MMTop::Config
- Inherits:
-
Object
- Object
- MMTop::Config
- Defined in:
- lib/mmtop/mmconfig.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
Returns the value of attribute filters.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#info ⇒ Object
Returns the value of attribute info.
-
#options ⇒ Object
Returns the value of attribute options.
-
#quick ⇒ Object
Returns the value of attribute quick.
Instance Method Summary collapse
- #all_processes ⇒ Object
- #find_pid(pid) ⇒ Object
- #find_server(name) ⇒ Object
- #get_info ⇒ Object
-
#initialize(cmdline) ⇒ Config
constructor
A new instance of Config.
- #run_filters ⇒ Object
Constructor Details
#initialize(cmdline) ⇒ Config
Returns a new instance of Config.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mmtop/mmconfig.rb', line 5 def initialize(cmdline) config_file = cmdline["-c"] || File.join(ENV["HOME"], ".mmtop_config") raise "No file found: #{config_file}" unless File.exist?(config_file) config = YAML.load_file(config_file) if config['hosts'].nil? || config['hosts'].empty? raise "Please configure the 'hosts' section of mmtop_config" end cmdline_user = cmdline['-u'] cmdline_pass = cmdline['-p'] @hosts = config['hosts'].map do |h| h = {'host' => h} if h.is_a?(String) defaults = {'user' => (cmdline_user || config['user']), 'password' => (cmdline_pass || config['password'])} h = defaults.merge(h) Host.new(h['host'], h['user'], h['password'], h) end.compact.uniq { |h| h.name + h.port.to_s } config['sleep'] ||= 5 if config['plugin_dir'] Dir.glob("#{config['plugin_dir']}/**/*.rb").each { |f| require(f) } end @filters = MMTop::Filter.default_filters @options = config @quick = cmdline["-q"] end |
Instance Attribute Details
#filters ⇒ Object
Returns the value of attribute filters.
40 41 42 |
# File 'lib/mmtop/mmconfig.rb', line 40 def filters @filters end |
#hosts ⇒ Object
Returns the value of attribute hosts.
38 39 40 |
# File 'lib/mmtop/mmconfig.rb', line 38 def hosts @hosts end |
#info ⇒ Object
Returns the value of attribute info.
39 40 41 |
# File 'lib/mmtop/mmconfig.rb', line 39 def info @info end |
#options ⇒ Object
Returns the value of attribute options.
41 42 43 |
# File 'lib/mmtop/mmconfig.rb', line 41 def @options end |
#quick ⇒ Object
Returns the value of attribute quick.
42 43 44 |
# File 'lib/mmtop/mmconfig.rb', line 42 def quick @quick end |
Instance Method Details
#all_processes ⇒ Object
66 67 68 |
# File 'lib/mmtop/mmconfig.rb', line 66 def all_processes @info.map(&:processlist).flatten end |
#find_pid(pid) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/mmtop/mmconfig.rb', line 44 def find_pid(pid) ret = info.map { |i| i.processlist.detect { |p| p.id == pid } }.flatten.compact ret[0] end |
#find_server(name) ⇒ Object
54 55 56 |
# File 'lib/mmtop/mmconfig.rb', line 54 def find_server(name) @info.detect { |i| i.host.name.downcase == name } end |
#get_info ⇒ Object
70 71 72 73 |
# File 'lib/mmtop/mmconfig.rb', line 70 def get_info @info = hosts.map { |h| h.hostinfo } run_filters end |
#run_filters ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/mmtop/mmconfig.rb', line 58 def run_filters @info.each do |i| @filters.each do |f| f.run(i.processlist, i, self) end end end |