vmstat 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +100 -110
- data/ext/vmstat/vmstat.c +133 -140
- data/ext/vmstat/vmstat.h +11 -18
- data/lib/vmstat.rb +79 -37
- data/lib/vmstat/cpu.rb +4 -0
- data/lib/vmstat/disk.rb +20 -0
- data/lib/vmstat/load_average.rb +4 -0
- data/lib/vmstat/memory.rb +24 -0
- data/lib/vmstat/network_interface.rb +19 -0
- data/lib/vmstat/snapshot.rb +17 -0
- data/lib/vmstat/task.rb +6 -0
- data/lib/vmstat/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/vmstat/cpu_spec.rb +34 -0
- data/spec/vmstat/disk_spec.rb +32 -0
- data/spec/vmstat/load_average_spec.rb +23 -0
- data/spec/vmstat/memory_spec.rb +44 -0
- data/spec/vmstat/network_spec.rb +38 -0
- data/spec/vmstat/snapshot_spec.rb +49 -0
- data/spec/vmstat/task_spec.rb +28 -0
- data/spec/vmstat_spec.rb +20 -161
- metadata +25 -4
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vmstat::Snapshot do
|
4
|
+
context "Vmstat#snapshot" do
|
5
|
+
let(:snapshot) { Vmstat.snapshot }
|
6
|
+
subject { snapshot }
|
7
|
+
|
8
|
+
it "should be an vmstat load snapshot object" do
|
9
|
+
should be_a(Vmstat::Snapshot)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "methods" do
|
13
|
+
it { should respond_to(:at) }
|
14
|
+
it { should respond_to(:boot_time) }
|
15
|
+
it { should respond_to(:cpu) }
|
16
|
+
it { should respond_to(:disks) }
|
17
|
+
it { should respond_to(:load_average) }
|
18
|
+
it { should respond_to(:memory) }
|
19
|
+
it { should respond_to(:network_interfaces) }
|
20
|
+
it { should respond_to(:task) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "content" do
|
24
|
+
its(:at) { should be_a(Time) }
|
25
|
+
its(:boot_time) { should be_a(Time) }
|
26
|
+
its(:cpu) { should be_a(Array) }
|
27
|
+
its(:disks) { should be_a(Array) }
|
28
|
+
its(:load_average) { should be_a(Vmstat::LoadAverage) }
|
29
|
+
its(:memory) { should be_a(Vmstat::Memory) }
|
30
|
+
its(:network_interfaces) { should be_a(Array) }
|
31
|
+
its(:task) { should be_a(Vmstat::Task) }
|
32
|
+
|
33
|
+
context "first of cpu" do
|
34
|
+
subject { snapshot.cpu.first }
|
35
|
+
it { should be_a(Vmstat::Cpu) }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "first of disks" do
|
39
|
+
subject { snapshot.disks.first }
|
40
|
+
it { should be_a(Vmstat::Disk) }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "first of network interfaces" do
|
44
|
+
subject { snapshot.network_interfaces.first }
|
45
|
+
it { should be_a(Vmstat::NetworkInterface) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vmstat::Task do
|
4
|
+
context "Vmstat#task" do
|
5
|
+
let(:task) { Vmstat.task }
|
6
|
+
subject { task }
|
7
|
+
|
8
|
+
it "should be a vmstat task object" do
|
9
|
+
should be_a(Vmstat::Task)
|
10
|
+
end
|
11
|
+
|
12
|
+
context "methods" do
|
13
|
+
it { should respond_to(:suspend_count) }
|
14
|
+
it { should respond_to(:virtual_size) }
|
15
|
+
it { should respond_to(:resident_size) }
|
16
|
+
it { should respond_to(:user_time_ms) }
|
17
|
+
it { should respond_to(:system_time_ms) }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "content" do
|
21
|
+
its(:suspend_count) { should be_a_kind_of(Numeric) }
|
22
|
+
its(:virtual_size) { should be_a_kind_of(Numeric) }
|
23
|
+
its(:resident_size) { should be_a_kind_of(Numeric) }
|
24
|
+
its(:user_time_ms) { should be_a_kind_of(Numeric) }
|
25
|
+
its(:system_time_ms) { should be_a_kind_of(Numeric) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/vmstat_spec.rb
CHANGED
@@ -1,165 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'ostruct'
|
3
2
|
|
4
3
|
describe Vmstat do
|
5
|
-
context "#network" do
|
6
|
-
let(:network) { Vmstat.network }
|
7
|
-
|
8
|
-
it "should return the enthernet and loopback network data as hash" do
|
9
|
-
network.should be_a(Hash)
|
10
|
-
end
|
11
|
-
|
12
|
-
context "loopback device" do
|
13
|
-
let(:loopback) { network[:lo0] }
|
14
|
-
subject { loopback }
|
15
|
-
|
16
|
-
it "should contain the a loopback device info also as a hash" do
|
17
|
-
should be_a(Hash)
|
18
|
-
end
|
19
|
-
|
20
|
-
context "keys" do
|
21
|
-
it { should have_key(:in_bytes) }
|
22
|
-
it { should have_key(:out_bytes) }
|
23
|
-
it { should have_key(:in_errors) }
|
24
|
-
it { should have_key(:out_errors) }
|
25
|
-
it { should have_key(:in_drops) }
|
26
|
-
it { should have_key(:type) }
|
27
|
-
end
|
28
|
-
|
29
|
-
context "type" do
|
30
|
-
subject { OpenStruct.new loopback }
|
31
|
-
|
32
|
-
its(:in_bytes) { should be_a_kind_of(Numeric) }
|
33
|
-
its(:out_bytes) { should be_a_kind_of(Numeric) }
|
34
|
-
its(:in_errors) { should be_a_kind_of(Numeric) }
|
35
|
-
its(:out_errors) { should be_a_kind_of(Numeric) }
|
36
|
-
its(:in_drops) { should be_a_kind_of(Numeric) }
|
37
|
-
its(:type) { should be_a_kind_of(Numeric) }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "#cpu" do
|
43
|
-
let(:cpu) { Vmstat.cpu }
|
44
|
-
|
45
|
-
it "should return an array of ethernet information" do
|
46
|
-
cpu.should be_a(Array)
|
47
|
-
end
|
48
|
-
|
49
|
-
context "first cpu" do
|
50
|
-
let(:first_cpu) { cpu.first }
|
51
|
-
subject { first_cpu }
|
52
|
-
|
53
|
-
it "should return a hash containing per cpu information" do
|
54
|
-
should be_a(Hash)
|
55
|
-
end
|
56
|
-
|
57
|
-
context "keys" do
|
58
|
-
it { should have_key(:user) }
|
59
|
-
it { should have_key(:system) }
|
60
|
-
it { should have_key(:nice) }
|
61
|
-
it { should have_key(:idle) }
|
62
|
-
end
|
63
|
-
|
64
|
-
context "type" do
|
65
|
-
subject { OpenStruct.new first_cpu }
|
66
|
-
|
67
|
-
its(:user) { should be_a_kind_of(Numeric) }
|
68
|
-
its(:system) { should be_a_kind_of(Numeric) }
|
69
|
-
its(:nice) { should be_a_kind_of(Numeric) }
|
70
|
-
its(:idle) { should be_a_kind_of(Numeric) }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "#memory" do
|
76
|
-
let(:memory) { Vmstat.memory }
|
77
|
-
subject { memory }
|
78
|
-
|
79
|
-
it "should be a hash of memory data" do
|
80
|
-
should be_a(Hash)
|
81
|
-
end
|
82
|
-
|
83
|
-
context "keys" do
|
84
|
-
it { should have_key(:pagesize) }
|
85
|
-
it { should have_key(:wired) }
|
86
|
-
it { should have_key(:active) }
|
87
|
-
it { should have_key(:inactive) }
|
88
|
-
it { should have_key(:free) }
|
89
|
-
it { should have_key(:wired_bytes) }
|
90
|
-
it { should have_key(:active_bytes) }
|
91
|
-
it { should have_key(:inactive_bytes) }
|
92
|
-
it { should have_key(:free_bytes) }
|
93
|
-
it { should have_key(:zero_filled) }
|
94
|
-
it { should have_key(:reactivated) }
|
95
|
-
it { should have_key(:faults) }
|
96
|
-
it { should have_key(:copy_on_write_faults) }
|
97
|
-
end
|
98
|
-
|
99
|
-
context "type" do
|
100
|
-
subject { OpenStruct.new memory }
|
101
|
-
|
102
|
-
its(:pagesize) { should be_a_kind_of(Numeric) }
|
103
|
-
its(:wired) { should be_a_kind_of(Numeric) }
|
104
|
-
its(:active) { should be_a_kind_of(Numeric) }
|
105
|
-
its(:inactive) { should be_a_kind_of(Numeric) }
|
106
|
-
its(:free) { should be_a_kind_of(Numeric) }
|
107
|
-
its(:wired_bytes) { should be_a_kind_of(Numeric) }
|
108
|
-
its(:active_bytes) { should be_a_kind_of(Numeric) }
|
109
|
-
its(:inactive_bytes) { should be_a_kind_of(Numeric) }
|
110
|
-
its(:free_bytes) { should be_a_kind_of(Numeric) }
|
111
|
-
its(:zero_filled) { should be_a_kind_of(Numeric) }
|
112
|
-
its(:reactivated) { should be_a_kind_of(Numeric) }
|
113
|
-
its(:faults) { should be_a_kind_of(Numeric) }
|
114
|
-
its(:copy_on_write_faults) { should be_a_kind_of(Numeric) }
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "#disk" do
|
119
|
-
let(:disk) { Vmstat.disk("/") }
|
120
|
-
subject { disk }
|
121
|
-
|
122
|
-
it "should be a hash of disk data" do
|
123
|
-
should be_a(Hash)
|
124
|
-
end
|
125
|
-
|
126
|
-
context "keys" do
|
127
|
-
it { should have_key(:type) }
|
128
|
-
it { should have_key(:origin) }
|
129
|
-
it { should have_key(:mount) }
|
130
|
-
it { should have_key(:free_bytes) }
|
131
|
-
it { should have_key(:available_bytes) }
|
132
|
-
it { should have_key(:used_bytes) }
|
133
|
-
it { should have_key(:total_bytes) }
|
134
|
-
end
|
135
|
-
|
136
|
-
context "type" do
|
137
|
-
subject { OpenStruct.new disk }
|
138
|
-
|
139
|
-
its(:type) { should be_a(Symbol) }
|
140
|
-
its(:origin) { should be_a(String) }
|
141
|
-
its(:mount) { should be_a(String) }
|
142
|
-
its(:free_bytes) { should be_a_kind_of(Numeric) }
|
143
|
-
its(:available_bytes) { should be_a_kind_of(Numeric) }
|
144
|
-
its(:used_bytes) { should be_a_kind_of(Numeric) }
|
145
|
-
its(:total_bytes) { should be_a_kind_of(Numeric) }
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context "#load_avg" do
|
150
|
-
subject { Vmstat.load_avg }
|
151
|
-
|
152
|
-
it "should be an array" do
|
153
|
-
should be_a(Array)
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should have three floats" do
|
157
|
-
subject[0].should be_a(Float)
|
158
|
-
subject[1].should be_a(Float)
|
159
|
-
subject[2].should be_a(Float)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
4
|
context "#boot_time" do
|
164
5
|
let(:boot_time) { Vmstat.boot_time }
|
165
6
|
|
@@ -171,8 +12,8 @@ describe Vmstat do
|
|
171
12
|
boot_time.should < Time.now
|
172
13
|
end
|
173
14
|
end
|
174
|
-
|
175
|
-
context "#filter_devices" do
|
15
|
+
|
16
|
+
context "Vmstat#filter_devices" do
|
176
17
|
it "should filter ethernet devices" do
|
177
18
|
Vmstat.ethernet_devices.size.should == 2
|
178
19
|
end
|
@@ -181,4 +22,22 @@ describe Vmstat do
|
|
181
22
|
Vmstat.loopback_devices.size.should == 1
|
182
23
|
end
|
183
24
|
end
|
25
|
+
|
26
|
+
context "performance" do
|
27
|
+
shared_examples "a not memory leaking method" do |method_name, *args|
|
28
|
+
it "should not grow the memory in method #{method_name} more than 10% " do
|
29
|
+
mem_before = Vmstat.task.resident_size
|
30
|
+
10000.times { Vmstat.send(method_name, *args) }
|
31
|
+
mem_after = Vmstat.task.resident_size
|
32
|
+
mem_after.should < (mem_before * 1.10)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it_should_behave_like "a not memory leaking method", :network_interfaces
|
37
|
+
it_should_behave_like "a not memory leaking method", :cpu
|
38
|
+
it_should_behave_like "a not memory leaking method", :memory
|
39
|
+
it_should_behave_like "a not memory leaking method", :disk, "/"
|
40
|
+
it_should_behave_like "a not memory leaking method", :boot_time
|
41
|
+
it_should_behave_like "a not memory leaking method", :load_average
|
42
|
+
end
|
184
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmstat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
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: 2012-09
|
12
|
+
date: 2012-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -63,8 +63,22 @@ files:
|
|
63
63
|
- ext/vmstat/vmstat.c
|
64
64
|
- ext/vmstat/vmstat.h
|
65
65
|
- lib/vmstat.rb
|
66
|
+
- lib/vmstat/cpu.rb
|
67
|
+
- lib/vmstat/disk.rb
|
68
|
+
- lib/vmstat/load_average.rb
|
69
|
+
- lib/vmstat/memory.rb
|
70
|
+
- lib/vmstat/network_interface.rb
|
71
|
+
- lib/vmstat/snapshot.rb
|
72
|
+
- lib/vmstat/task.rb
|
66
73
|
- lib/vmstat/version.rb
|
67
74
|
- spec/spec_helper.rb
|
75
|
+
- spec/vmstat/cpu_spec.rb
|
76
|
+
- spec/vmstat/disk_spec.rb
|
77
|
+
- spec/vmstat/load_average_spec.rb
|
78
|
+
- spec/vmstat/memory_spec.rb
|
79
|
+
- spec/vmstat/network_spec.rb
|
80
|
+
- spec/vmstat/snapshot_spec.rb
|
81
|
+
- spec/vmstat/task_spec.rb
|
68
82
|
- spec/vmstat_spec.rb
|
69
83
|
- vmstat.gemspec
|
70
84
|
homepage: http://threez.github.com/ruby-vmstat/
|
@@ -81,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
95
|
version: '0'
|
82
96
|
segments:
|
83
97
|
- 0
|
84
|
-
hash:
|
98
|
+
hash: -488329950864303377
|
85
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
100
|
none: false
|
87
101
|
requirements:
|
@@ -90,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
104
|
version: '0'
|
91
105
|
segments:
|
92
106
|
- 0
|
93
|
-
hash:
|
107
|
+
hash: -488329950864303377
|
94
108
|
requirements: []
|
95
109
|
rubyforge_project:
|
96
110
|
rubygems_version: 1.8.24
|
@@ -99,4 +113,11 @@ specification_version: 3
|
|
99
113
|
summary: A focused and fast library t gather system information
|
100
114
|
test_files:
|
101
115
|
- spec/spec_helper.rb
|
116
|
+
- spec/vmstat/cpu_spec.rb
|
117
|
+
- spec/vmstat/disk_spec.rb
|
118
|
+
- spec/vmstat/load_average_spec.rb
|
119
|
+
- spec/vmstat/memory_spec.rb
|
120
|
+
- spec/vmstat/network_spec.rb
|
121
|
+
- spec/vmstat/snapshot_spec.rb
|
122
|
+
- spec/vmstat/task_spec.rb
|
102
123
|
- spec/vmstat_spec.rb
|