Class: Process::Metrics::General
- Inherits:
-
Struct
- Object
- Struct
- Process::Metrics::General
- Defined in:
- lib/process/metrics/general.rb
Overview
General process information.
Defined Under Namespace
Modules: Linux, ProcessStatus
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
-
#memory ⇒ Object
Returns the value of attribute memory.
-
#parent_process_id ⇒ Object
Returns the value of attribute parent_process_id.
-
#process_group_id ⇒ Object
Returns the value of attribute process_group_id.
-
#process_id ⇒ Object
Returns the value of attribute process_id.
-
#processor_time ⇒ Object
Returns the value of attribute processor_time.
-
#processor_utilization ⇒ Object
Returns the value of attribute processor_utilization.
-
#resident_size ⇒ Object
Returns the value of attribute resident_size.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#virtual_size ⇒ Object
Returns the value of attribute virtual_size.
Class Method Summary collapse
-
.build_tree(processes) ⇒ Object
Build a parent-to-children process hierarchy from a set of processes.
- .capture ⇒ Object
-
.capture_memory(processes) ⇒ Object
Capture detailed memory metrics for each process in the given collection.
-
.expand(pid, hierarchy, pids) ⇒ Object
Recursively expand a process and its descendants into a collection.
-
.expand_children(children, hierarchy, pids) ⇒ Object
Recursively expand a set of child PIDs into a collection.
Instance Method Summary collapse
-
#as_json ⇒ Object
Convert the object to a JSON serializable hash.
-
#to_json(*arguments) ⇒ Object
Convert the object to a JSON string.
-
#total_size ⇒ Object
(also: #memory_usage)
The total size of the process in memory, in bytes.
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command
38 39 40 |
# File 'lib/process/metrics/general.rb', line 38 def command @command end |
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time
38 39 40 |
# File 'lib/process/metrics/general.rb', line 38 def elapsed_time @elapsed_time end |
#memory ⇒ Object
Returns the value of attribute memory
38 39 40 |
# File 'lib/process/metrics/general.rb', line 38 def memory @memory end |
#parent_process_id ⇒ Object
Returns the value of attribute parent_process_id
38 39 40 |
# File 'lib/process/metrics/general.rb', line 38 def parent_process_id @parent_process_id end |
#process_group_id ⇒ Object
Returns the value of attribute process_group_id
38 39 40 |
# File 'lib/process/metrics/general.rb', line 38 def process_group_id @process_group_id end |
#process_id ⇒ Object
Returns the value of attribute process_id
38 39 40 |
# File 'lib/process/metrics/general.rb', line 38 def process_id @process_id end |
#processor_time ⇒ Object
Returns the value of attribute processor_time
38 39 40 |
# File 'lib/process/metrics/general.rb', line 38 def processor_time @processor_time end |
#processor_utilization ⇒ Object
Returns the value of attribute processor_utilization
38 39 40 |
# File 'lib/process/metrics/general.rb', line 38 def processor_utilization @processor_utilization end |
#resident_size ⇒ Object
Returns the value of attribute resident_size
38 39 40 |
# File 'lib/process/metrics/general.rb', line 38 def resident_size @resident_size end |
#start_time ⇒ Object
Returns the value of attribute start_time
38 39 40 |
# File 'lib/process/metrics/general.rb', line 38 def start_time @start_time end |
#virtual_size ⇒ Object
Returns the value of attribute 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 |
.capture ⇒ Object
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.(pid, hierarchy, pids) unless pids.include?(pid) pids << pid if children = hierarchy.fetch(pid, nil) self.(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.(children, hierarchy, pids) children.each do |pid| self.(pid, hierarchy, pids) end end |
Instance Method Details
#as_json ⇒ Object
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_size ⇒ Object 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 |