Class: SystemInformation::Linux::Net

Inherits:
Object
  • Object
show all
Defined in:
lib/systeminformation/linux/net.rb

Instance Method Summary collapse

Constructor Details

#initializeNet

Returns a new instance of Net.



4
5
6
7
# File 'lib/systeminformation/linux/net.rb', line 4

def initialize
  @prev_data = get_data
	@prev_time = Time.now
end

Instance Method Details

#throughputObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/systeminformation/linux/net.rb', line 9

def throughput
  new_data = get_data
  difference ={}
	delta = Time.now - @prev_time
  @prev_data.keys.each{|k|
    difference[k] = @prev_data[k].zip(new_data[k]).map{|i| (i[1].to_f - i[0].to_f)/delta}
  }
  @prev_data = new_data
	@prev_time = Time.now
  result={}
  difference.each{|k,body|
    result[k] = {:rbytes => body[0], :rpackets => body[1], :sbytes => body[2], :spackets => body[3]}
  }
  result
end