usagewatch 0.0.6.beta1 → 0.0.6.beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +5 -0
- data/README.md +45 -17
- data/examples/linux_example.rb +21 -0
- data/examples/mac_example.rb +15 -0
- data/lib/usagewatch.rb +2 -1
- data/lib/usagewatch/linux.rb +13 -13
- data/lib/usagewatch/mac.rb +109 -0
- data/lib/usagewatch/version.rb +1 -1
- data/usagewatch.gemspec +2 -0
- metadata +13 -5
- data/examples/example.rb +0 -20
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -14,21 +14,21 @@ gem install usagewatch
|
|
14
14
|
```ruby
|
15
15
|
require 'usagewatch'
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
uw_diskused
|
20
|
-
uw_diskused_perc
|
21
|
-
uw_cpuused
|
22
|
-
uw_tcpused
|
23
|
-
uw_udpused
|
24
|
-
uw_memused
|
25
|
-
uw_load
|
26
|
-
uw_bandrx
|
27
|
-
uw_bandtx
|
28
|
-
uw_diskioreads
|
29
|
-
uw_diskiowrites
|
30
|
-
uw_cputop
|
31
|
-
uw_memtop
|
17
|
+
usw = Usagewatch
|
18
|
+
|
19
|
+
usw.uw_diskused
|
20
|
+
usw.uw_diskused_perc
|
21
|
+
usw.uw_cpuused
|
22
|
+
usw.uw_tcpused
|
23
|
+
usw.uw_udpused
|
24
|
+
usw.uw_memused
|
25
|
+
usw.uw_load
|
26
|
+
usw.uw_bandrx
|
27
|
+
usw.uw_bandtx
|
28
|
+
usw.uw_diskioreads
|
29
|
+
usw.uw_diskiowrites
|
30
|
+
usw.uw_cputop
|
31
|
+
usw.uw_memtop
|
32
32
|
```
|
33
33
|
|
34
34
|
## Example
|
@@ -36,7 +36,7 @@ uw_memtop
|
|
36
36
|
```bash
|
37
37
|
Run:
|
38
38
|
|
39
|
-
|
39
|
+
linux_example.rb
|
40
40
|
|
41
41
|
Example Output:
|
42
42
|
|
@@ -57,6 +57,34 @@ Top Ten Processes By Memory Consumption:
|
|
57
57
|
[["unicorn", "4.8"], ["unicorn", "4.7"], ["unicorn", "4.6"], ["unicorn", "4.6"], ["unicorn", "4.5"], ["unicorn", "4.5"], ["unicorn", "4.3"], ["unicorn", "4.3"], ["unicorn", "4.2"], ["/usr/lib64/erlang/erts-5.8.5/bin/beam.smp", "4.0"]]
|
58
58
|
```
|
59
59
|
|
60
|
+
|
61
|
+
## Methods available
|
62
|
+
|
63
|
+
##### Linux
|
64
|
+
uw_diskused
|
65
|
+
uw_diskused_perc
|
66
|
+
uw_cpuused
|
67
|
+
uw_tcpused
|
68
|
+
uw_udpused
|
69
|
+
uw_memused
|
70
|
+
uw_load
|
71
|
+
uw_bandrx
|
72
|
+
uw_bandtx
|
73
|
+
uw_diskioreads
|
74
|
+
uw_diskiowrites
|
75
|
+
uw_cputop
|
76
|
+
uw_memtop
|
77
|
+
|
78
|
+
##### Mac
|
79
|
+
uw_diskused
|
80
|
+
uw_diskused_perc
|
81
|
+
uw_cputop
|
82
|
+
uw_memtop
|
83
|
+
uw_load
|
84
|
+
uw_cpuused
|
85
|
+
uw_memused
|
86
|
+
|
87
|
+
|
60
88
|
## Notes
|
61
89
|
|
62
90
|
Disk Used is a sum of all partitions calculated in Gigabytes
|
@@ -85,4 +113,4 @@ RUBY VERSIONS:
|
|
85
113
|
ruby 1.9.3p429 (2013-05-15) [x86_64-linux]
|
86
114
|
|
87
115
|
OS VERSIONS:
|
88
|
-
CENTOS 5x 6x, Ubuntu 12.04, Fedora 18
|
116
|
+
CENTOS 5x 6x, Ubuntu 12.04, Fedora 18, Mountain Lion 10.8.4
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
#License: (MIT), Copyright (C) 2013 Author Phil Chen, Contributor Ruben Espinosa
|
4
|
+
|
5
|
+
require 'usagewatch'
|
6
|
+
|
7
|
+
usw = Usagewatch
|
8
|
+
|
9
|
+
puts "#{usw.uw_diskused} Gigabytes Used"
|
10
|
+
puts "#{usw.uw_diskused_perc} Perventage of Gigabytes Used"
|
11
|
+
puts "#{usw.uw_cpuused}% CPU Used"
|
12
|
+
puts "#{usw.uw_tcpused} TCP Connections Used"
|
13
|
+
puts "#{usw.uw_udpused} UDP Connections Used"
|
14
|
+
puts "#{usw.uw_memused}% Active Memory Used"
|
15
|
+
puts "#{usw.uw_load} Average System Load Of The Past Minute"
|
16
|
+
puts "#{usw.uw_bandrx} Mbit/s Current Bandwidth Received"
|
17
|
+
puts "#{usw.uw_bandtx} Mbit/s Current Bandwidth Transmitted"
|
18
|
+
puts "#{usw.uw_diskioreads}/s Current Disk Reads Completed"
|
19
|
+
puts "#{usw.uw_diskiowrites}/s Current Disk Writes Completed"
|
20
|
+
puts "Top Ten Processes By CPU Consumption: #{usw.uw_cputop}"
|
21
|
+
puts "Top Ten Processes By Memory Consumption: #{usw.uw_memtop}"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
#License: (MIT), Copyright (C) 2013 Author Phil Chen, Contributor Ruben Espinosa
|
4
|
+
|
5
|
+
require 'usagewatch'
|
6
|
+
|
7
|
+
usw = Usagewatch
|
8
|
+
|
9
|
+
puts "#{usw.uw_diskused} Gigabytes Used"
|
10
|
+
puts "#{usw.uw_diskused_perc} Percentage of Gigabytes Used"
|
11
|
+
puts "#{usw.uw_memused}% Active Memory Used"
|
12
|
+
puts "#{usw.uw_cpuused}% CPU Used"
|
13
|
+
puts "#{usw.uw_load} Average System Load Of The Past Minute"
|
14
|
+
puts "Top Ten Processes By CPU Consumption: #{usw.uw_cputop}"
|
15
|
+
puts "Top Ten Processes By Memory Consumption: #{usw.uw_memtop}"
|
data/lib/usagewatch.rb
CHANGED
@@ -6,7 +6,8 @@ os = RUBY_PLATFORM
|
|
6
6
|
text = "OS is not supported in this version."
|
7
7
|
|
8
8
|
if os.include? "darwin"
|
9
|
-
|
9
|
+
require "usagewatch/mac"
|
10
|
+
puts "Mac version is under development"
|
10
11
|
elsif os.include? "linux"
|
11
12
|
require "usagewatch/linux"
|
12
13
|
elsif os =~ /cygwin|mswin|mingw|bccwin|wince|emx/
|
data/lib/usagewatch/linux.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Usagewatch
|
2
|
-
def uw_diskused
|
2
|
+
def self.uw_diskused
|
3
3
|
@df = `df`
|
4
4
|
@parts = @df.split(" ").map { |s| s.to_i }
|
5
5
|
@sum = 0
|
@@ -11,12 +11,12 @@ module Usagewatch
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# Show the percentage of disk used.
|
14
|
-
def uw_diskused_perc
|
14
|
+
def self.uw_diskused_perc
|
15
15
|
df = `df --total`
|
16
16
|
df.split(" ").last.to_f.round(2)
|
17
17
|
end
|
18
18
|
|
19
|
-
def uw_cpuused
|
19
|
+
def self.uw_cpuused
|
20
20
|
@proc0 = File.readlines('/proc/stat').grep(/^cpu /).first.split(" ")
|
21
21
|
sleep 1
|
22
22
|
@proc1 = File.readlines('/proc/stat').grep(/^cpu /).first.split(" ")
|
@@ -41,7 +41,7 @@ module Usagewatch
|
|
41
41
|
|
42
42
|
# return hash of top ten proccesses by cpu consumption
|
43
43
|
# example [["apache2", 12.0], ["passenger", 13.2]]
|
44
|
-
def uw_cputop
|
44
|
+
def self.uw_cputop
|
45
45
|
ps = `ps aux | awk '{print $11, $3}' | sort -k2nr | head -n 10`
|
46
46
|
array = []
|
47
47
|
ps.each_line do |line|
|
@@ -52,7 +52,7 @@ module Usagewatch
|
|
52
52
|
end
|
53
53
|
|
54
54
|
|
55
|
-
def uw_tcpused
|
55
|
+
def self.uw_tcpused
|
56
56
|
if File.exists?("/proc/net/sockstat")
|
57
57
|
File.open("/proc/net/sockstat", "r") do |ipv4|
|
58
58
|
@sockstat = ipv4.read
|
@@ -75,7 +75,7 @@ module Usagewatch
|
|
75
75
|
@totaltcpused = @tcp4count.to_i + @tcp6count.to_i
|
76
76
|
end
|
77
77
|
|
78
|
-
def uw_udpused
|
78
|
+
def self.uw_udpused
|
79
79
|
if File.exists?("/proc/net/sockstat")
|
80
80
|
File.open("/proc/net/sockstat", "r") do |ipv4|
|
81
81
|
@sockstat = ipv4.read
|
@@ -97,7 +97,7 @@ module Usagewatch
|
|
97
97
|
@totaludpused = @udp4count.to_i + @udp6count.to_i
|
98
98
|
end
|
99
99
|
|
100
|
-
def uw_memused
|
100
|
+
def self.uw_memused
|
101
101
|
if File.exists?("/proc/meminfo")
|
102
102
|
File.open("/proc/meminfo", "r") do |file|
|
103
103
|
@result = file.read
|
@@ -113,7 +113,7 @@ module Usagewatch
|
|
113
113
|
|
114
114
|
# return hash of top ten proccesses by mem consumption
|
115
115
|
# example [["apache2", 12.0], ["passenger", 13.2]]
|
116
|
-
def uw_memtop
|
116
|
+
def self.uw_memtop
|
117
117
|
ps = `ps aux | awk '{print $11, $4}' | sort -k2nr | head -n 10`
|
118
118
|
array = []
|
119
119
|
ps.each_line do |line|
|
@@ -123,7 +123,7 @@ module Usagewatch
|
|
123
123
|
array
|
124
124
|
end
|
125
125
|
|
126
|
-
def uw_load
|
126
|
+
def self.uw_load
|
127
127
|
if File.exists?("/proc/loadavg")
|
128
128
|
File.open("/proc/loadavg", "r") do |file|
|
129
129
|
@loaddata = file.read
|
@@ -133,7 +133,7 @@ module Usagewatch
|
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
def uw_bandrx
|
136
|
+
def self.uw_bandrx
|
137
137
|
|
138
138
|
def bandrx
|
139
139
|
|
@@ -186,7 +186,7 @@ module Usagewatch
|
|
186
186
|
@megabitsreceived = (@bitsreceived.to_f / 1024 / 1024).round(3)
|
187
187
|
end
|
188
188
|
|
189
|
-
def uw_bandtx
|
189
|
+
def self.uw_bandtx
|
190
190
|
|
191
191
|
def bandtx
|
192
192
|
|
@@ -239,7 +239,7 @@ module Usagewatch
|
|
239
239
|
@megabitstransmitted = (@bitstransmitted.to_f / 1024 / 1024).round(3)
|
240
240
|
end
|
241
241
|
|
242
|
-
def uw_diskioreads
|
242
|
+
def self.uw_diskioreads
|
243
243
|
|
244
244
|
def diskio
|
245
245
|
|
@@ -288,7 +288,7 @@ module Usagewatch
|
|
288
288
|
@diskreads = @new1[0].to_i - @new0[0].to_i
|
289
289
|
end
|
290
290
|
|
291
|
-
def uw_diskiowrites
|
291
|
+
def self.uw_diskiowrites
|
292
292
|
|
293
293
|
def diskio
|
294
294
|
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module Usagewatch
|
2
|
+
|
3
|
+
# Show disk used in GB
|
4
|
+
def self.uw_diskused
|
5
|
+
df = `df -kl`
|
6
|
+
sum = 0.00
|
7
|
+
df.each_line.with_index do |line, line_index|
|
8
|
+
next if line_index.eql? 0
|
9
|
+
line = line.split(" ")
|
10
|
+
next if line[0] =~ /localhost/ #ignore backup filesystem
|
11
|
+
sum += ((line[2].to_f)/1024)/1024
|
12
|
+
end
|
13
|
+
sum.round(2)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Show the percentage of disk used.
|
17
|
+
def self.uw_diskused_perc
|
18
|
+
df = `df -kl`
|
19
|
+
total = 0.0
|
20
|
+
used = 0.0
|
21
|
+
df.each_line.with_index do |line, line_index|
|
22
|
+
next if line_index.eql? 0
|
23
|
+
line = line.split(" ")
|
24
|
+
next if line[0] =~ /localhost/ #ignore backup filesystem
|
25
|
+
total += ((line[3].to_f)/1024)/1024
|
26
|
+
used +=((line[2].to_f)/1024)/1024
|
27
|
+
end
|
28
|
+
((used/total) * 100).round(2)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Show the percentage of cpu used
|
32
|
+
def self.uw_cpuused
|
33
|
+
top = `top -l1 | awk '/CPU usage/'`
|
34
|
+
top = top.gsub(/[\,a-zA-Z:]/, "").split(" ")
|
35
|
+
top[0].to_f
|
36
|
+
end
|
37
|
+
|
38
|
+
# return hash of top ten proccesses by cpu consumption
|
39
|
+
# example [["apache2", 12.0], ["passenger", 13.2]]
|
40
|
+
def self.uw_cputop
|
41
|
+
ps = `ps aux | awk '{print $11, $3}' | sort -k2nr | head -n 10`
|
42
|
+
array = []
|
43
|
+
ps.each_line do |line|
|
44
|
+
line = line.chomp.split(" ")
|
45
|
+
array << [line.first.gsub(/[\[\]]/, "").split("/").last, line.last]
|
46
|
+
end
|
47
|
+
array
|
48
|
+
end
|
49
|
+
|
50
|
+
# todo
|
51
|
+
#def uw_tcpused
|
52
|
+
#
|
53
|
+
#end
|
54
|
+
|
55
|
+
# todo
|
56
|
+
#def uw_udpused
|
57
|
+
#
|
58
|
+
#end
|
59
|
+
|
60
|
+
# return hash of top ten proccesses by mem consumption
|
61
|
+
# example [["apache2", 12.0], ["passenger", 13.2]]
|
62
|
+
def self.uw_memtop
|
63
|
+
ps = `ps aux | awk '{print $11, $4}' | sort -k2nr | head -n 10`
|
64
|
+
array = []
|
65
|
+
ps.each_line do |line|
|
66
|
+
line = line.chomp.split(" ")
|
67
|
+
array << [line.first.gsub(/[\[\]]/, "").split("/").last, line.last]
|
68
|
+
end
|
69
|
+
array
|
70
|
+
end
|
71
|
+
|
72
|
+
# Percentage of mem used
|
73
|
+
def self.uw_memused
|
74
|
+
top = `top -l1 | awk '/PhysMem/'`
|
75
|
+
top = top.gsub(/[\.\,a-zA-Z:]/, "").split(" ").reverse
|
76
|
+
((top[1].to_f / (top[0].to_f + top[1].to_f)) * 100).round(2)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Show the average of load in the last minute
|
80
|
+
def self.uw_load
|
81
|
+
iostat = `iostat -w1 -c 2 | awk '{print $7}'`
|
82
|
+
cpu = 0.0
|
83
|
+
iostat.each_line.with_index do |line, line_index|
|
84
|
+
next if line_index.eql? 0 or line_index.eql? 1 or line_index.eql? 2
|
85
|
+
cpu = line.split(" ").last.to_f.round(2)
|
86
|
+
end
|
87
|
+
cpu
|
88
|
+
end
|
89
|
+
|
90
|
+
#todo
|
91
|
+
#def uw_bandrx
|
92
|
+
#
|
93
|
+
#end
|
94
|
+
|
95
|
+
#todo
|
96
|
+
#def uw_bandtx
|
97
|
+
#
|
98
|
+
#end
|
99
|
+
|
100
|
+
#todo
|
101
|
+
#def uw_diskioreads
|
102
|
+
#
|
103
|
+
#end
|
104
|
+
|
105
|
+
#todo
|
106
|
+
#def uw_diskiowrites
|
107
|
+
#
|
108
|
+
#end
|
109
|
+
end
|
data/lib/usagewatch/version.rb
CHANGED
data/usagewatch.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.summary = %q{Statistics on a Linux server}
|
13
13
|
spec.homepage = "https://github.com/nethacker/usagewatch"
|
14
14
|
spec.license = "MIT"
|
15
|
+
spec.rdoc_options << '--main' << 'README'
|
15
16
|
|
16
17
|
spec.files = `git ls-files`.split($/)
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -20,4 +21,5 @@ Gem::Specification.new do |spec|
|
|
20
21
|
|
21
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
23
|
spec.add_development_dependency "rake"
|
24
|
+
spec.post_install_message = "* Linux version are covered for our test.\n* Mac OS version is in development\nThanks for installing!"
|
23
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usagewatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.6.
|
4
|
+
version: 0.0.6.beta2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -57,16 +57,24 @@ files:
|
|
57
57
|
- LICENSE.txt
|
58
58
|
- README.md
|
59
59
|
- Rakefile
|
60
|
-
- examples/
|
60
|
+
- examples/linux_example.rb
|
61
|
+
- examples/mac_example.rb
|
61
62
|
- lib/usagewatch.rb
|
62
63
|
- lib/usagewatch/linux.rb
|
64
|
+
- lib/usagewatch/mac.rb
|
63
65
|
- lib/usagewatch/version.rb
|
64
66
|
- usagewatch.gemspec
|
65
67
|
homepage: https://github.com/nethacker/usagewatch
|
66
68
|
licenses:
|
67
69
|
- MIT
|
68
|
-
post_install_message:
|
69
|
-
|
70
|
+
post_install_message: ! '* Linux version are covered for our test.
|
71
|
+
|
72
|
+
* Mac OS version is in development
|
73
|
+
|
74
|
+
Thanks for installing!'
|
75
|
+
rdoc_options:
|
76
|
+
- --main
|
77
|
+
- README
|
70
78
|
require_paths:
|
71
79
|
- lib
|
72
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/examples/example.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
|
3
|
-
#License: (MIT), Copyright (C) 2013 Author Phil Chen, Contributor Ruben Espinosa
|
4
|
-
|
5
|
-
require 'usagewatch'
|
6
|
-
|
7
|
-
include Usagewatch
|
8
|
-
|
9
|
-
puts "#{uw_diskused} Gigabytes Used"
|
10
|
-
puts "#{uw_cpuused}% CPU Used"
|
11
|
-
puts "#{uw_tcpused} TCP Connections Used"
|
12
|
-
puts "#{uw_udpused} UDP Connections Used"
|
13
|
-
puts "#{uw_memused}% Active Memory Used"
|
14
|
-
puts "#{uw_load} Average System Load Of The Past Minute"
|
15
|
-
puts "#{uw_bandrx} Mbit/s Current Bandwidth Received"
|
16
|
-
puts "#{uw_bandtx} Mbit/s Current Bandwidth Transmitted"
|
17
|
-
puts "#{uw_diskioreads}/s Current Disk Reads Completed"
|
18
|
-
puts "#{uw_diskiowrites}/s Current Disk Writes Completed"
|
19
|
-
puts "Top Ten Processes By CPU Consumption: #{uw_cputop}"
|
20
|
-
puts "Top Ten Processes By Memory Consumption: #{uw_memtop}"
|