Sha256: ba1d18a3a360f8fc9561ca8fab16bacf41156feea20ac116bf4290db7b8e7da8

Contents?: true

Size: 911 Bytes

Versions: 7

Compression:

Stored size: 911 Bytes

Contents

require "server_metrics/system_info"

class ServerMetrics::Network < ServerMetrics::MultiCollector

  def build_report

    if linux?
      lines = File.read("/proc/net/dev").lines.to_a[2..-1]
      interfaces = []
      lines.each do |line|
        iface, rest = line.split(':', 2).collect { |e| e.strip }
        interfaces << iface
        next unless iface =~ /venet|eth/
        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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
server_metrics-1.2.3 lib/server_metrics/collectors/network.rb
server_metrics-1.2.3.pre lib/server_metrics/collectors/network.rb
server_metrics-1.2.2 lib/server_metrics/collectors/network.rb
server_metrics-1.2.2.pre lib/server_metrics/collectors/network.rb
server_metrics-1.2.1 lib/server_metrics/collectors/network.rb
server_metrics-1.2.0 lib/server_metrics/collectors/network.rb
server_metrics-1.2.0.pre lib/server_metrics/collectors/network.rb