Class: Fluent::Plugin::NodeExporter::FilefdMetricsCollector

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

Instance Method Summary collapse

Methods inherited from MetricsCollector

#scan_sysfs_path

Constructor Details

#initialize(config = {}) ⇒ FilefdMetricsCollector

Returns a new instance of FilefdMetricsCollector.



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

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

  @allocated = CMetrics::Gauge.new
  @allocated.create("node", "filefd", "allocated", "File descriptor statistics: allocated.")

  @maximum = CMetrics::Gauge.new
  @maximum.create("node", "filefd", "maximum", "File descriptor statistics: maximum.")
end

Instance Method Details

#cmetricsObject



51
52
53
54
55
56
# File 'lib/fluent/plugin/node_exporter/filefd_collector.rb', line 51

def cmetrics
  {
    filefd_allocated: @allocated,
    filefd_maximum: @maximum
  }
end

#filefd_updateObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fluent/plugin/node_exporter/filefd_collector.rb', line 38

def filefd_update
  # Etc.uname returns at least sysname,release,version,machine,nodename
  # but it is not guaranteed to return domainname.
  file_nr_path = File.join(@procfs_path, "/sys/fs/file-nr")
  entry = File.read(file_nr_path).split
  unless entry.size == 3
    $log.warn("invalid number of field <#{file_nr_path}>: #{entry.size}")
    return
  end
  @allocated.set(entry.first.to_f)
  @maximum.set(entry.last.to_f)
end

#runObject



34
35
36
# File 'lib/fluent/plugin/node_exporter/filefd_collector.rb', line 34

def run
  filefd_update
end