Module: UsagewatchExt
- Defined in:
- lib/usagewatch_ext.rb,
lib/usagewatch_ext/mac.rb,
lib/usagewatch_ext/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
-
.uw_cputop ⇒ Object
return hash of top ten proccesses by cpu consumption example [[“apache2”, 12.0], [“passenger”, 13.2]].
-
.uw_cpuused ⇒ Object
Show the percentage of cpu used.
-
.uw_diskused ⇒ Object
Show disk used in GB.
-
.uw_diskused_perc ⇒ Object
Show the percentage of disk used.
-
.uw_load ⇒ Object
Show the average of load in the last minute.
-
.uw_memtop ⇒ Object
return hash of top ten proccesses by mem consumption example [[“apache2”, 12.0], [“passenger”, 13.2]].
-
.uw_memused ⇒ Object
Percentage of mem used.
Class Method Details
.uw_cputop ⇒ Object
return hash of top ten proccesses by cpu consumption example [[“apache2”, 12.0], [“passenger”, 13.2]]
40 41 42 43 44 45 46 47 48 |
# File 'lib/usagewatch_ext/mac.rb', line 40 def self.uw_cputop ps = `ps aux | awk '{print $11, $3}' | sort -k2nr | head -n 10` array = [] ps.each_line do |line| line = line.chomp.split(" ") array << [line.first.gsub(/[\[\]]/, "").split("/").last, line.last] end array end |
.uw_cpuused ⇒ Object
Show the percentage of cpu used
32 33 34 35 36 |
# File 'lib/usagewatch_ext/mac.rb', line 32 def self.uw_cpuused top = `top -l1 | awk '/CPU usage/'` top = top.gsub(/[\,a-zA-Z:]/, "").split(" ") top[0].to_f end |
.uw_diskused ⇒ Object
Show disk used in GB
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/usagewatch_ext/mac.rb', line 4 def self.uw_diskused df = `df -kl` sum = 0.00 df.each_line.with_index do |line, line_index| next if line_index.eql? 0 line = line.split(" ") next if line[0] =~ /localhost/ #ignore backup filesystem sum += ((line[2].to_f)/1024)/1024 end sum.round(2) end |
.uw_diskused_perc ⇒ Object
Show the percentage of disk used.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/usagewatch_ext/mac.rb', line 17 def self.uw_diskused_perc df = `df -kl` total = 0.0 used = 0.0 df.each_line.with_index do |line, line_index| next if line_index.eql? 0 line = line.split(" ") next if line[0] =~ /localhost/ #ignore backup filesystem total += ((line[3].to_f)/1024)/1024 used +=((line[2].to_f)/1024)/1024 end ((used/total) * 100).round(2) end |
.uw_load ⇒ Object
Show the average of load in the last minute
80 81 82 83 84 85 86 87 88 |
# File 'lib/usagewatch_ext/mac.rb', line 80 def self.uw_load iostat = `iostat -w1 -c 2 | awk '{print $7}'` cpu = 0.0 iostat.each_line.with_index do |line, line_index| next if line_index.eql? 0 or line_index.eql? 1 or line_index.eql? 2 cpu = line.split(" ").last.to_f.round(2) end cpu end |
.uw_memtop ⇒ Object
return hash of top ten proccesses by mem consumption example [[“apache2”, 12.0], [“passenger”, 13.2]]
62 63 64 65 66 67 68 69 70 |
# File 'lib/usagewatch_ext/mac.rb', line 62 def self.uw_memtop ps = `ps aux | awk '{print $11, $4}' | sort -k2nr | head -n 10` array = [] ps.each_line do |line| line = line.chomp.split(" ") array << [line.first.gsub(/[\[\]]/, "").split("/").last, line.last] end array end |
.uw_memused ⇒ Object
Percentage of mem used
73 74 75 76 77 |
# File 'lib/usagewatch_ext/mac.rb', line 73 def self.uw_memused top = `top -l1 | awk '/PhysMem/'` top = top.gsub(/[\.\,a-zA-Z:]/, "").split(" ").reverse ((top[1].to_f / (top[0].to_f + top[1].to_f)) * 100).round(2) end |