Module: SystemInformation

Defined in:
lib/systeminformation.rb,
lib/systeminformation/os.rb,
lib/systeminformation/linux/cpu.rb,
lib/systeminformation/linux/net.rb,
lib/systeminformation/linux/load.rb,
lib/systeminformation/unix/users.rb,
lib/systeminformation/linux/memory.rb

Defined Under Namespace

Modules: Linux, OS

Class Method Summary collapse

Class Method Details

.cpuObject

Returns a hash of { "cpuid" => { :idle => 1.0, :user => 0.0, ... }, ... }

The numerical values for each cpu sum up to 1.

Note: Since cpu utilisation is only defined for a time interval, the first call to this methods does not return meaningful data. It should be discarded and after a short time reexecuted. Subsequent calls will use the previous call as reference.



26
27
28
29
30
31
# File 'lib/systeminformation.rb', line 26

def self.cpu
  if OS::linux?
    @@cpu ||= Linux::CPU.new
    @@cpu.utilization
  end    
end

.loadObject

Returns a hash of { :load_1 =>0.0, :load_5 =>0.0, :load_15 =>0.0, :procs_running =>0.0, :procs_total =>0.0 }



43
44
45
46
47
# File 'lib/systeminformation.rb', line 43

def self.load
  if OS::linux?
    Linux::Load.load
  end    
end

.memoryObject

Returns a hash of items = { :free=>23340, :cached=>106052, :buffers=>10864, :total=>505492, :swaptotal=>916472, :swapfree=>782652, :used=>365236, :swapused=>133820 }

The unit is kilobyte blocks.



85
86
87
88
89
# File 'lib/systeminformation.rb', line 85

def self.memory
  if OS::linux?
    Linux::Memory.usage
  end
end

.netObject

Returns a hash of { "eth0" => { :rbytes => 0.0, :rpackets=>0.0, :sbytes=>0.0, :spackets=>0.0 }, ... }

values are bytes/second or packets/second respectively

Note: Since network throughput is only defined for a time interval, the first call to this methods does not return meaningful data. It should be discarded and after a short time reexecuted. Subsequent calls will use the previous call as reference.



66
67
68
69
70
71
# File 'lib/systeminformation.rb', line 66

def self.net
  if OS::linux?
    @@net ||= Linux::Net.new
    @@net.throughput
  end    
end

.osObject

Returns what operating system is running. Valid return values are :linux, :solaris, :bsd, :darwin, :windows and :unknown



6
7
8
# File 'lib/systeminformation.rb', line 6

def self.os
  OS::os
end

.usersObject

Returns the number of currently logged in users as an integer



92
93
94
95
96
# File 'lib/systeminformation.rb', line 92

def self.users
  if OS::unix?
    Unix::Users.loggedin
  end
end