pulse-meter 0.4.9 → 0.4.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -48
- data/lib/pulse-meter.rb +1 -68
- data/lib/pulse-meter/visualizer.rb +1 -40
- data/pulse-meter.gemspec +4 -26
- metadata +10 -558
- data/Procfile +0 -3
- data/bin/pulse +0 -6
- data/examples/basic.ru +0 -145
- data/examples/basic_sensor_data.rb +0 -96
- data/examples/udp_benchmark.rb +0 -29
- data/lib/cmd.rb +0 -171
- data/lib/pulse-meter/command_aggregator/async.rb +0 -83
- data/lib/pulse-meter/command_aggregator/sync.rb +0 -18
- data/lib/pulse-meter/command_aggregator/udp.rb +0 -48
- data/lib/pulse-meter/extensions/enumerable.rb +0 -24
- data/lib/pulse-meter/mixins/cmd.rb +0 -46
- data/lib/pulse-meter/mixins/dumper.rb +0 -87
- data/lib/pulse-meter/mixins/utils.rb +0 -155
- data/lib/pulse-meter/observer.rb +0 -120
- data/lib/pulse-meter/observer/extended.rb +0 -34
- data/lib/pulse-meter/sensor.rb +0 -61
- data/lib/pulse-meter/sensor/base.rb +0 -88
- data/lib/pulse-meter/sensor/configuration.rb +0 -106
- data/lib/pulse-meter/sensor/counter.rb +0 -39
- data/lib/pulse-meter/sensor/hashed_counter.rb +0 -36
- data/lib/pulse-meter/sensor/hashed_indicator.rb +0 -24
- data/lib/pulse-meter/sensor/indicator.rb +0 -35
- data/lib/pulse-meter/sensor/multi.rb +0 -97
- data/lib/pulse-meter/sensor/timeline.rb +0 -236
- data/lib/pulse-meter/sensor/timeline_reduce.rb +0 -68
- data/lib/pulse-meter/sensor/timelined/average.rb +0 -32
- data/lib/pulse-meter/sensor/timelined/counter.rb +0 -23
- data/lib/pulse-meter/sensor/timelined/hashed_counter.rb +0 -31
- data/lib/pulse-meter/sensor/timelined/hashed_indicator.rb +0 -30
- data/lib/pulse-meter/sensor/timelined/indicator.rb +0 -23
- data/lib/pulse-meter/sensor/timelined/max.rb +0 -19
- data/lib/pulse-meter/sensor/timelined/median.rb +0 -14
- data/lib/pulse-meter/sensor/timelined/min.rb +0 -19
- data/lib/pulse-meter/sensor/timelined/multi_percentile.rb +0 -34
- data/lib/pulse-meter/sensor/timelined/percentile.rb +0 -22
- data/lib/pulse-meter/sensor/timelined/uniq_counter.rb +0 -22
- data/lib/pulse-meter/sensor/timelined/zset_based.rb +0 -38
- data/lib/pulse-meter/sensor/uniq_counter.rb +0 -24
- data/lib/pulse-meter/server.rb +0 -0
- data/lib/pulse-meter/server/command_line_options.rb +0 -0
- data/lib/pulse-meter/server/config_options.rb +0 -0
- data/lib/pulse-meter/server/sensors.rb +0 -0
- data/lib/pulse-meter/udp_server.rb +0 -45
- data/lib/pulse-meter/version.rb +0 -3
- data/lib/pulse-meter/visualize/app.rb +0 -78
- data/lib/pulse-meter/visualize/base.rb +0 -15
- data/lib/pulse-meter/visualize/coffee/application.coffee +0 -40
- data/lib/pulse-meter/visualize/coffee/collections/page_info_list.coffee +0 -17
- data/lib/pulse-meter/visualize/coffee/collections/sensor_info_list.coffee +0 -4
- data/lib/pulse-meter/visualize/coffee/collections/widget_list.coffee +0 -14
- data/lib/pulse-meter/visualize/coffee/extensions.coffee +0 -26
- data/lib/pulse-meter/visualize/coffee/models/dinamic_widget.coffee +0 -34
- data/lib/pulse-meter/visualize/coffee/models/page_info.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/models/sensor_info.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/models/widget.coffee +0 -54
- data/lib/pulse-meter/visualize/coffee/presenters/area.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/presenters/gauge.coffee +0 -11
- data/lib/pulse-meter/visualize/coffee/presenters/line.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/presenters/pie.coffee +0 -20
- data/lib/pulse-meter/visualize/coffee/presenters/series.coffee +0 -44
- data/lib/pulse-meter/visualize/coffee/presenters/table.coffee +0 -10
- data/lib/pulse-meter/visualize/coffee/presenters/timeline.coffee +0 -13
- data/lib/pulse-meter/visualize/coffee/presenters/widget.coffee +0 -65
- data/lib/pulse-meter/visualize/coffee/router.coffee +0 -21
- data/lib/pulse-meter/visualize/coffee/views/dynamic_chart.coffee +0 -91
- data/lib/pulse-meter/visualize/coffee/views/dynamic_widget.coffee +0 -58
- data/lib/pulse-meter/visualize/coffee/views/page_title.coffee +0 -17
- data/lib/pulse-meter/visualize/coffee/views/page_titles.coffee +0 -15
- data/lib/pulse-meter/visualize/coffee/views/sensor_info_list.coffee +0 -19
- data/lib/pulse-meter/visualize/coffee/views/widget.coffee +0 -99
- data/lib/pulse-meter/visualize/coffee/views/widget_chart.coffee +0 -13
- data/lib/pulse-meter/visualize/coffee/views/widget_list.coffee +0 -15
- data/lib/pulse-meter/visualize/dsl/base.rb +0 -131
- data/lib/pulse-meter/visualize/dsl/errors.rb +0 -40
- data/lib/pulse-meter/visualize/dsl/layout.rb +0 -27
- data/lib/pulse-meter/visualize/dsl/page.rb +0 -33
- data/lib/pulse-meter/visualize/dsl/sensor.rb +0 -20
- data/lib/pulse-meter/visualize/dsl/widget.rb +0 -37
- data/lib/pulse-meter/visualize/dsl/widgets/area.rb +0 -20
- data/lib/pulse-meter/visualize/dsl/widgets/gauge.rb +0 -12
- data/lib/pulse-meter/visualize/dsl/widgets/line.rb +0 -21
- data/lib/pulse-meter/visualize/dsl/widgets/pie.rb +0 -16
- data/lib/pulse-meter/visualize/dsl/widgets/table.rb +0 -19
- data/lib/pulse-meter/visualize/layout.rb +0 -79
- data/lib/pulse-meter/visualize/page.rb +0 -25
- data/lib/pulse-meter/visualize/public/css/application.css +0 -56
- data/lib/pulse-meter/visualize/public/css/bootstrap.css +0 -4883
- data/lib/pulse-meter/visualize/public/css/bootstrap.min.css +0 -729
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_222222_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_454545_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_888888_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_f6cf3b_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/jquery-ui-1.8.16.bootstrap.css +0 -1320
- data/lib/pulse-meter/visualize/public/favicon.ico +0 -208
- data/lib/pulse-meter/visualize/public/img/glyphicons-halflings-white.png +0 -0
- data/lib/pulse-meter/visualize/public/img/glyphicons-halflings.png +0 -0
- data/lib/pulse-meter/visualize/public/js/application.js +0 -973
- data/lib/pulse-meter/visualize/public/js/backbone-min.js +0 -38
- data/lib/pulse-meter/visualize/public/js/bootstrap.js +0 -1835
- data/lib/pulse-meter/visualize/public/js/jquery-1.7.2.min.js +0 -4
- data/lib/pulse-meter/visualize/public/js/jquery-ui-1.8.16.bootstrap.min.js +0 -791
- data/lib/pulse-meter/visualize/public/js/jquery-ui-1.8.23.custom.min.js +0 -21
- data/lib/pulse-meter/visualize/public/js/jquery-ui-timepicker-addon.js +0 -1687
- data/lib/pulse-meter/visualize/public/js/json2.js +0 -487
- data/lib/pulse-meter/visualize/public/js/underscore-min.js +0 -32
- data/lib/pulse-meter/visualize/sensor.rb +0 -63
- data/lib/pulse-meter/visualize/series_extractor.rb +0 -107
- data/lib/pulse-meter/visualize/views/main.haml +0 -30
- data/lib/pulse-meter/visualize/views/sensors.haml +0 -76
- data/lib/pulse-meter/visualize/views/widgets/area.haml +0 -53
- data/lib/pulse-meter/visualize/views/widgets/extend_options.haml +0 -11
- data/lib/pulse-meter/visualize/views/widgets/gauge.haml +0 -13
- data/lib/pulse-meter/visualize/views/widgets/line.haml +0 -54
- data/lib/pulse-meter/visualize/views/widgets/pie.haml +0 -13
- data/lib/pulse-meter/visualize/views/widgets/table.haml +0 -45
- data/lib/pulse-meter/visualize/widget.rb +0 -38
- data/lib/pulse-meter/visualize/widgets/gauge.rb +0 -47
- data/lib/pulse-meter/visualize/widgets/pie.rb +0 -36
- data/lib/pulse-meter/visualize/widgets/timeline.rb +0 -114
- data/spec/pulse_meter/command_aggregator/async_spec.rb +0 -53
- data/spec/pulse_meter/command_aggregator/sync_spec.rb +0 -25
- data/spec/pulse_meter/command_aggregator/udp_spec.rb +0 -45
- data/spec/pulse_meter/extensions/enumerable_spec.rb +0 -58
- data/spec/pulse_meter/mixins/cmd_spec.rb +0 -117
- data/spec/pulse_meter/mixins/dumper_spec.rb +0 -162
- data/spec/pulse_meter/mixins/utils_spec.rb +0 -212
- data/spec/pulse_meter/observer/extended_spec.rb +0 -92
- data/spec/pulse_meter/observer_spec.rb +0 -207
- data/spec/pulse_meter/sensor/base_spec.rb +0 -106
- data/spec/pulse_meter/sensor/configuration_spec.rb +0 -103
- data/spec/pulse_meter/sensor/counter_spec.rb +0 -54
- data/spec/pulse_meter/sensor/hashed_counter_spec.rb +0 -43
- data/spec/pulse_meter/sensor/hashed_indicator_spec.rb +0 -39
- data/spec/pulse_meter/sensor/indicator_spec.rb +0 -43
- data/spec/pulse_meter/sensor/multi_spec.rb +0 -137
- data/spec/pulse_meter/sensor/timeline_spec.rb +0 -88
- data/spec/pulse_meter/sensor/timelined/average_spec.rb +0 -6
- data/spec/pulse_meter/sensor/timelined/counter_spec.rb +0 -6
- data/spec/pulse_meter/sensor/timelined/hashed_counter_spec.rb +0 -8
- data/spec/pulse_meter/sensor/timelined/hashed_indicator_spec.rb +0 -8
- data/spec/pulse_meter/sensor/timelined/indicator_spec.rb +0 -6
- data/spec/pulse_meter/sensor/timelined/max_spec.rb +0 -7
- data/spec/pulse_meter/sensor/timelined/median_spec.rb +0 -7
- data/spec/pulse_meter/sensor/timelined/min_spec.rb +0 -7
- data/spec/pulse_meter/sensor/timelined/multi_percentile_spec.rb +0 -21
- data/spec/pulse_meter/sensor/timelined/percentile_spec.rb +0 -17
- data/spec/pulse_meter/sensor/timelined/uniq_counter_spec.rb +0 -9
- data/spec/pulse_meter/sensor/uniq_counter_spec.rb +0 -28
- data/spec/pulse_meter/udp_server_spec.rb +0 -36
- data/spec/pulse_meter/visualize/app_spec.rb +0 -27
- data/spec/pulse_meter/visualize/dsl/layout_spec.rb +0 -64
- data/spec/pulse_meter/visualize/dsl/page_spec.rb +0 -62
- data/spec/pulse_meter/visualize/dsl/sensor_spec.rb +0 -30
- data/spec/pulse_meter/visualize/dsl/widget_spec.rb +0 -6
- data/spec/pulse_meter/visualize/dsl/widgets/area_spec.rb +0 -44
- data/spec/pulse_meter/visualize/dsl/widgets/gauge_spec.rb +0 -22
- data/spec/pulse_meter/visualize/dsl/widgets/line_spec.rb +0 -44
- data/spec/pulse_meter/visualize/dsl/widgets/pie_spec.rb +0 -35
- data/spec/pulse_meter/visualize/dsl/widgets/table_spec.rb +0 -36
- data/spec/pulse_meter/visualize/layout_spec.rb +0 -54
- data/spec/pulse_meter/visualize/page_spec.rb +0 -153
- data/spec/pulse_meter/visualize/sensor_spec.rb +0 -120
- data/spec/pulse_meter/visualize/series_extractor_spec.rb +0 -80
- data/spec/pulse_meter/visualize/widgets/area_spec.rb +0 -6
- data/spec/pulse_meter/visualize/widgets/gauge_spec.rb +0 -63
- data/spec/pulse_meter/visualize/widgets/line_spec.rb +0 -6
- data/spec/pulse_meter/visualize/widgets/pie_spec.rb +0 -73
- data/spec/pulse_meter/visualize/widgets/table_spec.rb +0 -6
- data/spec/pulse_meter/visualizer_spec.rb +0 -42
- data/spec/pulse_meter_spec.rb +0 -73
- data/spec/shared_examples/dsl_widget.rb +0 -106
- data/spec/shared_examples/timeline_sensor.rb +0 -439
- data/spec/shared_examples/timelined_subclass.rb +0 -23
- data/spec/shared_examples/widget.rb +0 -97
- data/spec/spec_helper.rb +0 -40
- data/spec/support/matchers.rb +0 -34
- data/spec/support/observered.rb +0 -40
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PulseMeter::Sensor::Counter do
|
4
|
-
let(:name){ :some_counter }
|
5
|
-
let(:sensor){ described_class.new(name) }
|
6
|
-
let(:redis){ PulseMeter.redis }
|
7
|
-
|
8
|
-
describe "#event" do
|
9
|
-
it "should increment sensor value by passed value" do
|
10
|
-
expect{ sensor.event(10) }.to change{ sensor.value }.from(0).to(10)
|
11
|
-
expect{ sensor.event(15) }.to change{ sensor.value }.from(10).to(25)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should truncate increment value" do
|
15
|
-
expect{ sensor.event(10.4) }.to change{ sensor.value }.from(0).to(10)
|
16
|
-
expect{ sensor.event(15.1) }.to change{ sensor.value }.from(10).to(25)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#value_key" do
|
21
|
-
it "should be composed of sensor name and pulse_meter:value: prefix" do
|
22
|
-
sensor.value_key.should == "pulse_meter:value:#{name}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "#value" do
|
27
|
-
it "should have initial value 0" do
|
28
|
-
sensor.value.should == 0
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should store stringified value by value_key" do
|
32
|
-
sensor.event(123)
|
33
|
-
sensor.value.should == 123
|
34
|
-
redis.get(sensor.value_key).should == '123'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#incr" do
|
39
|
-
it "should increment value by 1" do
|
40
|
-
expect{ sensor.incr }.to change{ sensor.value }.from(0).to(1)
|
41
|
-
expect{ sensor.incr }.to change{ sensor.value }.from(1).to(2)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "#cleanup" do
|
46
|
-
it "should remove all sensor data" do
|
47
|
-
sensor.annotate("My Counter")
|
48
|
-
sensor.event(123)
|
49
|
-
sensor.cleanup
|
50
|
-
redis.keys('*').should be_empty
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PulseMeter::Sensor::HashedCounter do
|
4
|
-
let(:name){ :some_counter }
|
5
|
-
let(:sensor){ described_class.new(name) }
|
6
|
-
let(:redis){ PulseMeter.redis }
|
7
|
-
|
8
|
-
describe "#event" do
|
9
|
-
it "should increment sensor value by passed value" do
|
10
|
-
expect{ sensor.event({"foo" => 10}) }.to change{ sensor.value["foo"] }.from(0).to(10)
|
11
|
-
expect{ sensor.event({"foo" => 15}) }.to change{ sensor.value["foo"] }.from(10).to(25)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should truncate increment value" do
|
15
|
-
expect{ sensor.event({"foo" => 10.4}) }.to change{ sensor.value["foo"] }.from(0).to(10)
|
16
|
-
expect{ sensor.event({"foo" => 15.1}) }.to change{ sensor.value["foo"] }.from(10).to(25)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should increment total value" do
|
20
|
-
expect{ sensor.event({"foo" => 1, "bar" => 2}) }.to change{sensor.value["total"]}.from(0).to(3)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#value" do
|
25
|
-
it "should have initial value 0" do
|
26
|
-
sensor.value["foo"].should == 0
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should store redis hash by value_key" do
|
30
|
-
sensor.event({"foo" => 1})
|
31
|
-
sensor.value.should == {"foo" => 1, "total" => 1}
|
32
|
-
redis.hgetall(sensor.value_key).should == {"foo" => "1", "total" => "1"}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "#incr" do
|
37
|
-
it "should increment key value by 1" do
|
38
|
-
expect{ sensor.incr("foo") }.to change{ sensor.value["foo"] }.from(0).to(1)
|
39
|
-
expect{ sensor.incr("foo") }.to change{ sensor.value["foo"] }.from(1).to(2)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PulseMeter::Sensor::HashedIndicator do
|
4
|
-
let(:name){ :some_counter }
|
5
|
-
let(:sensor){ described_class.new(name) }
|
6
|
-
let(:redis){ PulseMeter.redis }
|
7
|
-
|
8
|
-
describe "#event" do
|
9
|
-
it "should set sensor value to passed value" do
|
10
|
-
expect{ sensor.event("foo" => 10.4) }.to change{ sensor.value["foo"] }.from(0).to(10.4)
|
11
|
-
expect{ sensor.event("foo" => 15.1) }.to change{ sensor.value["foo"] }.from(10.4).to(15.1)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should take multiple events" do
|
15
|
-
data = {"foo" => 1.1, "boo" => 2.2}
|
16
|
-
sensor.event(data)
|
17
|
-
sensor.value.should == data
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#value_key" do
|
22
|
-
it "should be composed of sensor name and pulse_meter:value: prefix" do
|
23
|
-
sensor.value_key.should == "pulse_meter:value:#{name}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#value" do
|
28
|
-
it "should have initial value 0" do
|
29
|
-
sensor.value["foo"].should == 0
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should store redis hash by value_key" do
|
33
|
-
sensor.event({"foo" => 1})
|
34
|
-
sensor.value.should == {"foo" => 1}
|
35
|
-
redis.hgetall(sensor.value_key).should == {"foo" => "1.0"}
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PulseMeter::Sensor::Indicator do
|
4
|
-
let(:name){ :some_value }
|
5
|
-
let(:sensor){ described_class.new(name) }
|
6
|
-
let(:redis){ PulseMeter.redis }
|
7
|
-
|
8
|
-
describe "#event" do
|
9
|
-
it "should set sensor value to passed value" do
|
10
|
-
expect{ sensor.event(10.4) }.to change{ sensor.value }.from(0).to(10.4)
|
11
|
-
expect{ sensor.event(15.1) }.to change{ sensor.value }.from(10.4).to(15.1)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#value_key" do
|
16
|
-
it "should be composed of sensor name and pulse_meter:value: prefix" do
|
17
|
-
sensor.value_key.should == "pulse_meter:value:#{name}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#value" do
|
22
|
-
it "should have initial value 0" do
|
23
|
-
sensor.value.should == 0
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should store stringified value by value_key" do
|
27
|
-
sensor.event(123)
|
28
|
-
sensor.value.should == 123
|
29
|
-
redis.get(sensor.value_key) == '123'
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#cleanup" do
|
34
|
-
it "should remove all sensor data" do
|
35
|
-
sensor.annotate("My Indicator")
|
36
|
-
sensor.event(123)
|
37
|
-
sensor.cleanup
|
38
|
-
redis.keys('*').should be_empty
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
@@ -1,137 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PulseMeter::Sensor::Multi do
|
4
|
-
let(:name){ :foo }
|
5
|
-
let(:annotation) { "Multi sensor" }
|
6
|
-
let(:type) {'counter'}
|
7
|
-
let(:factors) {[:f1, :f2]}
|
8
|
-
let(:configuration) {
|
9
|
-
{
|
10
|
-
sensor_type: type,
|
11
|
-
args: {
|
12
|
-
annotation: annotation
|
13
|
-
}
|
14
|
-
}
|
15
|
-
}
|
16
|
-
let(:init_values) { { factors: factors, configuration: configuration } }
|
17
|
-
let!(:sensor) { described_class.new(name, init_values) }
|
18
|
-
let!(:redis){ PulseMeter.redis }
|
19
|
-
|
20
|
-
describe '#initialize' do
|
21
|
-
context "when factors are not corretly passed" do
|
22
|
-
it "raises ArgumentError" do
|
23
|
-
expect {described_class.new(name, {factors: :not_array, configuration: configuration})}.to raise_exception(ArgumentError)
|
24
|
-
expect {described_class.new(name, {configuration: configuration})}.to raise_exception(ArgumentError)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when configuration missing" do
|
29
|
-
it "raises ArgumentError" do
|
30
|
-
expect {described_class.new(name, {factors: factors})}.to raise_exception(ArgumentError)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#factors" do
|
36
|
-
it "returns factors passed to constructor" do
|
37
|
-
sensor.factors.should == factors
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#configuration_options" do
|
42
|
-
it "returns configuration option passed to constructor" do
|
43
|
-
sensor.configuration_options.should == configuration
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "#sensors" do
|
48
|
-
it "returns PulseMeter::Sensor::Configuration instance" do
|
49
|
-
sensor.sensors.should be_instance_of(PulseMeter::Sensor::Configuration)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#event" do
|
54
|
-
|
55
|
-
it "raises ArgumentError unless all factors' values given" do
|
56
|
-
expect {sensor.event({f1: :v1}, 1)}.to raise_exception(ArgumentError)
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
context "when sensors must be created" do
|
61
|
-
let(:factor_values) { {f1: :v1, f2: :v2} }
|
62
|
-
|
63
|
-
it "implicitly creates them" do
|
64
|
-
expect {sensor.event(factor_values, 1)}.to change{sensor.sensors.to_a.count}
|
65
|
-
end
|
66
|
-
|
67
|
-
it "assigns names based on factors' names and values" do
|
68
|
-
sensor.event(factor_values, 1)
|
69
|
-
names = sensor.sensors.to_a.map(&:name)
|
70
|
-
names.sort.should == [
|
71
|
-
"#{name}",
|
72
|
-
"#{name}_f1_v1",
|
73
|
-
"#{name}_f2_v2",
|
74
|
-
"#{name}_f1_v1_f2_v2"
|
75
|
-
].sort
|
76
|
-
end
|
77
|
-
|
78
|
-
it "creates sensors of given type with configuration options passed" do
|
79
|
-
sensor.event(factor_values, 1)
|
80
|
-
sensor.sensors.each do |s|
|
81
|
-
s.should be_instance_of(PulseMeter::Sensor::Counter)
|
82
|
-
s.annotation.should == annotation
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
it "sends event to all combinations of factors and values" do
|
88
|
-
sensor.event({f1: :f1v1, f2: :f2v1}, 1)
|
89
|
-
sensor.event({f1: :f1v2, f2: :f2v1}, 2)
|
90
|
-
[
|
91
|
-
["#{name}", 3],
|
92
|
-
["#{name}_f1_f1v1", 1],
|
93
|
-
["#{name}_f1_f1v2", 2],
|
94
|
-
["#{name}_f2_f2v1", 3],
|
95
|
-
["#{name}_f1_f1v1_f2_f2v1", 1],
|
96
|
-
["#{name}_f1_f1v2_f2_f2v1", 2]
|
97
|
-
].each do |sensor_name, sum|
|
98
|
-
sensor.sensor(sensor_name) { |s|
|
99
|
-
s.value.should == sum
|
100
|
-
}
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "#each" do
|
106
|
-
it "when used by Enumerable it lists all ever created subsensors of multisensor" do
|
107
|
-
sensor.event({f1: :f1v1, f2: :f2v1}, 1)
|
108
|
-
restored_sensor = PulseMeter::Sensor::Base.restore(name)
|
109
|
-
|
110
|
-
restored_sensor.to_a.map(&:name).sort.should == [
|
111
|
-
"#{name}",
|
112
|
-
"#{name}_f1_f1v1",
|
113
|
-
"#{name}_f2_f2v1",
|
114
|
-
"#{name}_f1_f1v1_f2_f2v1",
|
115
|
-
].sort
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "#sensor_for_factors" do
|
120
|
-
context "when sensor has already been created" do
|
121
|
-
it "yields block with sensor for given combination of factors and their values" do
|
122
|
-
sensor.event({f1: :f1v1, f2: :f2v1}, 1)
|
123
|
-
sensor.sensor_for_factors([:f1, :f2], [:f1v1, :f2v1]){|s| s.name.should == "#{name}_f1_f1v1_f2_f2v1"}
|
124
|
-
sensor.sensor_for_factors([:f1], [:f1v1]){|s| s.name.should == "#{name}_f1_f1v1"}
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
context "when such a sensor was not created" do
|
129
|
-
it "does not yields block" do
|
130
|
-
yielded = false
|
131
|
-
sensor.sensor_for_factors([:foo], [:bar]){ yielded = true }
|
132
|
-
yielded.should be_false
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PulseMeter::Sensor::Timeline do
|
4
|
-
let(:name){ :some_value_with_history }
|
5
|
-
let(:ttl){ 100 }
|
6
|
-
let(:raw_data_ttl){ 10 }
|
7
|
-
let(:interval){ 5 }
|
8
|
-
let(:reduce_delay){ 3 }
|
9
|
-
let(:good_init_values){ {:ttl => ttl, :raw_data_ttl => raw_data_ttl, :interval => interval, :reduce_delay => reduce_delay} }
|
10
|
-
let(:sensor){ described_class.new(name, good_init_values) }
|
11
|
-
let(:redis){ PulseMeter.redis }
|
12
|
-
|
13
|
-
it_should_behave_like "timeline sensor"
|
14
|
-
|
15
|
-
describe '#new' do
|
16
|
-
INIT_VALUE_NAMES = {
|
17
|
-
:with_defaults => [:raw_data_ttl, :reduce_delay],
|
18
|
-
:without_defaults => [:ttl, :interval]
|
19
|
-
}
|
20
|
-
|
21
|
-
shared_examples_for "error raiser" do |value_names, bad_values|
|
22
|
-
value_names.each do |value|
|
23
|
-
bad_values.each do |bad_value|
|
24
|
-
it "should raise exception if a bad value #{bad_value.inspect} passed for #{value.inspect}" do
|
25
|
-
expect{ described_class.new(name, good_init_values.merge(value => bad_value)) }.to raise_exception(ArgumentError)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should initialize #ttl #raw_data_ttl #interval and #name attributes" do
|
32
|
-
sensor.name.should == name.to_s
|
33
|
-
|
34
|
-
sensor.ttl.should == ttl
|
35
|
-
sensor.raw_data_ttl.should == raw_data_ttl
|
36
|
-
sensor.interval.should == interval
|
37
|
-
end
|
38
|
-
|
39
|
-
it_should_behave_like "error raiser", INIT_VALUE_NAMES[:without_defaults], [:bad, -1, nil]
|
40
|
-
it_should_behave_like "error raiser", INIT_VALUE_NAMES[:with_defaults], [:bad, -1]
|
41
|
-
|
42
|
-
INIT_VALUE_NAMES[:with_defaults].each do |value|
|
43
|
-
it "should not raise exception if #{value.inspect} is not defined" do
|
44
|
-
values = good_init_values
|
45
|
-
values.delete(value)
|
46
|
-
expect {described_class.new(name, good_init_values)}.not_to raise_exception(ArgumentError)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should assign default value to #{value.inspect} if it is not defined" do
|
50
|
-
values = good_init_values
|
51
|
-
values.delete(value)
|
52
|
-
obj = described_class.new(name, good_init_values)
|
53
|
-
obj.send(value).should be_kind_of(Fixnum)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#deflate_safe" do
|
60
|
-
class GoodSubclass < described_class
|
61
|
-
def deflate(value)
|
62
|
-
value.to_i
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class BadSubclass < described_class
|
67
|
-
def deflate(value)
|
68
|
-
raise "Any conversion error"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
let!(:good_instance) { GoodSubclass.new("good", good_init_values) }
|
73
|
-
let!(:bad_instance) { BadSubclass.new("bad", good_init_values) }
|
74
|
-
|
75
|
-
it "preserves nil values" do
|
76
|
-
good_instance.deflate_safe(nil).should be_nil
|
77
|
-
end
|
78
|
-
|
79
|
-
it "converts value as defined in subclass" do
|
80
|
-
good_instance.deflate_safe("10").should == 10
|
81
|
-
end
|
82
|
-
|
83
|
-
it "returns nil if conversion fails" do
|
84
|
-
bad_instance.deflate_safe(:foo).should be_nil
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PulseMeter::Sensor::Timelined::HashedCounter do
|
4
|
-
it_should_behave_like "timeline sensor", {}, {:foo => 1}
|
5
|
-
it_should_behave_like "timelined subclass", [{:foo => 1}, {:foo => 2}], {:foo => 3, :total => 3}.to_json
|
6
|
-
it_should_behave_like "timelined subclass", [{:foo => 1}, {:foo => :bad_value}], {:foo => 1, :total => 1}.to_json
|
7
|
-
it_should_behave_like "timelined subclass", [{:foo => 1}, {:boo => 2}], {:foo => 1, :boo => 2, :total => 3}.to_json
|
8
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PulseMeter::Sensor::Timelined::HashedIndicator do
|
4
|
-
it_should_behave_like "timeline sensor", {}, {:foo => 1}
|
5
|
-
it_should_behave_like "timelined subclass", [{:foo => 1}, {:foo => 2}], {:foo => 2}.to_json
|
6
|
-
it_should_behave_like "timelined subclass", [{:foo => 1}, {:foo => :bad_value}], {:foo => 1}.to_json
|
7
|
-
it_should_behave_like "timelined subclass", [{:foo => 1}, {:boo => 2}], {:foo => 1, :boo => 2}.to_json
|
8
|
-
end
|