Class: Fluent::Plugin::NodeExporter::LoadavgMetricsCollector

Inherits:
MetricsCollector show all
Defined in:
lib/fluent/plugin/node_exporter/loadavg_collector.rb

Instance Method Summary collapse

Methods inherited from MetricsCollector

#scan_sysfs_path

Constructor Details

#initialize(config = {}) ⇒ LoadavgMetricsCollector

Returns a new instance of LoadavgMetricsCollector.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fluent/plugin/node_exporter/loadavg_collector.rb', line 24

def initialize(config={})
  super(config)

  @load1 = CMetrics::Gauge.new
  @load1.create("node", "", "load1", "1m load average.")

  @load5 = CMetrics::Gauge.new
  @load5.create("node", "", "load5", "5m load average.")

  @load15 = CMetrics::Gauge.new
  @load15.create("node", "", "load15", "15m load average.")
end

Instance Method Details

#cmetricsObject



54
55
56
57
58
59
60
# File 'lib/fluent/plugin/node_exporter/loadavg_collector.rb', line 54

def cmetrics
  {
    loadavg1: @load1,
    loadavg5: @load5,
    loadavg15: @load15
  }
end

#loadavg_updateObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fluent/plugin/node_exporter/loadavg_collector.rb', line 41

def loadavg_update
  loadavg_path = File.join(@procfs_path, "/loadavg")
  # Use 1 explicitly for default gauge value
  fields = File.read(loadavg_path).split
  unless fields.size == 5
    $log.warn("invalid number of fields <#{loadavg_path}>: <#{fields.size}>")
    return
  end
  @load1.set(fields[0].to_f)
  @load5.set(fields[1].to_f)
  @load15.set(fields[2].to_f)
end

#runObject



37
38
39
# File 'lib/fluent/plugin/node_exporter/loadavg_collector.rb', line 37

def run
  loadavg_update
end