class ServerMetrics::Processes::Process

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

Attributes

recent_cpu[RW]
recent_cpu_percentage[RW]

Public Class Methods

new(proctable_struct) click to toggle source
# File lib/server_metrics/collectors/processes.rb, line 164
def initialize(proctable_struct)
  @pts=proctable_struct
  @recent_cpu = 0
end

Public Instance Methods

cmdline() click to toggle source
# File lib/server_metrics/collectors/processes.rb, line 207
def cmdline
  @pts.cmdline
end
combined_cpu() click to toggle source
# 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() click to toggle source
# File lib/server_metrics/collectors/processes.rb, line 203
def comm
  @comm ||= @pts.comm
end
has?(method_name) click to toggle source

because apparently respond_to doesn't work through method_missing

# File lib/server_metrics/collectors/processes.rb, line 170
def has?(method_name)
  @pts.respond_to?(method_name)
end
pid() click to toggle source

For better performance, not using method_missing to just pass these off to ProcTable::Struct.

# File lib/server_metrics/collectors/processes.rb, line 199
def pid
  @pts.pid
end
ppid() click to toggle source
# File lib/server_metrics/collectors/processes.rb, line 211
def ppid
  @pts.ppid
end
rss() click to toggle source
# File lib/server_metrics/collectors/processes.rb, line 223
def rss
  @pts.rss
end
set_recent_cpu(last_cpu,elapsed_jiffies,num_processors) click to toggle source
# 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() click to toggle source
# File lib/server_metrics/collectors/processes.rb, line 219
def stime
  @pts.stime
end
utime() click to toggle source
# File lib/server_metrics/collectors/processes.rb, line 215
def utime
  @pts.utime
end