Class: Fluent::Plugin::NodeExporter::StatMetricsCollector

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

Instance Method Summary collapse

Methods inherited from MetricsCollector

#scan_sysfs_path

Constructor Details

#initialize(config = {}) ⇒ StatMetricsCollector

Returns a new instance of StatMetricsCollector.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fluent/plugin/node_exporter/stat_collector.rb', line 24

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

  @intr_total = CMetrics::Counter.new
  @intr_total.create("node", "", "intr_total", "Total number of interrupts serviced.")

  @context_switches_total = CMetrics::Counter.new
  @context_switches_total.create("node", "", "context_switches_total", "Total number of context switches.")

  @forks_total = CMetrics::Counter.new
  @forks_total.create("node", "", "forks_total", "Total number of forks.")

  @boot_time_seconds = CMetrics::Gauge.new
  @boot_time_seconds.create("node", "", "boot_time_seconds", "Node boot time, in unixtime.")

  @procs_running = CMetrics::Gauge.new
  @procs_running.create("node", "", "procs_running", "Number of processes in runnable state.")

  @procs_blocked = CMetrics::Gauge.new
  @procs_blocked.create("node", "", "procs_blocked", "Number of processes blocked waiting for I/O to complete.")
end

Instance Method Details

#cmetricsObject



71
72
73
74
75
76
77
78
79
80
# File 'lib/fluent/plugin/node_exporter/stat_collector.rb', line 71

def cmetrics
  {
    intr_total: @intr_total,
    context_switches_total: @context_switches_total,
    forks_total: @forks_total,
    boot_time_seconds: @boot_time_seconds,
    procs_running: @procs_running,
    procs_blocked: @procs_blocked
  }
end

#runObject



46
47
48
# File 'lib/fluent/plugin/node_exporter/stat_collector.rb', line 46

def run
  stat_update
end

#stat_updateObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fluent/plugin/node_exporter/stat_collector.rb', line 50

def stat_update
  stat_path = File.join(@procfs_path, "stat")
  File.readlines(stat_path).each do |line|
    entry, value, _ = line.split
    case entry
    when "intr"
      @intr_total.set(value.to_f)
    when "ctxt"
      @context_switches_total.set(value.to_f)
    when "btime"
      @boot_time_seconds.set(value.to_f)
    when "processes"
      @forks_total.set(value.to_f)
    when "procs_running"
      @procs_running.set(value.to_f)
    when "procs_blocked"
      @procs_blocked.set(value.to_f)
    end
  end
end