Class: PrometheusExporter::Ext::Instrumentation::ProcCpu

Inherits:
PeriodicStats show all
Defined in:
lib/prometheus_exporter/ext/instrumentation/proc_cpu.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PeriodicStats

started?, stop

Methods inherited from BaseStats

#type

Constructor Details

#initializeProcCpu

Returns a new instance of ProcCpu.



18
19
20
21
# File 'lib/prometheus_exporter/ext/instrumentation/proc_cpu.rb', line 18

def initialize(...)
  @last_cpu_time = 0.0
  super
end

Class Method Details

.start(type:, labels: {}) ⇒ Object



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

def start(type:, labels: {}, **)
  labels = labels.merge(type:)

  super(labels:, **)
end

Instance Method Details

#collectObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/prometheus_exporter/ext/instrumentation/proc_cpu.rb', line 23

def collect
  stat = PrometheusExporter::Ext::ProcSelfStat.get
  collect_data(
    labels: {
      pid: stat.pid,
      hostname: ::PrometheusExporter.hostname
    },
    usage_seconds_total: stat.cpu_time - @last_cpu_time
  )
  @last_cpu_time = stat.cpu_time
end