Class: Mool::Process

Inherits:
Base
  • Object
show all
Defined in:
lib/mool/process.rb

Constant Summary collapse

STATUS_PROCESS =
{
  'D' => :uninterruptible_sleep,
  'R' => :running,
  'S' => :sleeping,
  'T' => :stopped_by_job_control_signal,
  't' => :stopped_by_debugger_during_trace,
  'Z' => :zombie
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#attrs

Constructor Details

#initialize(name, pattern, opt = {}) ⇒ Process

Returns a new instance of Process.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mool/process.rb', line 14

def initialize(name, pattern, opt = {})
  if name.class != String || pattern.class != String
    raise 'Please only use string types!'
  end

  @messures = []
  @pattern = pattern

  result = opt[:result] ||
           Mool::Process.services_status(
             [{ name: name,
                pattern: pattern }]
           )[name]

  result.each do |res|
    # pid, user, pcpu, pmem, rss, priority, args, nice, memory_in_kb,
    # status, cpu_percetage, men_percentage, time
    @messures << {
      name: name,
      pattern: pattern,
      ruser: res[0], # The real user ID of the process.
      user: res[1], # The effective user ID of the process.
      rgroup: res[2], #  The real group ID of the process.
      group: res[3], # The effective group ID of the process.
      pid: res[4], # The decimal value of the process ID.
      ppid: res[5], # The decimal value of the parent process ID.
      pgid: res[6], # The decimal value of the process group ID.
      pcpu: res[7], # The ratio of CPU time used recently to CPU time available in the same period, expressed as a percentage.
      vsz: res[8], # The size of the process in (virtual) memory in 1024 byte units as a decimal integer.
      nice: res[9], # The decimal value of the nice value of the process; see nice.
      etime: res[10], # In the POSIX locale, the elapsed time since the process was started, in the form: [[dd-]hh:]mm:ss
      time: res[11], # In the POSIX locale, the cumulative CPU time of the process in the form:  [dd-]hh:mm:ss
      tty: res[12], # The name of the controlling terminal of the process (if any) in the same format used by the who utility.
      comm: res[13], # The name of the command being executed (argv[0] value) as a string.
      args: res[14], # The command with all its arguments as a string.
      priority: res[15], # Priority: The scheduling priority of the task.
      virt: res[17], # Virtual Memory Size (KiB) The total amount of virtual memory used by the task
      res: res[18], # Resident Memory Size (KiB), A subset of the virtual address space (VIRT)
      shr: res[19], # Shared Memory Size (KiB), A subset of resident memory (RES) that may be used by other processes
      status: Mool::Process::STATUS_PROCESS[res[20]],
      cpu_percentage: res[21], # CPU Usage The task's share of the elapsed CPU
      mem_percentage: res[22], # Memory Usage (RES) A task's currently resident share of available physical memory.
      time_plus: res[22] # CPU Time, hundredths The same as TIME, but reflecting more granularity through hundredths of a second
    }
  end
end

Instance Attribute Details

#messuresObject

Returns the value of attribute messures.



3
4
5
# File 'lib/mool/process.rb', line 3

def messures
  @messures
end

#patternObject

Returns the value of attribute pattern.



3
4
5
# File 'lib/mool/process.rb', line 3

def pattern
  @pattern
end

Class Method Details

.all(services) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mool/process.rb', line 61

def self.all(services)
  raise 'Please only use Array type!' if services.class != Array
  result = {}

  services_data = Mool::Process.services_status(services)

  services.each do |service|
    result[service[:name]] = Mool::Process.new(
      service[:name],
      service[:pattern],
      result: services_data[service[:name]]
    )
  end

  result
end

.services_status(services) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/mool/process.rb', line 78

def self.services_status(services)
  command_ps = Mool::Command.ps
  command_top = Mool::Command.top

  result = {}

  services.each do |service|
    ps_parsed = Mool::Process.ps_parser(
      command_ps,
      service[:pattern]
    )

    result[service[:name]] = ps_parsed.collect do |data|
      data + Mool::Process.top_parser(command_top, data[4])
    end
  end

  result
end