usagewatch_ext 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +139 -0
- data/Rakefile +7 -0
- data/examples/linux_example.rb +21 -0
- data/examples/mac_example.rb +15 -0
- data/lib/usagewatch_ext.rb +18 -0
- data/lib/usagewatch_ext/mac.rb +109 -0
- data/lib/usagewatch_ext/version.rb +3 -0
- data/spec/mac_spec.rb +74 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/usagewatch_spec.rb +126 -0
- data/spec/version_spec.rb +10 -0
- data/usagewatch_ext.gemspec +26 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODM3NDNhZWQwMzIzMjc1MTRmNmU0ZjRkMGExZDNkNDFhNDYyN2RlMg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NWNiZWQxYjJiNjQ0ZjExZGI0ODY1ZGZjODgzM2VjNWYwZWU1MGY4Yg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTg0M2I0MTc1MTAwYmMxMjM5Y2MyYjIzNzFmY2E2Mzc5N2U0NzdjNTZkZGVm
|
10
|
+
NDgxNzEwN2ZmNzY4YmRkODcxNTA4ZjRiNTZkOTYxNjdiNWRlODUwY2FjN2Q5
|
11
|
+
OTU4NGViNmVmODUxNmEzMmJlMTY5ZTJkNjFhMjAyZjEzMjIxOGI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OThhNzBhMjJiOGZkZDZjNmYzNmVmOGE5NzMxNzIxOWUzODg1NDA2YWEzMmVl
|
14
|
+
NjRhZDM3OGE5NDYxYjNhMmM4MWUxODAxYjc0ODk4YmI3NTQ1ZTY1OWMzYzll
|
15
|
+
MTBjNGM4NmRhNGE2MGNiMWI2N2Y3MDY1ZjdkYzQyYzI1ZjdmODk=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ruben Espinosa
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
[![Coverage Status](https://coveralls.io/repos/rderoldan1/usagewatch/badge.png)](https://coveralls.io/r/rderoldan1/usagewatch)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/usagewatch.png)](http://badge.fury.io/rb/usagewatch)
|
3
|
+
[![Build Status](https://travis-ci.org/rderoldan1/usagewatch.png?branch=master)](https://travis-ci.org/rderoldan1/usagewatch)
|
4
|
+
|
5
|
+
# usagewatch extended version
|
6
|
+
|
7
|
+
License: (MIT) Copyright (C) 2013 Author Ruben Espinosa.
|
8
|
+
|
9
|
+
## DESCRIPTION:
|
10
|
+
This project is based in [Usagewatch](https://github.com/rderoldan1/nethacker/usagewatch) gem written by Phil Chen, I try to expand the OS version, first with mac OS,
|
11
|
+
in future versions Windows will be include.
|
12
|
+
|
13
|
+
This is Ruby Gem with methods to find usage statistics on your system such as CPU, Disk, TCP/UDP Connections, Load,
|
14
|
+
Bandwidth, Disk I/O, and Memory, top processes by memory and cpu consumption
|
15
|
+
|
16
|
+
## Getting Started
|
17
|
+
|
18
|
+
gem install usagewatch_ext
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require 'usagewatch_ext'
|
22
|
+
|
23
|
+
usw = UsagewatchExt
|
24
|
+
|
25
|
+
usw.uw_diskused
|
26
|
+
usw.uw_diskused_perc
|
27
|
+
usw.uw_cpuused
|
28
|
+
usw.uw_tcpused
|
29
|
+
usw.uw_udpused
|
30
|
+
usw.uw_memused
|
31
|
+
usw.uw_load
|
32
|
+
usw.uw_bandrx
|
33
|
+
usw.uw_bandtx
|
34
|
+
usw.uw_diskioreads
|
35
|
+
usw.uw_diskiowrites
|
36
|
+
usw.uw_cputop
|
37
|
+
usw.uw_memtop
|
38
|
+
```
|
39
|
+
|
40
|
+
## Example
|
41
|
+
|
42
|
+
```bash
|
43
|
+
Run:
|
44
|
+
|
45
|
+
linux_example.rb
|
46
|
+
|
47
|
+
Example Output:
|
48
|
+
|
49
|
+
11.56 Gigabytes Disk Used
|
50
|
+
7.0% Disk Used
|
51
|
+
0.25% CPU Used
|
52
|
+
30 TCP Connections Used
|
53
|
+
0 UDP Connections Used
|
54
|
+
43% Active Memory Used
|
55
|
+
0.01 Average System Load Of The Past Minute
|
56
|
+
0.008 Mbit/s Current Bandwidth Received
|
57
|
+
0.2 Mbit/s Current Bandwidth Transmitted
|
58
|
+
0/s Current Disk Reads Completed
|
59
|
+
2/s Current Disk Writes Completed
|
60
|
+
Top Ten Processes By CPU Consumption:
|
61
|
+
[["/usr/lib64/erlang/erts-5.8.5/bin/beam.smp", "5.2"], ["ruby", "4.1"], ["ps", "2.0"], ["abrt-dump-oops", "0.8"], ["aoe_ktio", "0.7"], ["aoe_tx", "0.4"], ["ata_sff", "0.2"], ["auditd", "0.1"], ["awk", "0.1"], ["-bash", "0.1"]]
|
62
|
+
Top Ten Processes By Memory Consumption:
|
63
|
+
[["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"]]
|
64
|
+
```
|
65
|
+
|
66
|
+
```bash
|
67
|
+
Run:
|
68
|
+
|
69
|
+
mac_example.rb
|
70
|
+
|
71
|
+
Example Output:
|
72
|
+
|
73
|
+
Mac version is under development
|
74
|
+
92.8 Gigabytes Used
|
75
|
+
24.96 Percentage of Gigabytes Used
|
76
|
+
71.47% Active Memory Used
|
77
|
+
7.69% CPU Used
|
78
|
+
1.19 Average System Load Of The Past Minute
|
79
|
+
Top Ten Processes By CPU Consumption: [["PluginProcess", "9.0"], ["WindowServer", "2.7"], ["iPhoto", "1.2"], ["Terminal", "1.0"], ["rubymine", "0.5"], ["SystemUIServer", "0.1"], ["(scanunit)", "0.0"], ["(scanunit)", "0.0"], ["(scanunit)", "0.0"], ["(scanunit)", "0.0"]]
|
80
|
+
Top Ten Processes By Memory Consumption: [["WebProcess", "8.3"], ["rubymine", "6.4"], ["Safari", "2.0"], ["iPhoto", "1.8"], ["Mail", "1.7"], ["mds", "1.6"], ["ruby", "1.5"], ["WindowServer", "1.3"], ["PluginProcess", "1.2"], ["GitHub", "1.1"]]
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
## Methods available
|
85
|
+
|
86
|
+
##### Linux
|
87
|
+
uw_diskused
|
88
|
+
uw_diskused_perc
|
89
|
+
uw_cpuused
|
90
|
+
uw_tcpused
|
91
|
+
uw_udpused
|
92
|
+
uw_memused
|
93
|
+
uw_load
|
94
|
+
uw_bandrx
|
95
|
+
uw_bandtx
|
96
|
+
uw_diskioreads
|
97
|
+
uw_diskiowrites
|
98
|
+
uw_cputop
|
99
|
+
uw_memtop
|
100
|
+
|
101
|
+
##### Mac
|
102
|
+
uw_diskused
|
103
|
+
uw_diskused_perc
|
104
|
+
uw_cputop
|
105
|
+
uw_memtop
|
106
|
+
uw_load
|
107
|
+
uw_cpuused
|
108
|
+
uw_memused
|
109
|
+
|
110
|
+
|
111
|
+
## Notes
|
112
|
+
|
113
|
+
Disk Used is a sum of all partitions calculated in Gigabytes
|
114
|
+
|
115
|
+
Disk Used Percentage is a total percentage of all disk partitions used
|
116
|
+
|
117
|
+
CPU Used is a percentage of current CPU being used
|
118
|
+
|
119
|
+
TCP/UDP Connections Used is a total count of each respectively
|
120
|
+
|
121
|
+
Active Memory Used is a percentage of active system memory being used
|
122
|
+
|
123
|
+
Load is the average load of the past minute
|
124
|
+
|
125
|
+
Bandwidth is current received and transmitted in Megabits
|
126
|
+
|
127
|
+
Disk IO is current disk reads and writes completed per second
|
128
|
+
|
129
|
+
Top Ten Processes By CPU Consumption are based on percent CPU used
|
130
|
+
|
131
|
+
Top Ten Processes By Memory Consumption are base on percent Memory used
|
132
|
+
|
133
|
+
## Tested Using
|
134
|
+
|
135
|
+
RUBY VERSIONS:
|
136
|
+
ruby 1.9.3p429 (2013-05-15) [x86_64-linux]
|
137
|
+
|
138
|
+
OS VERSIONS:
|
139
|
+
CENTOS 5x 6x, Ubuntu 12.04, Fedora 18, Mountain Lion 10.8.4
|
data/Rakefile
ADDED
@@ -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_ext'
|
6
|
+
|
7
|
+
usw = UsagewatchExt
|
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}"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "usagewatch_ext/version"
|
2
|
+
|
3
|
+
module UsagewatchExt
|
4
|
+
os = RUBY_PLATFORM
|
5
|
+
text = "OS is not supported in this version."
|
6
|
+
|
7
|
+
if os.include? "darwin"
|
8
|
+
require "usagewatch_ext/mac"
|
9
|
+
puts "Mac version is under development"
|
10
|
+
elsif os.include? "linux"
|
11
|
+
require "usagewatch/linux"
|
12
|
+
elsif os =~ /cygwin|mswin|mingw|bccwin|wince|emx/
|
13
|
+
puts "Windows" + text
|
14
|
+
else
|
15
|
+
puts "This" + text
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module UsagewatchExt
|
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/spec/mac_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
os = RUBY_PLATFORM
|
5
|
+
if os.include? "darwin"
|
6
|
+
describe 'IncludeLibrary' do
|
7
|
+
it 'should include the library' do
|
8
|
+
a = UsagewatchExt
|
9
|
+
a.should be UsagewatchExt
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'DiskUsage' do
|
14
|
+
it "should be the GB of disk used" do
|
15
|
+
a = UsagewatchExt.uw_diskused
|
16
|
+
a.class.should be(Float)
|
17
|
+
a.should_not be_nil
|
18
|
+
a.should be >= 0
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'CPUUsage' do
|
23
|
+
it "should be the percentage of cpu used" do
|
24
|
+
a = UsagewatchExt.uw_cpuused
|
25
|
+
a.class.should be(Float)
|
26
|
+
a.should_not be_nil
|
27
|
+
a.should be <= 100
|
28
|
+
a.should be >= 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'PercentageDiskUsage' do
|
33
|
+
it "should be the percentage of GB of disk used" do
|
34
|
+
a = UsagewatchExt.uw_diskused_perc
|
35
|
+
a.class.should be(Float)
|
36
|
+
a.should_not be_nil
|
37
|
+
a.should be <= 100
|
38
|
+
a.should be >= 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'LoadAverage' do
|
43
|
+
it "should be the average load of the past minute" do
|
44
|
+
a = UsagewatchExt.uw_load
|
45
|
+
a.class.should be(Float)
|
46
|
+
a.should_not be_nil
|
47
|
+
a.should be >= 0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'TopCPUUsage' do
|
52
|
+
it "should be an array of top cpu consumption proccesses " do
|
53
|
+
a = UsagewatchExt.uw_cputop
|
54
|
+
a.class.should be(Array )
|
55
|
+
a.should_not be_nil
|
56
|
+
a[0][0].class.should be String
|
57
|
+
a[0][1].class.should be String
|
58
|
+
a.count.should be == 10
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'TopMEMUsage' do
|
63
|
+
it "should be an array of top mem consumption proccesses " do
|
64
|
+
a = UsagewatchExt.uw_cputop
|
65
|
+
a.class.should be(Array )
|
66
|
+
a.should_not be_nil
|
67
|
+
a[0][0].class.should be String
|
68
|
+
a[0][1].class.should be String
|
69
|
+
a.count.should be == 10
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
os = RUBY_PLATFORM
|
5
|
+
if os.include? "linux"
|
6
|
+
describe 'IncludeLibrary' do
|
7
|
+
it 'should include the library' do
|
8
|
+
a = Usagewatch
|
9
|
+
a.should be Usagewatch
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'DiskUsage' do
|
14
|
+
it "should be the GB of disk used" do
|
15
|
+
a = Usagewatch.uw_diskused
|
16
|
+
a.class.should be(Float)
|
17
|
+
a.should_not be_nil
|
18
|
+
a.should be >= 0
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'CPUUsage' do
|
23
|
+
it "should be the percentage of cpu used" do
|
24
|
+
a = Usagewatch.uw_cpuused
|
25
|
+
a.class.should be(Float)
|
26
|
+
a.should_not be_nil
|
27
|
+
a.should be <= 100
|
28
|
+
a.should be >= 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'PercentageDiskUsage' do
|
33
|
+
it "should be the percentage of GB of disk used" do
|
34
|
+
a = Usagewatch.uw_diskused_perc
|
35
|
+
a.class.should be(Float)
|
36
|
+
a.should_not be_nil
|
37
|
+
a.should be <= 100
|
38
|
+
a.should be >= 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'LoadAverage' do
|
43
|
+
it "should be the average load of the past minute" do
|
44
|
+
a = Usagewatch.uw_load
|
45
|
+
a.class.should be(Float)
|
46
|
+
a.should_not be_nil
|
47
|
+
a.should be >= 0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'TopCPUUsage' do
|
52
|
+
it "should be an array of top cpu consumption proccesses " do
|
53
|
+
a = Usagewatch.uw_cputop
|
54
|
+
a.class.should be(Array )
|
55
|
+
a.should_not be_nil
|
56
|
+
a[0][0].class.should be String
|
57
|
+
a[0][1].class.should be String
|
58
|
+
a.count.should be == 10
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'TopMEMUsage' do
|
63
|
+
it "should be an array of top mem consumption proccesses " do
|
64
|
+
a = Usagewatch.uw_cputop
|
65
|
+
a.class.should be(Array )
|
66
|
+
a.should_not be_nil
|
67
|
+
a[0][0].class.should be String
|
68
|
+
a[0][1].class.should be String
|
69
|
+
a.count.should be == 10
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'TCPConnectios' do
|
74
|
+
it 'should TCP Connections Used' do
|
75
|
+
a = Usagewatch.uw_tcpused
|
76
|
+
a.class.should be Fixnum
|
77
|
+
a.should_not be_nil
|
78
|
+
a.should be >= 0
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'UDPConections' do
|
83
|
+
it 'should UDP Connections Used ' do
|
84
|
+
a = Usagewatch.uw_udpused
|
85
|
+
a.class.should be Fixnum
|
86
|
+
a.should_not be_nil
|
87
|
+
a.should be >= 0
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'DiskREADS' do
|
92
|
+
it 'should be current disk reads ' do
|
93
|
+
a = Usagewatch.uw_diskioreads
|
94
|
+
a.class.should be Fixnum
|
95
|
+
a.should_not be_nil
|
96
|
+
a.should be >= 0
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe 'DiskWrites' do
|
101
|
+
it 'should be current disk writes ' do
|
102
|
+
a = Usagewatch.uw_diskiowrites
|
103
|
+
a.class.should be Fixnum
|
104
|
+
a.should_not be_nil
|
105
|
+
a.should be >= 0
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'Bandwidth' do
|
110
|
+
it 'should be current received ' do
|
111
|
+
a = Usagewatch.uw_bandrx
|
112
|
+
a.class.should be Float
|
113
|
+
a.should_not be_nil
|
114
|
+
a.should be >= 0
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'Bandwidth' do
|
119
|
+
it 'should be current received ' do
|
120
|
+
a = Usagewatch.uw_bandtx
|
121
|
+
a.class.should be Float
|
122
|
+
a.should_not be_nil
|
123
|
+
a.should be >= 0
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'usagewatch_ext/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "usagewatch_ext"
|
8
|
+
spec.version = UsagewatchExt::VERSION
|
9
|
+
spec.authors = ["Ruben Espinosa"]
|
10
|
+
spec.email = ["rderoldan1@gmail.com"]
|
11
|
+
spec.description = %q{A Ruby Gem with methods to find usage statistics such as CPU, Disk, TCP/UDP Connections, Load, Bandwidth, Disk I/O, and Memory}
|
12
|
+
spec.summary = %q{Extended version of usagewatch}
|
13
|
+
spec.homepage = "https://github.com/rderoldan1/usagewatch_ext"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.rdoc_options << '--main' << 'README'
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
spec.add_runtime_dependency('usagewatch', '~> 0.0.6')
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: usagewatch_ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ruben Espinosa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: usagewatch
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A Ruby Gem with methods to find usage statistics such as CPU, Disk, TCP/UDP
|
70
|
+
Connections, Load, Bandwidth, Disk I/O, and Memory
|
71
|
+
email:
|
72
|
+
- rderoldan1@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- .travis.yml
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- examples/linux_example.rb
|
85
|
+
- examples/mac_example.rb
|
86
|
+
- lib/usagewatch_ext.rb
|
87
|
+
- lib/usagewatch_ext/mac.rb
|
88
|
+
- lib/usagewatch_ext/version.rb
|
89
|
+
- spec/mac_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/usagewatch_spec.rb
|
92
|
+
- spec/version_spec.rb
|
93
|
+
- usagewatch_ext.gemspec
|
94
|
+
homepage: https://github.com/rderoldan1/usagewatch_ext
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options:
|
100
|
+
- --main
|
101
|
+
- README
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.0.3
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Extended version of usagewatch
|
120
|
+
test_files:
|
121
|
+
- spec/mac_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
- spec/usagewatch_spec.rb
|
124
|
+
- spec/version_spec.rb
|