class Solanum::Source::Network
bytes - The total number of bytes of data transmitted or received by the interface. packets - The total number of packets of data transmitted or received by the interface. errs - The total number of transmit or receive errors detected by the device driver. drop - The total number of packets dropped by the device driver. fifo - The number of FIFO buffer errors. frame - The number of packet framing errors. colls - The number of collisions detected on the interface. compressed - The number of compressed packets transmitted or received by the device driver. (This appears to be unused in the 2.2.15 kernel.) carrier - The number of carrier losses detected by the device driver. multicast - The number of multicast frames transmitted or received by the device driver.
Constants
- FIELDS
- SIMPLE_FIELDS
- STAT_FILE
Attributes
Public Class Methods
Solanum::Source::new
# File lib/solanum/source/network.rb, line 26 def initialize(opts) super(opts) @interfaces = opts['interfaces'] || [] @detailed = opts['detailed'] || false @last = {} end
Public Instance Methods
# File lib/solanum/source/network.rb, line 41 def collect! events = [] File.readlines(STAT_FILE).drop(2).each do |line| iface, stats = parse_stats(line) if @interfaces.empty? || @interfaces.include?(iface) if @last[iface] FIELDS.each do |field| next unless @detailed || SIMPLE_FIELDS.include?(field) diff = stats[field] - @last[iface][field] events << { service: "net #{iface} #{field.gsub('_', ' ')}", metric: diff, } end end @last[iface] = stats end end events end
# File lib/solanum/source/network.rb, line 34 def parse_stats(line) columns = line.strip.split(/\s+/) iface = columns.shift.chomp(':') return iface, Hash[FIELDS.zip(columns.map(&:to_i))] end