-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from rderoldan1/master
Mac Info ! :D
- Loading branch information
Showing
8 changed files
with
207 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/ruby | ||
|
||
#License: (MIT), Copyright (C) 2013 Author Phil Chen, Contributor Ruben Espinosa | ||
|
||
require 'usagewatch' | ||
|
||
usw = Usagewatch | ||
|
||
puts "#{usw.uw_diskused} Gigabytes Used" | ||
puts "#{usw.uw_diskused_perc} Perventage of Gigabytes Used" | ||
puts "#{usw.uw_cpuused}% CPU Used" | ||
puts "#{usw.uw_tcpused} TCP Connections Used" | ||
puts "#{usw.uw_udpused} UDP Connections Used" | ||
puts "#{usw.uw_memused}% Active Memory Used" | ||
puts "#{usw.uw_load} Average System Load Of The Past Minute" | ||
puts "#{usw.uw_bandrx} Mbit/s Current Bandwidth Received" | ||
puts "#{usw.uw_bandtx} Mbit/s Current Bandwidth Transmitted" | ||
puts "#{usw.uw_diskioreads}/s Current Disk Reads Completed" | ||
puts "#{usw.uw_diskiowrites}/s Current Disk Writes Completed" | ||
puts "Top Ten Processes By CPU Consumption: #{usw.uw_cputop}" | ||
puts "Top Ten Processes By Memory Consumption: #{usw.uw_memtop}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/ruby | ||
|
||
#License: (MIT), Copyright (C) 2013 Author Phil Chen, Contributor Ruben Espinosa | ||
|
||
require 'usagewatch' | ||
|
||
usw = Usagewatch | ||
|
||
puts "#{usw.uw_diskused} Gigabytes Used" | ||
puts "#{usw.uw_diskused_perc} Percentage of Gigabytes Used" | ||
puts "#{usw.uw_memused}% Active Memory Used" | ||
puts "#{usw.uw_cpuused}% CPU Used" | ||
puts "#{usw.uw_load} Average System Load Of The Past Minute" | ||
puts "Top Ten Processes By CPU Consumption: #{usw.uw_cputop}" | ||
puts "Top Ten Processes By Memory Consumption: #{usw.uw_memtop}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
module Usagewatch | ||
|
||
# Show disk used in GB | ||
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 | ||
|
||
# Show the percentage of disk used. | ||
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 | ||
|
||
# Show the percentage of cpu used | ||
def self.uw_cpuused | ||
top = `top -l1 | awk '/CPU usage/'` | ||
top = top.gsub(/[\,a-zA-Z:]/, "").split(" ") | ||
top[0].to_f | ||
end | ||
|
||
# return hash of top ten proccesses by cpu consumption | ||
# example [["apache2", 12.0], ["passenger", 13.2]] | ||
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 | ||
|
||
# todo | ||
#def uw_tcpused | ||
# | ||
#end | ||
|
||
# todo | ||
#def uw_udpused | ||
# | ||
#end | ||
|
||
# return hash of top ten proccesses by mem consumption | ||
# example [["apache2", 12.0], ["passenger", 13.2]] | ||
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 | ||
|
||
# Percentage of mem used | ||
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 | ||
|
||
# Show the average of load in the last minute | ||
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 | ||
|
||
#todo | ||
#def uw_bandrx | ||
# | ||
#end | ||
|
||
#todo | ||
#def uw_bandtx | ||
# | ||
#end | ||
|
||
#todo | ||
#def uw_diskioreads | ||
# | ||
#end | ||
|
||
#todo | ||
#def uw_diskiowrites | ||
# | ||
#end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters