Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/usagewatch/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def self.uw_diskused
# Show the percentage of disk used.
def self.uw_diskused_perc
df = `df --total`
df.split(" ").last.to_f.round(2)

df.split(" ").reverse.each do |l|
return l.to_f.round(2) if l.include?("%")
end
end

# Show the percentage of CPU used
Expand Down Expand Up @@ -110,10 +113,14 @@ def self.uw_memused
end
end

@memstat = @result.split("\n").collect{|x| x.strip}
@memtotal = @memstat[0].gsub(/[^0-9]/, "")
@memactive = @memstat[5].gsub(/[^0-9]/, "")
@memactivecalc = (@memactive.to_f * 100) / @memtotal.to_f
memhash = Hash.new
@result.each_line do |l|
key, val = l.split(':')
if val.include?('kB') then val = val.gsub(/\s+kB/, ''); end
memhash["#{key}"] = val.strip
end

@memactivecalc = (memhash["Active"].to_f * 100) / memhash["MemTotal"].to_f
@memusagepercentage = @memactivecalc.round
end

Expand Down