<commit_before>require "server_metrics/system_info"

class ServerMetrics::Network < ServerMetrics::MultiCollector

  def build_report
    if linux?
      lines = File.read("#{ServerMetrics::SystemInfo.proc_dir}/net/dev").lines.to_a[2..-1]
      interfaces = []
      lines.each do |line|
        iface, rest = line.split(':', 2).collect { |e| e.strip }
        interfaces << iface
        next if iface =~ /lo/
        found = true
        cols = rest.split(/\s+/)

        bytes_in, packets_in, bytes_out, packets_out = cols.values_at(0, 1, 8, 9).collect { |i| i.to_i }

        counter(iface, :bytes_in, bytes_in.to_f / 1024.0, :per => :second, :round => 2)
        counter(iface, :packets_in, packets_in.to_f, :per => :second, :round => 2)
        counter(iface, :bytes_out, bytes_out.to_f / 1024.0, :per => :second, :round => 2)
        counter(iface, :packets_out, packets_out.to_f, :per => :second, :round => 2)
      end
    end
  end
end<commit_msg>Dont report docker/lxc/etc vethXXXX interfaces<commit_after>require "server_metrics/system_info"

class ServerMetrics::Network < ServerMetrics::MultiCollector

  def build_report
    if linux?
      lines = File.read("#{ServerMetrics::SystemInfo.proc_dir}/net/dev").lines.to_a[2..-1]
      interfaces = []
      lines.each do |line|
        iface, rest = line.split(':', 2).collect { |e| e.strip }
        interfaces << iface
        next if iface =~ /^(lo|veth\w{4,})$/
        found = true
        cols = rest.split(/\s+/)

        bytes_in, packets_in, bytes_out, packets_out = cols.values_at(0, 1, 8, 9).collect { |i| i.to_i }

        counter(iface, :bytes_in, bytes_in.to_f / 1024.0, :per => :second, :round => 2)
        counter(iface, :packets_in, packets_in.to_f, :per => :second, :round => 2)
        counter(iface, :bytes_out, bytes_out.to_f / 1024.0, :per => :second, :round => 2)
        counter(iface, :packets_out, packets_out.to_f, :per => :second, :round => 2)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.15749235474006115, 'fraction_numerical': 0.021916411824668705, 'mean_word_length': 2.8794466403162056, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1873105', 'n_tokens_mistral': 740, 'n_tokens_neox': 702, 'n_words': 153}