Class: ServerMetrics::Processes::Process
- Inherits:
-
Object
- Object
- ServerMetrics::Processes::Process
- Defined in:
- lib/server_metrics/collectors/processes.rb
Overview
a thin wrapper around Sys:ProcTable’s ProcTableStruct. We’re using it to add some fields and behavior. Beyond what we’re adding, it just passes through to its instance of ProcTableStruct
Instance Attribute Summary collapse
-
#recent_cpu ⇒ Object
used to store the calculation of CPU since last sample.
-
#recent_cpu_percentage ⇒ Object
used to store the calculation of CPU since last sample.
Instance Method Summary collapse
- #combined_cpu ⇒ Object
-
#has?(method_name) ⇒ Boolean
because apparently respond_to doesn’t work through method_missing.
-
#initialize(proctable_struct) ⇒ Process
constructor
A new instance of Process.
-
#method_missing(sym, *args, &block) ⇒ Object
delegate everything else to ProcTable::Struct.
Constructor Details
#initialize(proctable_struct) ⇒ Process
Returns a new instance of Process.
151 152 153 154 |
# File 'lib/server_metrics/collectors/processes.rb', line 151 def initialize(proctable_struct) @pts=proctable_struct @recent_cpu = 0 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
delegate everything else to ProcTable::Struct
166 167 168 |
# File 'lib/server_metrics/collectors/processes.rb', line 166 def method_missing(sym, *args, &block) @pts.send sym, *args, &block end |
Instance Attribute Details
#recent_cpu ⇒ Object
used to store the calculation of CPU since last sample
150 151 152 |
# File 'lib/server_metrics/collectors/processes.rb', line 150 def recent_cpu @recent_cpu end |
#recent_cpu_percentage ⇒ Object
used to store the calculation of CPU since last sample
150 151 152 |
# File 'lib/server_metrics/collectors/processes.rb', line 150 def recent_cpu_percentage @recent_cpu_percentage end |
Instance Method Details
#combined_cpu ⇒ Object
159 160 161 162 163 164 |
# File 'lib/server_metrics/collectors/processes.rb', line 159 def combined_cpu # best thread I've seen on cutime vs utime & cstime vs stime: https://www.ruby-forum.com/topic/93176 # * cutime and cstime include CPUusage of child processes # * utime and stime don't include CPU usage of child processes (utime || 0) + (stime || 0) # utime and stime aren't available on mac. Result is %cpu is 0 on mac. end |
#has?(method_name) ⇒ Boolean
because apparently respond_to doesn’t work through method_missing
156 157 158 |
# File 'lib/server_metrics/collectors/processes.rb', line 156 def has?(method_name) @pts.respond_to?(method_name) end |