lib/Dysnomia/linux.rb in Dysnomia-0.0.1 vs lib/Dysnomia/linux.rb in Dysnomia-0.0.2
- old
+ new
@@ -1,10 +1,15 @@
module Dysnomia
class << self
@@ipv4_file = "/proc/net/sockstat"
@@ipv6_file = "/proc/net/sockstat6"
+ @@memory_file = "/proc/meminfo"
+ @@load_avarange_file = "/proc/loadavg"
+
+ @@bw_file = "/proc/net/dev"
+
def disk_usage
# return gib
# execute command
@@ -95,9 +100,52 @@
$l = pro.chomp.split(' ')
$return_array << $l.first + "," + $l.last
end
$return_array
+
+ end
+
+
+ def memory_used
+
+ # get memory used percent
+ $result = nil
+ if File.exist?(@@memory_file)
+ File.open(@@memory_file, "r") do |mem|
+ $result = mem.read
+ end
+ end
+
+ if ! nil?
+ $m = $result.split("\n").collect{|x| x.strip}
+ $total = $m[0].gsub(/[^0-9]/, "")
+ $active = $m[5].gsub(/[^0-9]/, "")
+
+ # Calc active memory
+ $calc = ($active.to_f * 100) / $total.to_f
+
+ # Round calc
+ $calc.rond
+
+ else
+ $result = "Memory file not found !"
+ end
+ end
+
+
+ def average_load
+ # get average load of the past minute
+
+ $load_data = nil
+
+ if File.exist?(@@load_avarange_file)
+ File.open(@@load_avarange_file,"r") do |load|
+ $load_data = load.read
+ end
+ end
+
+ $load_data = $load_data.split(/ /).first.to_s
end
def top_memory_processes