Class: PrometheusExporter::Ext::ProcSelfStat

Inherits:
Object
  • Object
show all
Defined in:
lib/prometheus_exporter/ext/proc_self_stat.rb

Overview

Constant Summary collapse

KERNEL_PAGE_SIZE =

rubocop:disable Style/RescueModifier

`getconf PAGESIZE`.chomp.to_i rescue 4096
TICKS_PER_SEC =
Etc.sysconf(Etc::SC_CLK_TCK)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*fields) ⇒ ProcSelfStat

Returns a new instance of ProcSelfStat.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 27

def initialize(*fields)
  @pid = fields[0]
  @comm = fields[1]
  @state = fields[2]
  @utime = Integer(fields[13])
  @stime = Integer(fields[14])
  @starttime = Integer(fields[21])
  @vsize = Integer(fields[22])
  @rss = Integer(fields[23])
  @fields = fields
end

Instance Attribute Details

#commObject (readonly)

Returns the value of attribute comm.



18
19
20
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 18

def comm
  @comm
end

#pidObject (readonly)

Returns the value of attribute pid.



18
19
20
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 18

def pid
  @pid
end

#rssObject (readonly)

Returns the value of attribute rss.



18
19
20
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 18

def rss
  @rss
end

#starttimeObject (readonly)

Returns the value of attribute starttime.



18
19
20
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 18

def starttime
  @starttime
end

#stateObject (readonly)

Returns the value of attribute state.



18
19
20
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 18

def state
  @state
end

#stimeObject (readonly)

Returns the value of attribute stime.



18
19
20
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 18

def stime
  @stime
end

#utimeObject (readonly)

Returns the value of attribute utime.



18
19
20
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 18

def utime
  @utime
end

#vsizeObject (readonly)

Returns the value of attribute vsize.



18
19
20
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 18

def vsize
  @vsize
end

Class Method Details

.getObject



10
11
12
13
14
15
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 10

def get
  stat = File.read('/proc/self/stat')
  parts = stat.match(/\A(\d+)\s\((.*)\)\s([A-Z])\s(.*)/)[1..]
  rest = parts.pop.split
  new(*parts, *rest)
end

Instance Method Details

#cpu_timeFloat

Returns:

  • (Float)


40
41
42
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 40

def cpu_time
  (utime + stime).to_f / TICKS_PER_SEC
end

#inspectObject



70
71
72
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 70

def inspect
  to_s
end

#rss_bytesInteger

Returns:

  • (Integer)


45
46
47
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 45

def rss_bytes
  rss * KERNEL_PAGE_SIZE
end

#to_aObject



49
50
51
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 49

def to_a
  @fields.dup
end

#to_hObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 53

def to_h
  {
    pid:,
    comm:,
    state:,
    utime:,
    stime:,
    starttime:,
    vsize:,
    rss:
  }
end

#to_sObject



66
67
68
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 66

def to_s
  "#<#{self.class.name} #{to_h.map { |k, v| "#{k}=#{v.inspect}" }.join(' ')}>"
end