Class: Process::Metrics::General

Inherits:
Struct
  • Object
show all
Defined in:
lib/process/metrics/general.rb

Overview

General process information.

Defined Under Namespace

Modules: Linux, ProcessStatus

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commandObject

Returns the value of attribute command

Returns:

  • (Object)

    the current value of command



38
39
40
# File 'lib/process/metrics/general.rb', line 38

def command
  @command
end

#elapsed_timeObject

Returns the value of attribute elapsed_time

Returns:

  • (Object)

    the current value of elapsed_time



38
39
40
# File 'lib/process/metrics/general.rb', line 38

def elapsed_time
  @elapsed_time
end

#memoryObject

Returns the value of attribute memory

Returns:

  • (Object)

    the current value of memory



38
39
40
# File 'lib/process/metrics/general.rb', line 38

def memory
  @memory
end

#parent_process_idObject

Returns the value of attribute parent_process_id

Returns:

  • (Object)

    the current value of parent_process_id



38
39
40
# File 'lib/process/metrics/general.rb', line 38

def parent_process_id
  @parent_process_id
end

#process_group_idObject

Returns the value of attribute process_group_id

Returns:

  • (Object)

    the current value of process_group_id



38
39
40
# File 'lib/process/metrics/general.rb', line 38

def process_group_id
  @process_group_id
end

#process_idObject

Returns the value of attribute process_id

Returns:

  • (Object)

    the current value of process_id



38
39
40
# File 'lib/process/metrics/general.rb', line 38

def process_id
  @process_id
end

#processor_timeObject

Returns the value of attribute processor_time

Returns:

  • (Object)

    the current value of processor_time



38
39
40
# File 'lib/process/metrics/general.rb', line 38

def processor_time
  @processor_time
end

#processor_utilizationObject

Returns the value of attribute processor_utilization

Returns:

  • (Object)

    the current value of processor_utilization



38
39
40
# File 'lib/process/metrics/general.rb', line 38

def processor_utilization
  @processor_utilization
end

#resident_sizeObject

Returns the value of attribute resident_size

Returns:

  • (Object)

    the current value of resident_size



38
39
40
# File 'lib/process/metrics/general.rb', line 38

def resident_size
  @resident_size
end

#start_timeObject

Returns the value of attribute start_time

Returns:

  • (Object)

    the current value of start_time



38
39
40
# File 'lib/process/metrics/general.rb', line 38

def start_time
  @start_time
end

#virtual_sizeObject

Returns the value of attribute virtual_size

Returns:

  • (Object)

    the current value of virtual_size



38
39
40
# File 'lib/process/metrics/general.rb', line 38

def virtual_size
  @virtual_size
end

Class Method Details

.build_tree(processes) ⇒ Object

Build a parent-to-children process hierarchy from a set of processes.



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/process/metrics/general.rb', line 100

def self.build_tree(processes)
	hierarchy = Hash.new{|h,k| h[k] = []}
	
	processes.each_value do |process|
		if parent_process_id = process.parent_process_id
			hierarchy[parent_process_id] << process.process_id
		end
	end
	
	return hierarchy
end

.captureObject



131
132
133
# File 'lib/process/metrics/general/linux.rb', line 131

def capture(...)
	Process::Metrics::General::Linux.capture(...)
end

.capture_memory(processes) ⇒ Object

Capture detailed memory metrics for each process in the given collection.



114
115
116
117
118
119
120
# File 'lib/process/metrics/general.rb', line 114

def self.capture_memory(processes)
	count = processes.size
	
	processes.each do |pid, process|
		process.memory = Memory.capture(pid, count: count)
	end
end

.expand(pid, hierarchy, pids) ⇒ Object

Recursively expand a process and its descendants into a collection.



87
88
89
90
91
92
93
94
95
# File 'lib/process/metrics/general.rb', line 87

def self.expand(pid, hierarchy, pids)
	unless pids.include?(pid)
		pids << pid
		
		if children = hierarchy.fetch(pid, nil)
			self.expand_children(children, hierarchy, pids)
		end
	end
end

.expand_children(children, hierarchy, pids) ⇒ Object

Recursively expand a set of child PIDs into a collection.



77
78
79
80
81
# File 'lib/process/metrics/general.rb', line 77

def self.expand_children(children, hierarchy, pids)
	children.each do |pid|
		self.expand(pid, hierarchy, pids)
	end
end

Instance Method Details

#as_jsonObject

Convert the object to a JSON serializable hash.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/process/metrics/general.rb', line 40

def as_json
	{
		process_id: self.process_id,
		parent_process_id: self.parent_process_id,
		process_group_id: self.process_group_id,
		processor_utilization: self.processor_utilization,
		total_size: self.total_size,
		virtual_size: self.virtual_size,
		resident_size: self.resident_size,
		processor_time: self.processor_time,
		elapsed_time: self.elapsed_time,
		start_time: self.start_time,
		command: self.command,
		memory: self.memory&.as_json,
	}
end

#to_json(*arguments) ⇒ Object

Convert the object to a JSON string.



58
59
60
# File 'lib/process/metrics/general.rb', line 58

def to_json(*arguments)
	as_json.to_json(*arguments)
end

#total_sizeObject Also known as: memory_usage

The total size of the process in memory, in bytes.



63
64
65
66
67
68
69
# File 'lib/process/metrics/general.rb', line 63

def total_size
	if memory = self.memory
		memory.proportional_size
	else
		self.resident_size
	end
end