Class: ServerMetrics::Processes::Process

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(proctable_struct) ⇒ Process

Returns a new instance of Process.



144
145
146
147
# File 'lib/server_metrics/collectors/processes.rb', line 144

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



154
155
156
# File 'lib/server_metrics/collectors/processes.rb', line 154

def method_missing(sym, *args, &block)
  @pts.send sym, *args, &block
end

Instance Attribute Details

#recent_cpuObject

used to store the calculation of CPU since last sample



143
144
145
# File 'lib/server_metrics/collectors/processes.rb', line 143

def recent_cpu
  @recent_cpu
end

#recent_cpu_percentageObject

used to store the calculation of CPU since last sample



143
144
145
# File 'lib/server_metrics/collectors/processes.rb', line 143

def recent_cpu_percentage
  @recent_cpu_percentage
end

Instance Method Details

#combined_cpuObject



148
149
150
151
152
# File 'lib/server_metrics/collectors/processes.rb', line 148

def combined_cpu
  # best thread I've seen on cutime vs utime & cstime vs stime: https://www.ruby-forum.com/topic/93176
  # trying the metric that doesn't include the consumption of child processes
  utime + stime
end