class Fluent::Plugin::NodeExporter::NetdevMetricsCollector
Constants
- RECEIVE_FIELDS
- TRANSMIT_FIELDS
Public Class Methods
new(config={})
click to toggle source
Calls superclass method
Fluent::Plugin::NodeExporter::MetricsCollector::new
# File lib/fluent/plugin/node_exporter/netdev_collector.rb, line 25 def initialize(config={}) super(config) @metrics = {} RECEIVE_FIELDS.each_with_index do |field, index| metric_name = "receive_#{field}_total" @counter = CMetrics::Counter.new @counter.create("node", "network", metric_name, "Network device statistic #{metric_name}.", ["device"]) @metrics[metric_name.intern] = @counter end TRANSMIT_FIELDS.each_with_index do |field, index| metric_name = "transmit_#{field}_total" @counter = CMetrics::Counter.new @counter.create("node", "network", metric_name, "Network device statistic #{metric_name}.", ["device"]) @metrics[metric_name.intern] = @counter end end
Public Instance Methods
cmetrics()
click to toggle source
# File lib/fluent/plugin/node_exporter/netdev_collector.rb, line 86 def cmetrics @metrics end
netdev_update()
click to toggle source
# File lib/fluent/plugin/node_exporter/netdev_collector.rb, line 62 def netdev_update netdev_path = File.join(@procfs_path, "net/dev") File.readlines(netdev_path).each_with_index do |line, index| # net/dev must be 3 columns if index == 0 and line.split("|").size != 3 break end # first 2 line are header (Inter-face/Receive/Transmit) next if index < 2 interface, *values = line.split interface.delete!(":") RECEIVE_FIELDS.each_with_index do |field, index| metric_name = "receive_#{field}_total" @metrics[metric_name.intern].set(values[index].to_f, [interface]) end TRANSMIT_FIELDS.each_with_index do |field, index| metric_name = "transmit_#{field}_total" @metrics[metric_name.intern].set(values[index + RECEIVE_FIELDS.size].to_f, [interface]) end end end
run()
click to toggle source
# File lib/fluent/plugin/node_exporter/netdev_collector.rb, line 43 def run netdev_update end
target_devices()
click to toggle source
# File lib/fluent/plugin/node_exporter/netdev_collector.rb, line 50 def target_devices devices = [] netdev_path = File.join(@procfs_path, "net/dev") File.readlines(netdev_path).each_with_index do |line, index| next if index < 2 interface, _ = line.split interface.delete!(":") devices << interface end devices end