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
- #cmdline ⇒ Object
- #combined_cpu ⇒ Object
- #comm ⇒ 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.
-
#pid ⇒ Object
For better performance, not using #method_missing to just pass these off to ProcTable::Struct.
- #ppid ⇒ Object
- #rss ⇒ Object
- #set_recent_cpu(last_cpu, elapsed_jiffies, num_processors) ⇒ Object
- #stime ⇒ Object
- #utime ⇒ Object
Constructor Details
#initialize(proctable_struct) ⇒ Process
Returns a new instance of Process.
164 165 166 167 |
# File 'lib/server_metrics/collectors/processes.rb', line 164 def initialize(proctable_struct) @pts=proctable_struct @recent_cpu = 0 end |
Instance Attribute Details
#recent_cpu ⇒ Object
used to store the calculation of CPU since last sample
163 164 165 |
# File 'lib/server_metrics/collectors/processes.rb', line 163 def recent_cpu @recent_cpu end |
#recent_cpu_percentage ⇒ Object
used to store the calculation of CPU since last sample
163 164 165 |
# File 'lib/server_metrics/collectors/processes.rb', line 163 def recent_cpu_percentage @recent_cpu_percentage end |
Instance Method Details
#cmdline ⇒ Object
207 208 209 |
# File 'lib/server_metrics/collectors/processes.rb', line 207 def cmdline @pts.cmdline end |
#combined_cpu ⇒ Object
191 192 193 194 195 196 |
# File 'lib/server_metrics/collectors/processes.rb', line 191 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 |
#comm ⇒ Object
203 204 205 |
# File 'lib/server_metrics/collectors/processes.rb', line 203 def comm @comm ||= @pts.comm end |
#has?(method_name) ⇒ Boolean
because apparently respond_to doesn’t work through method_missing
170 171 172 |
# File 'lib/server_metrics/collectors/processes.rb', line 170 def has?(method_name) @pts.respond_to?(method_name) end |
#pid ⇒ Object
For better performance, not using #method_missing to just pass these off to ProcTable::Struct.
199 200 201 |
# File 'lib/server_metrics/collectors/processes.rb', line 199 def pid @pts.pid end |
#ppid ⇒ Object
211 212 213 |
# File 'lib/server_metrics/collectors/processes.rb', line 211 def ppid @pts.ppid end |
#rss ⇒ Object
223 224 225 |
# File 'lib/server_metrics/collectors/processes.rb', line 223 def rss @pts.rss end |
#set_recent_cpu(last_cpu, elapsed_jiffies, num_processors) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/server_metrics/collectors/processes.rb', line 174 def set_recent_cpu(last_cpu,elapsed_jiffies,num_processors) if last_cpu self.recent_cpu = combined_cpu - last_cpu else self.recent_cpu = combined_cpu # this process wasn't around last time, so just use the cumulative CPU time for its existence so far end # a) self.recent_cpu / elapsed_jiffies = the amount of CPU time this process has taken divided by the total "time slots" the CPU has available # b) * 100 ... this turns it into a percentage # b) / num_processors ... this normalizes for the the number of processors in the system, so it reflects the amount of CPU power avaiable as a whole self.recent_cpu_percentage = ((recent_cpu.to_f / elapsed_jiffies.to_f ) * 100.0) / num_processors.to_f end |
#stime ⇒ Object
219 220 221 |
# File 'lib/server_metrics/collectors/processes.rb', line 219 def stime @pts.stime end |
#utime ⇒ Object
215 216 217 |
# File 'lib/server_metrics/collectors/processes.rb', line 215 def utime @pts.utime end |