bookie_accounting 0.0.1
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/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +15 -0
- data/bin/bookie-create-tables +52 -0
- data/bin/bookie-data +102 -0
- data/bin/bookie-send +110 -0
- data/bookie_accounting.gemspec +28 -0
- data/lib/bookie.rb +11 -0
- data/lib/bookie/config.rb +101 -0
- data/lib/bookie/database.rb +656 -0
- data/lib/bookie/formatter.rb +149 -0
- data/lib/bookie/formatters/comma_dump.rb +24 -0
- data/lib/bookie/formatters/spreadsheet.rb +45 -0
- data/lib/bookie/formatters/stdout.rb +32 -0
- data/lib/bookie/sender.rb +108 -0
- data/lib/bookie/senders/standalone.rb +37 -0
- data/lib/bookie/senders/torque_cluster.rb +166 -0
- data/lib/bookie/version.rb +4 -0
- data/snapshot/config.json +12 -0
- data/snapshot/default.json +11 -0
- data/snapshot/pacct +0 -0
- data/snapshot/pacct_large +0 -0
- data/snapshot/pacct_test_config.json +14 -0
- data/snapshot/test_config.json +13 -0
- data/snapshot/torque +3 -0
- data/snapshot/torque_invalid_lines +5 -0
- data/snapshot/torque_invalid_lines_2 +4 -0
- data/snapshot/torque_invalid_lines_3 +3 -0
- data/snapshot/torque_large +100 -0
- data/spec/comma_dump_formatter_spec.rb +56 -0
- data/spec/config_spec.rb +55 -0
- data/spec/database_spec.rb +625 -0
- data/spec/formatter_spec.rb +93 -0
- data/spec/sender_spec.rb +104 -0
- data/spec/spec_helper.rb +121 -0
- data/spec/spreadsheet_formatter_spec.rb +112 -0
- data/spec/standalone_sender_spec.rb +40 -0
- data/spec/stdout_formatter_spec.rb +66 -0
- data/spec/torque_cluster_sender_spec.rb +111 -0
- metadata +227 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Bookie
|
|
4
|
+
module Formatters
|
|
5
|
+
module Stdout
|
|
6
|
+
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe Bookie::Formatters::Stdout do
|
|
12
|
+
before(:all) do
|
|
13
|
+
Bookie::Database::Migration.up
|
|
14
|
+
Helpers::generate_database
|
|
15
|
+
@jobs = Bookie::Database::Job
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
before(:each) do
|
|
19
|
+
@m = IOMock.new
|
|
20
|
+
File.expects(:open).returns(@m)
|
|
21
|
+
@formatter = Bookie::Formatter.new(:stdout, 'mock.out')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
after(:all) do
|
|
25
|
+
FileUtils.rm('test.sqlite')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "correctly opens files" do
|
|
29
|
+
f = Bookie::Formatter.new(:stdout)
|
|
30
|
+
f.instance_variable_get(:'@io').should eql STDOUT
|
|
31
|
+
File.expects(:open).with('mock.out')
|
|
32
|
+
f = Bookie::Formatter.new(:stdout, 'mock.out')
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "correctly formats jobs" do
|
|
36
|
+
@formatter.print_jobs(@jobs.order(:start_time).limit(2))
|
|
37
|
+
@formatter.flush
|
|
38
|
+
@m.buf.should eql \
|
|
39
|
+
"User Group System System type Start " +
|
|
40
|
+
"time End time Wall time CPU time Memory" +
|
|
41
|
+
" usage Exit code \n----------------------------------------------------" +
|
|
42
|
+
"--------------------------------------------------------------------------------" +
|
|
43
|
+
"------------------------------------------------------\nroot root " +
|
|
44
|
+
" test1 Standalone 2012-01-01 00:00:00 201" +
|
|
45
|
+
"2-01-01 01:00:00 01:00:00 00:01:40 200kb (avg) 0 " +
|
|
46
|
+
" \ntest default test1 Standalone 20" +
|
|
47
|
+
"12-01-01 01:00:00 2012-01-01 02:00:00 01:00:00 00:01:40 20" +
|
|
48
|
+
"0kb (avg) 1 \n"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "correctly formats summaries" do
|
|
52
|
+
Time.expects(:now).returns(Time.local(2012) + 36000 * 4).at_least_once
|
|
53
|
+
@formatter.print_summary(@jobs.order(:start_time).limit(5), Bookie::Database::System)
|
|
54
|
+
@formatter.flush
|
|
55
|
+
@m.buf.should eql <<-eos
|
|
56
|
+
Number of jobs: 5
|
|
57
|
+
Total wall time: 05:00:00
|
|
58
|
+
Total CPU time: 00:08:20
|
|
59
|
+
Successful: 60.0000%
|
|
60
|
+
Available CPU time: 140:00:00
|
|
61
|
+
CPU time used: 0.0992%
|
|
62
|
+
Available memory (average): 1750000 kb
|
|
63
|
+
Memory used (average): 0.0014%
|
|
64
|
+
eos
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
#Stubbed out for now so the 'describe' line works
|
|
4
|
+
module Bookie
|
|
5
|
+
module Senders
|
|
6
|
+
module TorqueCluster
|
|
7
|
+
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module Torque
|
|
13
|
+
class Job
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class JobLog
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe Bookie::Senders::TorqueCluster do
|
|
23
|
+
before(:all) do
|
|
24
|
+
config = Bookie::Config.new('snapshot/test_config.json')
|
|
25
|
+
@sender = Bookie::Sender.new(config)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "correctly yields jobs" do
|
|
29
|
+
@sender.each_job('snapshot/torque') do |job|
|
|
30
|
+
job.class.should eql Torque::Job
|
|
31
|
+
job.user_name.should eql 'blm768'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "has the correct system type name" do
|
|
36
|
+
@sender.system_type_name.should eql 'TORQUE cluster'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "has the correct memory stat type" do
|
|
40
|
+
@sender.memory_stat_type.should eql :max
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe Torque::Job do
|
|
45
|
+
it "has a to_model method" do
|
|
46
|
+
Torque::Job.new.respond_to?(:to_model).should eql true
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe Torque::JobLog do
|
|
51
|
+
before(:each) do
|
|
52
|
+
@log = Torque::JobLog.new('snapshot/torque')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "throws an error if the file does not exist" do
|
|
56
|
+
expect { Torque::JobLog.new('snapshot/abc') }.to raise_error
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "correctly reads data" do
|
|
60
|
+
n = 0
|
|
61
|
+
@log.each_job do |job|
|
|
62
|
+
job.user_name.should eql "blm768"
|
|
63
|
+
job.group_name.should eql "test"
|
|
64
|
+
job.start_time.should eql Time.at(1349679573)
|
|
65
|
+
job.wall_time.should eql 67
|
|
66
|
+
job.cpu_time.should eql 63
|
|
67
|
+
job.physical_memory.should eql 139776
|
|
68
|
+
job.virtual_memory.should eql 173444
|
|
69
|
+
job.memory.should eql job.physical_memory + job.virtual_memory
|
|
70
|
+
job.exit_code.should eql 0
|
|
71
|
+
n += 1
|
|
72
|
+
end
|
|
73
|
+
#One of the entries in the file is not a job end entry and should be skipped.
|
|
74
|
+
n.should eql 1
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "can read data more than once" do
|
|
78
|
+
2.times do
|
|
79
|
+
n = 0
|
|
80
|
+
@log.each_job do |job|
|
|
81
|
+
n += 1
|
|
82
|
+
end
|
|
83
|
+
n.should eql 1
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "correctly parses durations" do
|
|
88
|
+
@log.send(:parse_duration, "01:02:03").should eql 3723
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "raises errors when lines are invalid" do
|
|
92
|
+
log = Torque::JobLog.new('snapshot/torque_invalid_lines')
|
|
93
|
+
expect { log.each_job }.to raise_error(
|
|
94
|
+
Torque::JobLog::InvalidLineError,
|
|
95
|
+
"Line 1 of file 'snapshot/torque_invalid_lines' is invalid."
|
|
96
|
+
)
|
|
97
|
+
(2 ... 3).each do |i|
|
|
98
|
+
log = Torque::JobLog.new("snapshot/torque_invalid_lines_#{i}")
|
|
99
|
+
expect { log.each_job {} }.to raise_error(
|
|
100
|
+
Torque::JobLog::InvalidLineError,
|
|
101
|
+
"Line 3 of file 'snapshot/torque_invalid_lines_#{i}' is invalid."
|
|
102
|
+
)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it "correctly calculates the filename for a date" do
|
|
107
|
+
Torque::JobLog.filename_for_date(Date.new(2012, 1, 3)).should eql Torque::torque_root + '/server_priv/accounting/20120103'
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
#To consider: unit test torque_root's value?
|
|
111
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bookie_accounting
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Ben Merritt
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-02-21 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: json
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: activerecord
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: mysql2
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: pacct
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
type: :runtime
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
- !ruby/object:Gem::Dependency
|
|
79
|
+
name: spreadsheet
|
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
|
81
|
+
none: false
|
|
82
|
+
requirements:
|
|
83
|
+
- - ! '>='
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
type: :runtime
|
|
87
|
+
prerelease: false
|
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
+
none: false
|
|
90
|
+
requirements:
|
|
91
|
+
- - ! '>='
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
- !ruby/object:Gem::Dependency
|
|
95
|
+
name: mocha
|
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
|
97
|
+
none: false
|
|
98
|
+
requirements:
|
|
99
|
+
- - ! '>='
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
type: :development
|
|
103
|
+
prerelease: false
|
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
+
none: false
|
|
106
|
+
requirements:
|
|
107
|
+
- - ! '>='
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: rspec
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
none: false
|
|
114
|
+
requirements:
|
|
115
|
+
- - ! '>='
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
none: false
|
|
122
|
+
requirements:
|
|
123
|
+
- - ! '>='
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '0'
|
|
126
|
+
- !ruby/object:Gem::Dependency
|
|
127
|
+
name: sqlite3
|
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
|
129
|
+
none: false
|
|
130
|
+
requirements:
|
|
131
|
+
- - ! '>='
|
|
132
|
+
- !ruby/object:Gem::Version
|
|
133
|
+
version: '0'
|
|
134
|
+
type: :development
|
|
135
|
+
prerelease: false
|
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
137
|
+
none: false
|
|
138
|
+
requirements:
|
|
139
|
+
- - ! '>='
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
version: '0'
|
|
142
|
+
description: A simple system to record and query process accounting records
|
|
143
|
+
email:
|
|
144
|
+
- blm768@gmail.com
|
|
145
|
+
executables:
|
|
146
|
+
- bookie-create-tables
|
|
147
|
+
- bookie-data
|
|
148
|
+
- bookie-send
|
|
149
|
+
extensions: []
|
|
150
|
+
extra_rdoc_files: []
|
|
151
|
+
files:
|
|
152
|
+
- .gitignore
|
|
153
|
+
- Gemfile
|
|
154
|
+
- LICENSE
|
|
155
|
+
- README.md
|
|
156
|
+
- Rakefile
|
|
157
|
+
- bin/bookie-create-tables
|
|
158
|
+
- bin/bookie-data
|
|
159
|
+
- bin/bookie-send
|
|
160
|
+
- bookie_accounting.gemspec
|
|
161
|
+
- lib/bookie.rb
|
|
162
|
+
- lib/bookie/config.rb
|
|
163
|
+
- lib/bookie/database.rb
|
|
164
|
+
- lib/bookie/formatter.rb
|
|
165
|
+
- lib/bookie/formatters/comma_dump.rb
|
|
166
|
+
- lib/bookie/formatters/spreadsheet.rb
|
|
167
|
+
- lib/bookie/formatters/stdout.rb
|
|
168
|
+
- lib/bookie/sender.rb
|
|
169
|
+
- lib/bookie/senders/standalone.rb
|
|
170
|
+
- lib/bookie/senders/torque_cluster.rb
|
|
171
|
+
- lib/bookie/version.rb
|
|
172
|
+
- snapshot/config.json
|
|
173
|
+
- snapshot/default.json
|
|
174
|
+
- snapshot/pacct
|
|
175
|
+
- snapshot/pacct_large
|
|
176
|
+
- snapshot/pacct_test_config.json
|
|
177
|
+
- snapshot/test_config.json
|
|
178
|
+
- snapshot/torque
|
|
179
|
+
- snapshot/torque_invalid_lines
|
|
180
|
+
- snapshot/torque_invalid_lines_2
|
|
181
|
+
- snapshot/torque_invalid_lines_3
|
|
182
|
+
- snapshot/torque_large
|
|
183
|
+
- spec/comma_dump_formatter_spec.rb
|
|
184
|
+
- spec/config_spec.rb
|
|
185
|
+
- spec/database_spec.rb
|
|
186
|
+
- spec/formatter_spec.rb
|
|
187
|
+
- spec/sender_spec.rb
|
|
188
|
+
- spec/spec_helper.rb
|
|
189
|
+
- spec/spreadsheet_formatter_spec.rb
|
|
190
|
+
- spec/standalone_sender_spec.rb
|
|
191
|
+
- spec/stdout_formatter_spec.rb
|
|
192
|
+
- spec/torque_cluster_sender_spec.rb
|
|
193
|
+
homepage: https://github.com/blm768/bookie/
|
|
194
|
+
licenses: []
|
|
195
|
+
post_install_message:
|
|
196
|
+
rdoc_options: []
|
|
197
|
+
require_paths:
|
|
198
|
+
- lib
|
|
199
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
|
+
none: false
|
|
201
|
+
requirements:
|
|
202
|
+
- - ! '>='
|
|
203
|
+
- !ruby/object:Gem::Version
|
|
204
|
+
version: '0'
|
|
205
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
|
+
none: false
|
|
207
|
+
requirements:
|
|
208
|
+
- - ! '>='
|
|
209
|
+
- !ruby/object:Gem::Version
|
|
210
|
+
version: '0'
|
|
211
|
+
requirements: []
|
|
212
|
+
rubyforge_project:
|
|
213
|
+
rubygems_version: 1.8.24
|
|
214
|
+
signing_key:
|
|
215
|
+
specification_version: 3
|
|
216
|
+
summary: A simple system to record and query process accounting records
|
|
217
|
+
test_files:
|
|
218
|
+
- spec/comma_dump_formatter_spec.rb
|
|
219
|
+
- spec/config_spec.rb
|
|
220
|
+
- spec/database_spec.rb
|
|
221
|
+
- spec/formatter_spec.rb
|
|
222
|
+
- spec/sender_spec.rb
|
|
223
|
+
- spec/spec_helper.rb
|
|
224
|
+
- spec/spreadsheet_formatter_spec.rb
|
|
225
|
+
- spec/standalone_sender_spec.rb
|
|
226
|
+
- spec/stdout_formatter_spec.rb
|
|
227
|
+
- spec/torque_cluster_sender_spec.rb
|