class GitLab::Exporter::ProcessStats
A helper class to stats from /proc/<pid>/stat
See: man 5 proc
It takes a pid
Public Class Methods
new(pid)
click to toggle source
# File lib/gitlab_exporter/process.rb, line 16 def initialize(pid) @pid = pid @user_hertz = retrieve_user_hertz @stats = populate_info end
Public Instance Methods
cpu_time()
click to toggle source
# File lib/gitlab_exporter/process.rb, line 26 def cpu_time (@stats[14].to_i + @stats[15].to_i) / @user_hertz end
rss()
click to toggle source
# File lib/gitlab_exporter/process.rb, line 39 def rss # Resident Set Size: number of pages the process has in real memory. @stats[24].to_i * 4096 end
start_time()
click to toggle source
# File lib/gitlab_exporter/process.rb, line 30 def start_time @stats[22].to_i / @user_hertz end
valid?()
click to toggle source
# File lib/gitlab_exporter/process.rb, line 22 def valid? !@stats.nil? end
vsize()
click to toggle source
# File lib/gitlab_exporter/process.rb, line 34 def vsize # Virtual memory size in bytes. @stats[23].to_i end
Private Instance Methods
populate_info()
click to toggle source
# File lib/gitlab_exporter/process.rb, line 46 def populate_info # Pad the array by one element to make field numbers match the man page. [""].concat(File.read("/proc/#{@pid}/stat").split(" ")) rescue Errno::ENOENT nil end
retrieve_user_hertz()
click to toggle source
# File lib/gitlab_exporter/process.rb, line 53 def retrieve_user_hertz Process.clock_getres(:TIMES_BASED_CLOCK_PROCESS_CPUTIME_ID, :hertz) rescue Errno::EINVAL 100.0 end