rearview 1.0.2.rc.4-jruby → 1.0.3.rc.1-jruby
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/templates/rearview.rb +14 -3
- data/lib/rearview.rb +12 -1
- data/lib/rearview/configuration.rb +8 -1
- data/lib/rearview/engine.rb +4 -1
- data/lib/rearview/ext/numeric.rb +8 -0
- data/lib/rearview/stats_service.rb +22 -0
- data/lib/rearview/stats_task.rb +51 -0
- data/lib/rearview/statsd.rb +11 -0
- data/lib/rearview/templates/utilities.rb +13 -10
- data/lib/rearview/version.rb +1 -1
- data/lib/rearview/vm.rb +69 -0
- data/spec/data/metric_b.dat +2 -2
- data/spec/dummy/config/database.yml +3 -3
- data/spec/dummy/log/development.log +72 -0
- data/spec/dummy/log/test.log +11050 -0
- data/spec/lib/rearview/configuration_spec.rb +10 -0
- data/spec/lib/rearview/stats_service_spec.rb +43 -0
- data/spec/lib/rearview/stats_task_spec.rb +45 -0
- data/spec/lib/rearview/statsd_spec.rb +20 -0
- data/spec/lib/rearview/templates/utilities_spec.rb +4 -5
- data/spec/lib/rearview/vm_spec.rb +79 -0
- data/spec/spec_helper.rb +2 -1
- metadata +29 -2
@@ -59,6 +59,14 @@ describe Rearview::Configuration do
|
|
59
59
|
config.valid?
|
60
60
|
expect(config.errors[:graphite_url]).to be_empty
|
61
61
|
end
|
62
|
+
it "should require statsd_connection to be present if stats are enabled" do
|
63
|
+
config.enable_stats = false
|
64
|
+
config.valid?
|
65
|
+
expect(config.errors[:statsd_connection]).to be_empty
|
66
|
+
config.enable_stats = true
|
67
|
+
config.valid?
|
68
|
+
expect(config.errors[:statsd_connection]).to include("can't be blank")
|
69
|
+
end
|
62
70
|
pending "should require sanbox_exec to be executable"
|
63
71
|
end
|
64
72
|
|
@@ -70,8 +78,10 @@ describe Rearview::Configuration do
|
|
70
78
|
expect(config.enable_alerts).to be_true
|
71
79
|
expect(config.preload_jobs).to be_true
|
72
80
|
expect(config.enable_monitor).to be_true
|
81
|
+
expect(config.enable_stats).to be_false
|
73
82
|
expect(config.verify).to be_false
|
74
83
|
expect(config.authentication).to eq({strategy: :database})
|
84
|
+
expect(config.default_url_options).to eq({:host=>"localhost", :port=>"3000"})
|
75
85
|
end
|
76
86
|
end
|
77
87
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rearview::StatsService do
|
4
|
+
before do
|
5
|
+
Celluloid.shutdown
|
6
|
+
Celluloid.boot
|
7
|
+
@service = Rearview::StatsService.new
|
8
|
+
end
|
9
|
+
context '#startup' do
|
10
|
+
it "can only be started if stopped" do
|
11
|
+
Rearview::StatsTask.stubs(:supervise).returns(mock)
|
12
|
+
@service.startup
|
13
|
+
expect { @service.startup }.to raise_error(Rearview::StatsService::StatsServiceError,"service already started")
|
14
|
+
end
|
15
|
+
it "should create the supervised task" do
|
16
|
+
Rearview::StatsTask.expects(:supervise)
|
17
|
+
@service.startup
|
18
|
+
end
|
19
|
+
end
|
20
|
+
context '#shutdown' do
|
21
|
+
it "can only be shutdown if started" do
|
22
|
+
expect { @service.shutdown }.to raise_error(Rearview::StatsService::StatsServiceError,"service not started")
|
23
|
+
end
|
24
|
+
it "should terminate the supervised task" do
|
25
|
+
mock_task = mock
|
26
|
+
mock_task.expects(:terminate).once
|
27
|
+
Rearview::StatsTask.stubs(:supervise).returns(stub(:actors => stub(:first => mock_task)))
|
28
|
+
@service.startup
|
29
|
+
@service.shutdown
|
30
|
+
end
|
31
|
+
end
|
32
|
+
context '#started?' do
|
33
|
+
it "should be true if the service is started" do
|
34
|
+
Rearview::StatsTask.stubs(:supervise).returns(mock)
|
35
|
+
@service.startup
|
36
|
+
expect(@service.started?).to be_true
|
37
|
+
end
|
38
|
+
it "should be false if the service is not started" do
|
39
|
+
expect(@service.started?).to be_false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rearview::StatsTask do
|
4
|
+
|
5
|
+
context '.initialize' do
|
6
|
+
it "sets the default delay to 120s" do
|
7
|
+
Rearview::StatsTask.any_instance.stubs(:schedule)
|
8
|
+
stats_task = Rearview::StatsTask.new
|
9
|
+
Rearview::Statsd.stubs(:new).returns(mock)
|
10
|
+
expect(stats_task.delay).to eq(120)
|
11
|
+
end
|
12
|
+
it "sets the batch size correctly" do
|
13
|
+
Rearview::StatsTask.any_instance.stubs(:schedule)
|
14
|
+
statsd = mock
|
15
|
+
statsd.expects(:batch_size=).with(11)
|
16
|
+
Rearview::Statsd.stubs(:new).returns(statsd)
|
17
|
+
stats_task = Rearview::StatsTask.new
|
18
|
+
end
|
19
|
+
it "schedules itself by default" do
|
20
|
+
statsd = mock
|
21
|
+
statsd.expects(:batch_size=).with(anything)
|
22
|
+
Rearview::Statsd.stubs(:new).returns(statsd)
|
23
|
+
Rearview::StatsTask.any_instance.expects(:schedule)
|
24
|
+
stats_task = Rearview::StatsTask.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context '#schedule' do
|
29
|
+
it "sets the timer delay" do
|
30
|
+
stats_task = Rearview::StatsTask.new(120,false)
|
31
|
+
stats_task.expects(:after).with(120)
|
32
|
+
stats_task.schedule
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context '#run' do
|
37
|
+
it "sends a batch request to statsd" do
|
38
|
+
stats_task = Rearview::StatsTask.new(120,false)
|
39
|
+
stats_task.statsd.expects(:batch)
|
40
|
+
stats_task.run
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rearview::Statsd do
|
4
|
+
context '.initialize' do
|
5
|
+
before(:all) do
|
6
|
+
Rearview.config.statsd_connection = { host: 'myhost', port: 123, namespace: 'mynamespace' }
|
7
|
+
end
|
8
|
+
let(:statsd) { Rearview::Statsd.new }
|
9
|
+
it "sets the port from Rearview::Configuration" do
|
10
|
+
expect(statsd.port).to eq(123)
|
11
|
+
end
|
12
|
+
it "sets the host from Rearview::Configuration" do
|
13
|
+
expect(statsd.host).to eq('myhost')
|
14
|
+
end
|
15
|
+
it "sets the namespace from Rearview::Configuration" do
|
16
|
+
expect(statsd.namespace).to eq('mynamespace')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -66,14 +66,13 @@ describe "utility method" do
|
|
66
66
|
monitor_expr = <<-'eos'
|
67
67
|
puts @a
|
68
68
|
eos
|
69
|
-
result = collect_aberrations(all_created,
|
70
|
-
expect(result
|
69
|
+
result = collect_aberrations(all_created, 0)
|
70
|
+
expect(result).to eq({"All Purchases Created in the last hour"=>0.3505384991636653})
|
71
71
|
end
|
72
72
|
|
73
73
|
it "returns correct errors for multiple metrics" do
|
74
|
-
result = collect_aberrations(all_created, local_created,
|
75
|
-
expect(result
|
76
|
-
expect(result[1]).to be_empty
|
74
|
+
result = collect_aberrations(all_created, local_created, 0.36)
|
75
|
+
expect(result).to eq({"Local Purchases Created in the last hour"=>0.40808960944909956})
|
77
76
|
end
|
78
77
|
end
|
79
78
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rearview::Vm do
|
4
|
+
|
5
|
+
let(:vm) { Rearview::Vm.new }
|
6
|
+
|
7
|
+
context '#heap' do
|
8
|
+
it "should be present" do
|
9
|
+
expect(vm.heap.present?).to be_true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context '#non_heap' do
|
14
|
+
it "should be present" do
|
15
|
+
expect(vm.non_heap.present?).to be_true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '#total_memory' do
|
20
|
+
it "should be non-zero" do
|
21
|
+
expect(vm.total_memory>0).to be_true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context '#free_memory' do
|
26
|
+
it "should be non-zero" do
|
27
|
+
expect(vm.free_memory>0).to be_true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#max_memory' do
|
32
|
+
it "should be non-zero" do
|
33
|
+
expect(vm.max_memory>0).to be_true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe Rearview::Vm::Memory do
|
38
|
+
let(:heap) { Rearview::Vm::Heap.new }
|
39
|
+
let(:non_heap) { Rearview::Vm::Heap.new }
|
40
|
+
|
41
|
+
context '#committed' do
|
42
|
+
it "heap should be non-zero" do
|
43
|
+
expect(heap.committed>0).to be_true
|
44
|
+
end
|
45
|
+
it "non_heap should be non-zero" do
|
46
|
+
expect(non_heap.committed>0).to be_true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '#init' do
|
51
|
+
it "heap should be non-zero" do
|
52
|
+
expect(heap.init>0).to be_true
|
53
|
+
end
|
54
|
+
it "non_heap should be non-zero" do
|
55
|
+
expect(non_heap.init>0).to be_true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context '#max' do
|
60
|
+
it "heap should be non-zero" do
|
61
|
+
expect(heap.max>0).to be_true
|
62
|
+
end
|
63
|
+
it "non_heap should be non-zero" do
|
64
|
+
expect(non_heap.max>0).to be_true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context '#used' do
|
69
|
+
it "heap should be non-zero" do
|
70
|
+
expect(heap.used>0).to be_true
|
71
|
+
end
|
72
|
+
it "non_heap should be non-zero" do
|
73
|
+
expect(non_heap.used>0).to be_true
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -18,7 +18,8 @@ Rearview.configure do |config|
|
|
18
18
|
config.sandbox_timeout = 10
|
19
19
|
config.preload_jobs = false
|
20
20
|
config.enable_monitor = false
|
21
|
-
config.default_url_options = {:
|
21
|
+
config.default_url_options = { host: 'localhost', port: '3000' }
|
22
|
+
config.statsd_connection = { host: '127.0.0.1', port: 8125, namespace: 'rearview' }
|
22
23
|
end
|
23
24
|
|
24
25
|
Rearview.boot!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rearview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3.rc.1
|
5
5
|
platform: jruby
|
6
6
|
authors:
|
7
7
|
- Trent Albright
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
version: 1.5.2
|
137
137
|
prerelease: false
|
138
138
|
type: :runtime
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: statsd-ruby
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.2.1
|
146
|
+
requirement: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ~>
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 1.2.1
|
151
|
+
prerelease: false
|
152
|
+
type: :runtime
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: activerecord-jdbcmysql-adapter
|
141
155
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -321,14 +335,19 @@ files:
|
|
321
335
|
- lib/rearview/monitor_supervisor.rb
|
322
336
|
- lib/rearview/monitor_task.rb
|
323
337
|
- lib/rearview/results_handler.rb
|
338
|
+
- lib/rearview/stats_service.rb
|
339
|
+
- lib/rearview/stats_task.rb
|
340
|
+
- lib/rearview/statsd.rb
|
324
341
|
- lib/rearview/url_helper.rb
|
325
342
|
- lib/rearview/version.rb
|
343
|
+
- lib/rearview/vm.rb
|
326
344
|
- lib/rearview/alerts/base.rb
|
327
345
|
- lib/rearview/alerts/campfire_alert.rb
|
328
346
|
- lib/rearview/alerts/email_alert.rb
|
329
347
|
- lib/rearview/alerts/pagerduty_alert.rb
|
330
348
|
- lib/rearview/concerns/models.rb
|
331
349
|
- lib/rearview/concerns/models/user.rb
|
350
|
+
- lib/rearview/ext/numeric.rb
|
332
351
|
- lib/rearview/ext/state_machine.rb
|
333
352
|
- lib/rearview/templates/monitor.rb
|
334
353
|
- lib/rearview/templates/utilities.rb
|
@@ -2212,7 +2231,11 @@ files:
|
|
2212
2231
|
- spec/lib/rearview/monitor_task_spec.rb
|
2213
2232
|
- spec/lib/rearview/rearview_spec.rb
|
2214
2233
|
- spec/lib/rearview/results_handler_spec.rb
|
2234
|
+
- spec/lib/rearview/stats_service_spec.rb
|
2235
|
+
- spec/lib/rearview/stats_task_spec.rb
|
2236
|
+
- spec/lib/rearview/statsd_spec.rb
|
2215
2237
|
- spec/lib/rearview/url_helper_spec.rb
|
2238
|
+
- spec/lib/rearview/vm_spec.rb
|
2216
2239
|
- spec/lib/rearview/alerts/campfire_alert_spec.rb
|
2217
2240
|
- spec/lib/rearview/alerts/email_alert_spec.rb
|
2218
2241
|
- spec/lib/rearview/alerts/pagerduty_alert_spec.rb
|
@@ -2330,7 +2353,11 @@ test_files:
|
|
2330
2353
|
- spec/lib/rearview/monitor_task_spec.rb
|
2331
2354
|
- spec/lib/rearview/rearview_spec.rb
|
2332
2355
|
- spec/lib/rearview/results_handler_spec.rb
|
2356
|
+
- spec/lib/rearview/stats_service_spec.rb
|
2357
|
+
- spec/lib/rearview/stats_task_spec.rb
|
2358
|
+
- spec/lib/rearview/statsd_spec.rb
|
2333
2359
|
- spec/lib/rearview/url_helper_spec.rb
|
2360
|
+
- spec/lib/rearview/vm_spec.rb
|
2334
2361
|
- spec/lib/rearview/alerts/campfire_alert_spec.rb
|
2335
2362
|
- spec/lib/rearview/alerts/email_alert_spec.rb
|
2336
2363
|
- spec/lib/rearview/alerts/pagerduty_alert_spec.rb
|