disk-stats 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -0
- data/Gemfile.lock +12 -0
- data/LICENSE.txt +20 -0
- data/Rakefile +10 -0
- data/VERSION +1 -0
- data/disk-stats.gemspec +47 -0
- data/lib/disk-stats.rb +63 -0
- data/test/helper.rb +4 -0
- data/test/test_disk_stats.rb +111 -0
- metadata +88 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Edward Muller
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/disk-stats.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'disk-stats'
|
3
|
+
s.version = "0.0.1"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Edward Muller"]
|
7
|
+
s.date = "2012-01-26"
|
8
|
+
s.description = 'Some stuff for dealing with /proc/diskstats'
|
9
|
+
s.email = "edward@heroku.com"
|
10
|
+
s.extra_rdoc_files = [
|
11
|
+
"LICENSE.txt"
|
12
|
+
]
|
13
|
+
s.files = [
|
14
|
+
"Gemfile",
|
15
|
+
"Gemfile.lock",
|
16
|
+
"LICENSE.txt",
|
17
|
+
"Rakefile",
|
18
|
+
"VERSION",
|
19
|
+
"disk-stats.gemspec",
|
20
|
+
"lib/disk-stats.rb",
|
21
|
+
"test/helper.rb",
|
22
|
+
"test/test_disk_stats.rb"
|
23
|
+
]
|
24
|
+
s.homepage = "http://github.com/freeformz/disk-stats"
|
25
|
+
s.licenses = ["MIT"]
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
s.rubygems_version = "1.8.10"
|
28
|
+
s.summary = 'Some stuff for dealing with /proc/diskstats'
|
29
|
+
|
30
|
+
if s.respond_to? :specification_version then
|
31
|
+
s.specification_version = 3
|
32
|
+
|
33
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
34
|
+
s.add_development_dependency(%q<minitest>, [">= 0"])
|
35
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.1.rc"])
|
36
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
37
|
+
else
|
38
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
39
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.rc"])
|
40
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
41
|
+
end
|
42
|
+
else
|
43
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
44
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.rc"])
|
45
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
46
|
+
end
|
47
|
+
end
|
data/lib/disk-stats.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module DiskStats
|
4
|
+
|
5
|
+
class ParseError < RuntimeError; end
|
6
|
+
|
7
|
+
class Device
|
8
|
+
LINE = Regexp.new('(\d+)\ +(\d+)\ ([\w-]+)\ (\d+)\ (\d+)\ (\d+)\ (\d+)\ (\d+)\ (\d+)\ (\d+)\ (\d+)\ (\d+)\ (\d+)\ (\d+)')
|
9
|
+
|
10
|
+
def initialize line
|
11
|
+
unless @line = LINE.match(line)
|
12
|
+
raise DiskStats::ParseError.new("Error parsing line: #{line}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def major; @line[1].to_i; end
|
17
|
+
def minor; @line[2].to_i; end
|
18
|
+
def name; @line[3]; end
|
19
|
+
def reads_completed; @line[4].to_i; end
|
20
|
+
def reads_merged; @line[5].to_i; end
|
21
|
+
def sectors_read; @line[6].to_i; end
|
22
|
+
def read_time; @line[7].to_i; end
|
23
|
+
def writes_completed; @line[8].to_i; end
|
24
|
+
def writes_merged; @line[9].to_i; end
|
25
|
+
def sectors_written; @line[10].to_i; end
|
26
|
+
def write_time; @line[11].to_i; end
|
27
|
+
def inflight; @line[12].to_i; end
|
28
|
+
def total_time; @line[13].to_i; end
|
29
|
+
def weighted_time; @line[14].to_i; end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Parser
|
33
|
+
extend Forwardable
|
34
|
+
include Enumerable
|
35
|
+
|
36
|
+
def_delegators :@devices, :each, :count
|
37
|
+
|
38
|
+
def initialize output
|
39
|
+
update output
|
40
|
+
end
|
41
|
+
|
42
|
+
def [] id
|
43
|
+
case id
|
44
|
+
when Symbol, String
|
45
|
+
id = id.to_s
|
46
|
+
@devices.find { |d| d.name == id }
|
47
|
+
when Fixnum
|
48
|
+
@devices[id]
|
49
|
+
else
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def update new_output
|
55
|
+
parse! new_output.split("\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def parse! lines
|
60
|
+
@devices = lines.map { |line| ::DiskStats::Device.new line }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
$output =
|
4
|
+
%q{ 1 0 ram0 0 0 0 0 0 0 0 0 0 0 0
|
5
|
+
7 0 loop0 0 0 0 0 0 0 0 0 0 0 0
|
6
|
+
7 1 loop1 0 0 0 0 0 0 0 0 0 0 0
|
7
|
+
8 1 sda1 19855 6 508474 118980 959732 197454 9317336 45178260 136 546160 45302960
|
8
|
+
8 16 sdb 143 6 1186 90 309 523 6656 2620 0 380 2710
|
9
|
+
8 88 sdf8 8159 13 399360 57330 44722 40106 2189984 4677860 0 76940 4735190
|
10
|
+
8 81 sdf1 8250 16 401466 110900 47127 40591 2213244 4678750 96 58847720 1350355434
|
11
|
+
8 65 sde1 101 1 810 310 989858 1589839 20637576 18587270 0 536750 18587210
|
12
|
+
9 0 md0 65272 0 3236125 0 680840 0 17512761 0 0 0 0
|
13
|
+
254 0 dm-0 65226 0 3235829 728940 685988 0 17603486 84449350 130 58938560 3428434364
|
14
|
+
}
|
15
|
+
|
16
|
+
$output2 =
|
17
|
+
%q{ 1 0 ram0 0 0 0 0 0 0 0 0 0 0 0
|
18
|
+
7 0 loop0 0 0 0 0 0 0 0 0 0 0 0
|
19
|
+
7 1 loop1 0 0 0 0 0 0 0 0 0 0 0
|
20
|
+
8 1 sda1 9855 6 58474 11980 95932 19454 917336 4178260 16 54160 4532960
|
21
|
+
}
|
22
|
+
|
23
|
+
describe DiskStats::Parser do
|
24
|
+
|
25
|
+
describe 'with good data' do
|
26
|
+
before do
|
27
|
+
@parser = DiskStats::Parser.new($output)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should properly count the number of devices' do
|
31
|
+
@parser.count.must_equal 10
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should be enumerable' do
|
35
|
+
@parser.is_a? Enumerable
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should support each, returning the right types' do
|
39
|
+
@parser.each do |device|
|
40
|
+
device.must_be_instance_of DiskStats::Device
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return a device when indexed by the device name' do
|
45
|
+
@parser[:ram0].must_be_instance_of DiskStats::Device
|
46
|
+
@parser[:ram0].name.must_equal 'ram0'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return the correct device when indexed by number' do
|
50
|
+
@parser[4].must_be_instance_of DiskStats::Device
|
51
|
+
@parser[4].name.must_equal 'sdb'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should support updating' do
|
55
|
+
@parser.update($output2)
|
56
|
+
@parser[:sdf1].must_be_nil
|
57
|
+
@parser[:sda1].name.must_equal 'sda1'
|
58
|
+
@parser[:sda1].reads_completed.must_equal 9855
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'with bad data' do
|
64
|
+
|
65
|
+
it 'should raise a ParseError' do
|
66
|
+
Proc.new { DiskStats::Parser.new('sdfsdfsdfsdfsdf') }.must_raise DiskStats::ParseError
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe DiskStats::Device do
|
72
|
+
before do
|
73
|
+
@parser = DiskStats::Parser.new($output)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should have the right data for a specific parsed row' do
|
77
|
+
@sdf1 = @parser[:sdf1]
|
78
|
+
@sdf1.name.must_equal 'sdf1'
|
79
|
+
@sdf1.major.must_equal 8
|
80
|
+
@sdf1.minor.must_equal 81
|
81
|
+
@sdf1.reads_completed.must_equal 8250
|
82
|
+
@sdf1.reads_merged.must_equal 16
|
83
|
+
@sdf1.sectors_read.must_equal 401466
|
84
|
+
@sdf1.read_time.must_equal 110900
|
85
|
+
@sdf1.writes_completed.must_equal 47127
|
86
|
+
@sdf1.writes_merged.must_equal 40591
|
87
|
+
@sdf1.sectors_written.must_equal 2213244
|
88
|
+
@sdf1.write_time.must_equal 4678750
|
89
|
+
@sdf1.inflight.must_equal 96
|
90
|
+
@sdf1.total_time.must_equal 58847720
|
91
|
+
@sdf1.weighted_time.must_equal 1350355434
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should have the right data for a different specific parsed row' do
|
95
|
+
@loop0 = @parser[:loop0]
|
96
|
+
@loop0.name.must_equal 'loop0'
|
97
|
+
@loop0.major.must_equal 7
|
98
|
+
@loop0.minor.must_equal 0
|
99
|
+
@loop0.reads_completed.must_equal 0
|
100
|
+
@loop0.reads_merged.must_equal 0
|
101
|
+
@loop0.sectors_read.must_equal 0
|
102
|
+
@loop0.read_time.must_equal 0
|
103
|
+
@loop0.writes_completed.must_equal 0
|
104
|
+
@loop0.writes_merged.must_equal 0
|
105
|
+
@loop0.sectors_written.must_equal 0
|
106
|
+
@loop0.write_time.must_equal 0
|
107
|
+
@loop0.inflight.must_equal 0
|
108
|
+
@loop0.total_time.must_equal 0
|
109
|
+
@loop0.weighted_time.must_equal 0
|
110
|
+
end
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: disk-stats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Edward Muller
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-26 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: &70171135253500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70171135253500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &70171135253020 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.1.rc
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70171135253020
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &70171135252540 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70171135252540
|
47
|
+
description: Some stuff for dealing with /proc/diskstats
|
48
|
+
email: edward@heroku.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE.txt
|
53
|
+
files:
|
54
|
+
- Gemfile
|
55
|
+
- Gemfile.lock
|
56
|
+
- LICENSE.txt
|
57
|
+
- Rakefile
|
58
|
+
- VERSION
|
59
|
+
- disk-stats.gemspec
|
60
|
+
- lib/disk-stats.rb
|
61
|
+
- test/helper.rb
|
62
|
+
- test/test_disk_stats.rb
|
63
|
+
homepage: http://github.com/freeformz/disk-stats
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.10
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Some stuff for dealing with /proc/diskstats
|
88
|
+
test_files: []
|