Class: PrometheusExporter::Ext::ProcSelfStat
- Inherits:
-
Object
- Object
- PrometheusExporter::Ext::ProcSelfStat
- 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
-
#comm ⇒ Object
readonly
Returns the value of attribute comm.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#rss ⇒ Object
readonly
Returns the value of attribute rss.
-
#starttime ⇒ Object
readonly
Returns the value of attribute starttime.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#stime ⇒ Object
readonly
Returns the value of attribute stime.
-
#utime ⇒ Object
readonly
Returns the value of attribute utime.
-
#vsize ⇒ Object
readonly
Returns the value of attribute vsize.
Class Method Summary collapse
Instance Method Summary collapse
- #cpu_time ⇒ Float
-
#initialize(*fields) ⇒ ProcSelfStat
constructor
A new instance of ProcSelfStat.
- #inspect ⇒ Object
- #rss_bytes ⇒ Integer
- #to_a ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
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
#comm ⇒ Object (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 |
#pid ⇒ Object (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 |
#rss ⇒ Object (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 |
#starttime ⇒ Object (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 |
#state ⇒ Object (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 |
#stime ⇒ Object (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 |
#utime ⇒ Object (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 |
#vsize ⇒ Object (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
.get ⇒ Object
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_time ⇒ 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 |
#inspect ⇒ Object
70 71 72 |
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 70 def inspect to_s end |
#rss_bytes ⇒ Integer
45 46 47 |
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 45 def rss_bytes rss * KERNEL_PAGE_SIZE end |
#to_a ⇒ Object
49 50 51 |
# File 'lib/prometheus_exporter/ext/proc_self_stat.rb', line 49 def to_a @fields.dup end |
#to_h ⇒ Object
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_s ⇒ Object
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 |