Class: SlashPort::Component::LinuxProcess

Inherits:
SlashPort::Component show all
Defined in:
app/models/components/linuxprocess.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SlashPort::Component

#_want, attribute, attributes, #attributes, class_initialize, components, config, #configs, configs, disable, enable, #get_attributes, get_attributes, #get_configs, get_configs, #get_things, get_things, inherited, is_enabled?, label, #path

Class Method Details

.add_process(name, &pid_method) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'app/models/components/linuxprocess.rb', line 4

def self.add_process(name, &pid_method)
  define_method(name.to_sym) do
    pid = pid_method.call().to_i
    query_process(pid)
  end

  attribute :name => name,
            :handler => name.to_sym,
            :doc => "Process data for #{name}"
end

Instance Method Details

#query_process(pid) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/components/linuxprocess.rb', line 15

def query_process(pid)
  procinfo = ProcessInfo.new(pid)
  limits = procinfo.get_limits
  tuple = SlashPort::Tuple.new
  tuple.data["open_files_max"] = limits["open files"].to_f
  tuple.data["open_files_used"] = procinfo.open_files.to_f
  if limits["open files"] == "unlimited"
    tuple.data["open_files_percent"] = 0.0
  else
    tuple.data["open_files_percent"] = procinfo.open_files / limits["open files"].to_f
  end
  return tuple
end