Browse files

make it run on linux

  • Loading branch information...
1 parent 9b0c8fa commit 1919e0cf20608117b532ccf6598bd48cc59f17d0 @tliff tliff committed Jun 7, 2010
Showing with 32 additions and 24 deletions.
  1. +23 −18 lib/systeminformation.rb
  2. +1 −1 lib/systeminformation/linux/cpu.rb
  3. +8 −5 lib/systeminformation/linux/net.rb
View
41 lib/systeminformation.rb
@@ -1,46 +1,51 @@
-os = [:unix, :linux]
-os.each do |o|
- if SystemInformation::OS::os == o
- Dir.glob(File.dirname(__FILE__) + "/#{o.to_s}/*.rb") do |i|
- require i
- end
- end
-end
-
+require 'lib/systeminformation/os.rb'
module SystemInformation
- def os
+ def self.os
OS::os
end
- def cpu
+ def self.cpu
if OS::linux?
@@cpu ||= Linux::CPU.new
@@cpu.utilization
end
end
- def load
+ def self.load
if OS::linux?
- Linux::Memory.usage
+ Linux::Load.load
end
end
- def net
+ def self.net
if OS::linux?
- Linux::Net.throughput
+ @@net ||= Linux::Net.new
+ @@net.throughput
end
end
- def memory
+ def self.memory
if OS::linux?
Linux::Memory.usage
end
end
- def users
+ def self.users
if OS::unix?
Unix::Users.loggedin
end
end
-end
+end
+
+os = [:unix, :linux]
+os.each do |o|
+ if SystemInformation::OS::os == o
+ puts (File.dirname(__FILE__) + "/systeminformation/#{o.to_s}/*.rb")
+ Dir.glob(File.dirname(__FILE__) + "/systeminformation/#{o.to_s}/*.rb") do |i|
+ puts "loading #{i}"
+ require i
+ end
+ end
+end
+
View
2 lib/systeminformation/linux/cpu.rb
@@ -1,6 +1,6 @@
module SystemInformation
module Linux
- module CPU
+ class CPU
def initialize
@prev_data = read_data
end
View
13 lib/systeminformation/linux/net.rb
@@ -1,17 +1,20 @@
module SystemInformation
module Linux
- module Net
- def initialize(args)
- @prev_data = get_data.call
+ class Net
+ def initialize
+ @prev_data = get_data
+ @prev_time = Time.now
end
def throughput
- new_data = get_data.call
+ 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]}
@@ -35,4 +38,4 @@ def get_data
end
end
end
-end
+end

0 comments on commit 1919e0c

Please sign in to comment.