Class: GitLab::Exporter::ProcessStats

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_exporter/process.rb

Overview

A helper class to stats from /proc/<pid>/stat

See: man 5 proc

It takes a pid

Instance Method Summary collapse

Constructor Details

#initialize(pid) ⇒ ProcessStats

Returns a new instance of ProcessStats.



16
17
18
19
20
# File 'lib/gitlab_exporter/process.rb', line 16

def initialize(pid)
  @pid = pid
  @user_hertz = retrieve_user_hertz
  @stats = populate_info
end

Instance Method Details

#cpu_timeObject



26
27
28
# File 'lib/gitlab_exporter/process.rb', line 26

def cpu_time
  (@stats[14].to_i + @stats[15].to_i) / @user_hertz
end

#rssObject



39
40
41
42
# 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_timeObject



30
31
32
# File 'lib/gitlab_exporter/process.rb', line 30

def start_time
  @stats[22].to_i / @user_hertz
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/gitlab_exporter/process.rb', line 22

def valid?
  !@stats.nil?
end

#vsizeObject



34
35
36
37
# File 'lib/gitlab_exporter/process.rb', line 34

def vsize
  # Virtual memory size in bytes.
  @stats[23].to_i
end