Class: Cloudscopes::Process::SystemProcess
- Inherits:
-
Object
- Object
- Cloudscopes::Process::SystemProcess
show all
- Defined in:
- lib/cloudscopes/process.rb
Constant Summary
collapse
- @@maxpid =
File.read('/proc/sys/kernel/pid_max').to_i
Instance Method Summary
collapse
Constructor Details
Returns a new instance of SystemProcess.
11
12
13
14
|
# File 'lib/cloudscopes/process.rb', line 11
def initialize(id)
@id = id.to_i
raise "Invalid system process id #{id}" unless @id > 0 && @id < @@maxpid
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/cloudscopes/process.rb', line 20
def method_missing(name, *args)
raise ArgumentError.new("wrong number of arguments (#{args.length} for 0)") unless args.length == 0
begin
File.read(procpath(name.to_s))
rescue Errno::ENOENT => e
''
rescue SystemCallError => e
$stderr.puts "Error accessing process #{@id}: #{e.class}:#{e.message}"
''
end
end
|
Instance Method Details
#exe ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/cloudscopes/process.rb', line 32
def exe
begin
File.readlink(procpath('exe'))
rescue Errno::ENOENT => e
''
rescue SystemCallError => e
$stderr.puts "Error accessing process #{@id}: #{e.class}:#{e.message}"
''
end
end
|
#exe_name ⇒ Object
43
44
45
|
# File 'lib/cloudscopes/process.rb', line 43
def exe_name
File.basename(exe)
end
|
59
60
61
|
# File 'lib/cloudscopes/process.rb', line 59
def
statm.strip.split(/\s+/)[1].to_i * Etc.sysconf(Etc::SC_PAGESIZE)
end
|
#mem_usage_virt ⇒ Object
Also known as:
mem_usage
62
63
64
|
# File 'lib/cloudscopes/process.rb', line 62
def mem_usage_virt
statm.strip.split(/\s+/)[0].to_i * Etc.sysconf(Etc::SC_PAGESIZE)
end
|
#procpath(field = nil) ⇒ Object
16
17
18
|
# File 'lib/cloudscopes/process.rb', line 16
def procpath(field = nil)
"/proc/#{@id}/#{field}"
end
|
#uid ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/cloudscopes/process.rb', line 47
def uid
begin
File.stat(procpath('mem')).uid
rescue Errno::ENOENT => e
nil
end
end
|
#user ⇒ Object
55
56
57
|
# File 'lib/cloudscopes/process.rb', line 55
def user
Etc.getpwuid(uid || 0).name
end
|