fnordmetric 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/VERSION +1 -1
- data/doc/preview1.png +0 -0
- data/doc/preview2.png +0 -0
- data/doc/ulm_stats.rb +622 -0
- data/doc/version +1 -0
- data/fnordmetric.gemspec +16 -38
- data/haml/app.haml +12 -5
- data/lib/fnordmetric.rb +3 -0
- data/lib/fnordmetric/app.rb +19 -10
- data/lib/fnordmetric/bars_widget.rb +26 -0
- data/lib/fnordmetric/context.rb +3 -3
- data/lib/fnordmetric/gauge.rb +20 -0
- data/lib/fnordmetric/gauge_calculations.rb +28 -4
- data/lib/fnordmetric/gauge_modifiers.rb +39 -6
- data/lib/fnordmetric/logger.rb +19 -0
- data/lib/fnordmetric/numbers_widget.rb +5 -15
- data/lib/fnordmetric/pie_widget.rb +23 -0
- data/lib/fnordmetric/standalone.rb +1 -1
- data/lib/fnordmetric/timeline_widget.rb +16 -23
- data/lib/fnordmetric/toplist_widget.rb +25 -0
- data/lib/fnordmetric/widget.rb +3 -3
- data/pub/{fnordmetric/fnordmetric.css → fnordmetric.css} +46 -36
- data/pub/fnordmetric.js +1069 -0
- data/pub/loader.gif +0 -0
- data/pub/{highcharts → vendor}/highcharts.js +0 -0
- data/pub/{jquery-1.6.1.min.js → vendor/jquery-1.6.1.min.js} +0 -0
- data/readme.rdoc +228 -311
- data/spec/app_spec.rb +63 -3
- data/spec/gauge_modifiers_spec.rb +157 -2
- data/spec/gauge_spec.rb +143 -12
- data/spec/widget_spec.rb +18 -18
- metadata +33 -58
- data/.document +0 -5
- data/_spec/app_spec.rb +0 -178
- data/_spec/cache_spec.rb +0 -53
- data/_spec/combine_metric_spec.rb +0 -19
- data/_spec/core_spec.rb +0 -50
- data/_spec/count_metric_spec.rb +0 -32
- data/_spec/dashboard_spec.rb +0 -67
- data/_spec/event_spec.rb +0 -46
- data/_spec/metric_spec.rb +0 -118
- data/_spec/report_spec.rb +0 -87
- data/_spec/sum_metric_spec.rb +0 -33
- data/_spec/widget_spec.rb +0 -107
- data/doc/example_server.rb +0 -56
- data/doc/import_dump.rb +0 -26
- data/pub/fnordmetric/fnordmetric.js +0 -543
- data/pub/fnordmetric/widget_numbers.js +0 -71
- data/pub/fnordmetric/widget_timeline.css +0 -0
- data/pub/fnordmetric/widget_timeline.js +0 -110
- data/pub/highcharts/adapters/mootools-adapter.js +0 -12
- data/pub/highcharts/adapters/mootools-adapter.src.js +0 -243
- data/pub/highcharts/adapters/prototype-adapter.js +0 -14
- data/pub/highcharts/adapters/prototype-adapter.src.js +0 -284
- data/pub/highcharts/highcharts.src.js +0 -11103
- data/pub/highcharts/modules/exporting.js +0 -22
- data/pub/highcharts/modules/exporting.src.js +0 -703
- data/pub/highcharts/themes/dark-blue.js +0 -268
- data/pub/highcharts/themes/dark-green.js +0 -268
- data/pub/highcharts/themes/gray.js +0 -262
- data/pub/highcharts/themes/grid.js +0 -97
- data/pub/raphael-min.js +0 -8
- data/pub/raphael-utils.js +0 -221
- data/ulm_stats.rb +0 -198
data/_spec/cache_spec.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require ::File.expand_path('../spec_helper.rb', __FILE__)
|
2
|
-
|
3
|
-
describe FnordMetric::Cache do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
FnordMetric::Cache.destroy_all
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should store a cache item with a integer value" do
|
10
|
-
FnordMetric::Cache.store!('mykey', 123)
|
11
|
-
FnordMetric::Cache.last[:data].should be_a(Hash)
|
12
|
-
FnordMetric::Cache.last[:data].keys.should == ["value"]
|
13
|
-
FnordMetric::Cache.last[:data]["value"].to_i.should == 123
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should store a cache item with a float value" do
|
17
|
-
FnordMetric::Cache.store!('mykey', 123.5)
|
18
|
-
FnordMetric::Cache.last[:data].should be_a(Hash)
|
19
|
-
FnordMetric::Cache.last[:data].keys.should == ["value"]
|
20
|
-
FnordMetric::Cache.last[:data]["value"].to_f.should == 123.5
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should store a cache item with a hash value" do
|
24
|
-
FnordMetric::Cache.store!('mykey', :foobar => "fnord", :blubb => "asd")
|
25
|
-
FnordMetric::Cache.last[:data].should be_a(Hash)
|
26
|
-
FnordMetric::Cache.last[:data].keys.length.should == 2
|
27
|
-
FnordMetric::Cache.last[:data].keys.should include("foobar")
|
28
|
-
FnordMetric::Cache.last[:data].keys.should include("blubb")
|
29
|
-
FnordMetric::Cache.last[:data]["foobar"].should == "fnord"
|
30
|
-
FnordMetric::Cache.last[:data]["blubb"].should == "asd"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should get a cache item with a integer value" do
|
34
|
-
FnordMetric::Cache.store!('mykey', 123)
|
35
|
-
FnordMetric::Cache.get('mykey').should == 123
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should store a cache item with a float value" do
|
39
|
-
FnordMetric::Cache.store!('mykey', 42.5)
|
40
|
-
FnordMetric::Cache.get('mykey').should == 42.5
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should store a cache item with a hash value" do
|
44
|
-
FnordMetric::Cache.store!('mykey', :foobar => "fnord", :blubb => "asd")
|
45
|
-
FnordMetric::Cache.get('mykey').should be_a(Hash)
|
46
|
-
FnordMetric::Cache.get('mykey').keys.length.should == 2
|
47
|
-
FnordMetric::Cache.get('mykey').keys.should include("foobar")
|
48
|
-
FnordMetric::Cache.get('mykey').keys.should include("blubb")
|
49
|
-
FnordMetric::Cache.get('mykey')["foobar"].should == "fnord"
|
50
|
-
FnordMetric::Cache.get('mykey')["blubb"].should == "asd"
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require ::File.expand_path('../spec_helper.rb', __FILE__)
|
2
|
-
|
3
|
-
describe FnordMetric::CombineMetric do
|
4
|
-
|
5
|
-
it "should return the block return" do
|
6
|
-
metric = FnordMetric.metric('my_event_count', :combine => lambda{ |time_or_range|
|
7
|
-
2323
|
8
|
-
})
|
9
|
-
metric.current.should == 2323
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should pass the time_or_range to the bloc" do
|
13
|
-
metric = FnordMetric.metric('my_event_count', :combine => lambda{ |time_or_range|
|
14
|
-
time_or_range.to_i
|
15
|
-
})
|
16
|
-
metric.current.should == Time.now.to_i
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
data/_spec/core_spec.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require ::File.expand_path('../spec_helper.rb', __FILE__)
|
2
|
-
|
3
|
-
describe FnordMetric do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
FnordMetric::Event.destroy_all
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should define a new metric" do
|
10
|
-
FnordMetric.metric(:myfield_total, :sum => :myfield)
|
11
|
-
FnordMetric.metrics.keys.should include(:myfield_total)
|
12
|
-
FnordMetric.metrics[:myfield_total].should be_a(FnordMetric::Metric)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should define a new dashboard" do
|
16
|
-
FnordMetric.dashboard('My Dashboard'){ |dash| }
|
17
|
-
dashboard = FnordMetric.dashboards.last
|
18
|
-
dashboard.should be_a(FnordMetric::Dashboard)
|
19
|
-
dashboard.title.should == 'My Dashboard'
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should define a new dashboard and call the config block" do
|
23
|
-
block_called = false
|
24
|
-
FnordMetric.dashboard 'My Dashboard' do |dash|
|
25
|
-
block_called = true
|
26
|
-
dash.should be_a(FnordMetric::Dashboard)
|
27
|
-
end
|
28
|
-
block_called.should be_true
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should define a new widget" do
|
32
|
-
FnordMetric.metric(:my_metric, :sum => :my_field)
|
33
|
-
FnordMetric.widget(:my_widget, :metrics => :my_metric, :title => "My Widget", :type => :timeline)
|
34
|
-
FnordMetric.widgets[:my_widget].title.should == "My Widget"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should raise an error if no type option is provided" do
|
38
|
-
FnordMetric.metric(:my_metric, :sum => :my_field)
|
39
|
-
lambda{
|
40
|
-
FnordMetric.widget(:my_widget, :metrics => :my_metric, :title => "My Widget")
|
41
|
-
}.should raise_error(RuntimeError)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should raise an error if an unknown metric is added to a widget" do
|
45
|
-
lambda{
|
46
|
-
FnordMetric.widget(:my_widget, :metrics => :my_unknown_metric, :title => "My Widget", :type => :timeline)
|
47
|
-
}.should raise_error(RuntimeError)
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
data/_spec/count_metric_spec.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require ::File.expand_path('../spec_helper.rb', __FILE__)
|
2
|
-
|
3
|
-
describe FnordMetric::CountMetric do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
FnordMetric::Event.destroy_all
|
7
|
-
FnordMetric.track('my_event_type', :time => 33.hours.ago)
|
8
|
-
FnordMetric.track('my_event_type', :time => 32.hours.ago)
|
9
|
-
FnordMetric.track('my_event_type', :time => 28.hours.ago)
|
10
|
-
FnordMetric.track('my_event_type', :time => 27.hours.ago)
|
11
|
-
FnordMetric.track('my_event_type', :time => 26.hours.ago)
|
12
|
-
FnordMetric.track('my_event_type', :time => 13.hours.ago)
|
13
|
-
FnordMetric.track('my_event_type', :time => 12.hours.ago)
|
14
|
-
FnordMetric.track('my_event_type', :time => 11.hours.ago)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should count events until now" do
|
18
|
-
metric = FnordMetric.metric('my_event_count', :count => true, :types => [:my_event_type])
|
19
|
-
metric.current.should == 8
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should count events until 18 hours ago" do
|
23
|
-
metric = FnordMetric.metric('my_event_count', :count => true, :types => [:my_event_type])
|
24
|
-
metric.at(18.hours.ago).should == 5
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should count events from 30 to 20 hours ago" do
|
28
|
-
metric = FnordMetric.metric('my_event_count', :count => true, :types => [:my_event_type])
|
29
|
-
metric.at(30.hours.ago..20.hours.ago).should == 3
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/_spec/dashboard_spec.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require ::File.expand_path('../spec_helper.rb', __FILE__)
|
2
|
-
|
3
|
-
describe FnordMetric::Dashboard do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
FnordMetric::Event.destroy_all
|
7
|
-
FnordMetric.reset_metrics
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should remember it's title" do
|
11
|
-
dashboard = FnordMetric::Dashboard.new(:title => 'My Foobar Dashboard'){ |dash| }
|
12
|
-
dashboard.title.should == 'My Foobar Dashboard'
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should build a token" do
|
16
|
-
dashboard = FnordMetric::Dashboard.new(:title => 'My!F00bar-.Dash_board'){ |dash| }
|
17
|
-
dashboard.token.should == 'MyF00barDash_board'
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should add a widget" do
|
21
|
-
dashboard = FnordMetric::Dashboard.new(:title => 'My!F00bar-.Dash_board'){ |dash| }
|
22
|
-
FnordMetric.metric(:my_metric, :sum => :my_field)
|
23
|
-
widget = FnordMetric.widget(:my_widget, :metrics => :my_metric, :title => "My Widget", :type => :timeline)
|
24
|
-
dashboard.add_widget(widget)
|
25
|
-
dashboard.widgets.first.should == widget
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should add a widget by name" do
|
29
|
-
dashboard = FnordMetric::Dashboard.new(:title => 'My!F00bar-.Dash_board'){ |dash| }
|
30
|
-
FnordMetric.metric(:my_metric, :sum => :my_field)
|
31
|
-
widget = FnordMetric.widget(:my_widget, :metrics => :my_metric, :title => "My Widget", :type => :timeline)
|
32
|
-
dashboard.add_widget(:my_widget)
|
33
|
-
dashboard.widgets.first.should == widget
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should add the report on init (and to all widgets)" do
|
37
|
-
FnordMetric.metric(:my_metric, :sum => :my_field)
|
38
|
-
report = FnordMetric.report(:range => (4.days.ago..Time.now))
|
39
|
-
dashboard = FnordMetric::Dashboard.new(:title => 'My Foobar Dashboard', :report => report){ |dash|
|
40
|
-
dash.add_widget FnordMetric.widget(:my_widget, :metrics => :my_metric, :title => "My Widget", :type => :timeline)
|
41
|
-
}
|
42
|
-
dashboard.report.should == report
|
43
|
-
dashboard.widgets.last.report.should == report
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should add the report after init (and to all widgets)" do
|
47
|
-
FnordMetric.metric(:my_metric, :sum => :my_field)
|
48
|
-
report = FnordMetric.report(:range => (4.days.ago..Time.now))
|
49
|
-
dashboard = FnordMetric::Dashboard.new(:title => 'My Foobar Dashboard'){ |dash|
|
50
|
-
dash.add_widget FnordMetric.widget(:my_widget, :metrics => :my_metric, :title => "My Widget", :type => :timeline)
|
51
|
-
}
|
52
|
-
dashboard.report.should == nil
|
53
|
-
dashboard.add_report(report)
|
54
|
-
dashboard.report.should == report
|
55
|
-
dashboard.widgets.last.report.should == report
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should call the config block" do
|
59
|
-
block_called = false
|
60
|
-
FnordMetric::Dashboard.new(:title => 'My Dashboard') do |dash|
|
61
|
-
block_called = true
|
62
|
-
dash.should be_a(FnordMetric::Dashboard)
|
63
|
-
end
|
64
|
-
block_called.should be_true
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
data/_spec/event_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require ::File.expand_path('../spec_helper.rb', __FILE__)
|
2
|
-
|
3
|
-
include FnordMetric
|
4
|
-
|
5
|
-
describe "event" do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
Event.destroy_all
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should track an event" do
|
12
|
-
event = Event.track!('_referral', :foobar => "fnord")
|
13
|
-
Event.last[:type].should == "_referral"
|
14
|
-
Event.last[:foobar].should == "fnord"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should track an event via the proxy method" do
|
18
|
-
FnordMetric.track('blubb', :foo => "bar")
|
19
|
-
FnordMetric::Event.last.foo.should == "bar"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should access info like a 'ostruct' object" do
|
23
|
-
event = Event.track!('_referral', :foobar => "fnord")
|
24
|
-
Event.last.type.should == "_referral"
|
25
|
-
Event.last.foobar.should == "fnord"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should insert a data point in the past" do
|
29
|
-
my_time = 23.minutes.ago
|
30
|
-
event = Event.track!('_referral', :foobar => "fnord", :time => my_time)
|
31
|
-
Event.last[:type].should == "_referral"
|
32
|
-
Event.last[:foobar].should == "fnord"
|
33
|
-
Event.last[:time].should == my_time.to_i
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should save integer data" do
|
37
|
-
event = Event.track!('_test', :num => 23)
|
38
|
-
Event.last.num.should == 23
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should save float data" do
|
42
|
-
event = Event.track!('_test', :num => 42.5)
|
43
|
-
Event.last.num.should == 42.5
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
data/_spec/metric_spec.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
require ::File.expand_path('../spec_helper.rb', __FILE__)
|
2
|
-
|
3
|
-
describe FnordMetric::Metric do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
FnordMetric::Event.destroy_all
|
7
|
-
FnordMetric.track('my_event_type', :time => 33.hours.ago, :fnord => "a")
|
8
|
-
FnordMetric.track('my_event_type', :time => 32.hours.ago, :fnord => "b")
|
9
|
-
FnordMetric.track('my_event_type', :time => 28.hours.ago, :fnord => "c")
|
10
|
-
FnordMetric.track('my_event_type', :time => 27.hours.ago, :fnord => "d")
|
11
|
-
FnordMetric.track('my_event_type', :time => 26.hours.ago, :fnord => "e")
|
12
|
-
FnordMetric.track('another_event_type', :time => 26.hours.ago, :fnord => "x")
|
13
|
-
FnordMetric.track('my_event_type', :time => 13.hours.ago, :fnord => "f")
|
14
|
-
FnordMetric.track('my_event_type', :time => 12.hours.ago, :fnord => "g")
|
15
|
-
FnordMetric.track('my_event_type', :time => 11.hours.ago, :fnord => "h")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should find events by event_type" do
|
19
|
-
metric = FnordMetric::Metric.new(:types => [:my_event_type, :another_event_type])
|
20
|
-
metric.events.count.should == 9
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should find events by event_type" do
|
24
|
-
metric = FnordMetric::Metric.new(:types => [:my_event_type])
|
25
|
-
metric.events.count.should == 8
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should find events by event_type" do
|
29
|
-
metric = FnordMetric::Metric.new(:types => [:another_event_type])
|
30
|
-
metric.events.count.should == 1
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should find events by time range" do
|
34
|
-
metric = FnordMetric::Metric.new({})
|
35
|
-
metric.events_at(30.hours.ago..20.hours.ago).count.should == 4
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should find events by time range and event type" do
|
39
|
-
metric = FnordMetric::Metric.new(:types => [:my_event_type, :another_event_type])
|
40
|
-
metric.events_at(30.hours.ago..20.hours.ago).count.should == 4
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should find events by time range and event type" do
|
44
|
-
metric = FnordMetric::Metric.new(:types => [:my_event_type])
|
45
|
-
metric.events_at(30.hours.ago..20.hours.ago).count.should == 3
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should find events until time" do
|
49
|
-
metric = FnordMetric::Metric.new({})
|
50
|
-
metric.events_at(20.hours.ago).count.should == 6
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should find events until time and event type" do
|
54
|
-
metric = FnordMetric::Metric.new(:types => [:my_event_type, :another_event_type])
|
55
|
-
metric.events_at(20.hours.ago).count.should == 6
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should find events until time and event type" do
|
59
|
-
metric = FnordMetric::Metric.new(:types => [:my_event_type])
|
60
|
-
metric.events_at(20.hours.ago).count.should == 5
|
61
|
-
end
|
62
|
-
|
63
|
-
it "#from_options should return an instance of the right subclass" do
|
64
|
-
FnordMetric::Metric.from_options(:count => true).should be_a(FnordMetric::CountMetric)
|
65
|
-
FnordMetric::Metric.from_options(:sum => :fnord).should be_a(FnordMetric::SumMetric)
|
66
|
-
FnordMetric::Metric.from_options(:average => :f).should be_a(FnordMetric::AverageMetric)
|
67
|
-
FnordMetric::Metric.from_options(:combine => :l).should be_a(FnordMetric::CombineMetric)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "#from_options should raise if none of the mandatory opts is provided" do
|
71
|
-
lambda{ FnordMetric::Metric.from_options({}) }.should raise_error(RuntimeError)
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should never cache value_at(time) where time is in the future" do
|
75
|
-
FnordMetric::Metric.new({}).send(:cache_this?, Time.now.to_i+60).should be_false
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should never cache value_at(time) where time is now" do
|
79
|
-
FnordMetric::Metric.new({}).send(:cache_this?, Time.now.to_i).should be_false
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should always cache value_at(time) where time is in the past" do
|
83
|
-
FnordMetric::Metric.new({}).send(:cache_this?, Time.now.to_i-60).should be_true
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should never cache value_at(range) where range is completely in the future" do
|
87
|
-
range = ((Time.now.to_i+60)..(Time.now.to_i+120))
|
88
|
-
FnordMetric::Metric.new({}).send(:cache_this?, range).should be_false
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should never cache value_at(range) where range is partially in the future" do
|
92
|
-
range = ((Time.now.to_i-60)..(Time.now.to_i+120))
|
93
|
-
FnordMetric::Metric.new({}).send(:cache_this?, range).should be_false
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should never cache value_at(range) where range ends now" do
|
97
|
-
range = ((Time.now.to_i-60)..Time.now.to_i)
|
98
|
-
FnordMetric::Metric.new({}).send(:cache_this?, range).should be_false
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should always cache value_at(range) where range is completely in the past" do
|
102
|
-
range = ((Time.now.to_i-120)..(Time.now.to_i-60))
|
103
|
-
FnordMetric::Metric.new({}).send(:cache_this?, range).should be_true
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should generate a cache key for a time" do
|
107
|
-
time = Time.now.to_i - 120
|
108
|
-
metric = FnordMetric::Metric.new(:name => "my_foobar_metric")
|
109
|
-
metric.send(:cache_key, time).should == "my_foobar_metric|t#{time.to_i}"
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should generate a cache key for a range" do
|
113
|
-
range = ((Time.now.to_i-120)..(Time.now.to_i-60))
|
114
|
-
metric = FnordMetric::Metric.new(:name => "my_foobar_metric")
|
115
|
-
metric.send(:cache_key, range).should == "my_foobar_metric|r#{range.first.to_i}-#{range.last.to_i}"
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
data/_spec/report_spec.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
require ::File.expand_path('../spec_helper.rb', __FILE__)
|
2
|
-
|
3
|
-
describe FnordMetric::Report do
|
4
|
-
|
5
|
-
describe "Car Report" do
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
FnordMetric.reset_metrics
|
9
|
-
FnordMetric::Event.destroy_all
|
10
|
-
build_car_report_for_test!
|
11
|
-
sleep 1
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should build the car report" do
|
15
|
-
report = FnordMetric.report(:range => (3.days.ago..Time.now))
|
16
|
-
report.should be_a(FnordMetric::Report)
|
17
|
-
report.metrics.length.should == 4
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should return a metrics object for each defined metric" do
|
21
|
-
report = FnordMetric.report(:range => (3.days.ago..Time.now))
|
22
|
-
report.colors_total.should be_a(FnordMetric::Metric)
|
23
|
-
report.cars_total.should be_a(FnordMetric::Metric)
|
24
|
-
report.average_speed.should be_a(FnordMetric::Metric)
|
25
|
-
report.passengers_total.should be_a(FnordMetric::Metric)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should have the right total/current values" do
|
29
|
-
report = FnordMetric.report(:range => (3.days.ago..Time.now))
|
30
|
-
#report.colors_total.current.should == 3 # FIXME ~paul
|
31
|
-
report.cars_total.current.should == 7
|
32
|
-
#report.average_speed.current.should == 113.6 # FIXME ~paul
|
33
|
-
report.passengers_total.current.should == 16
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "Metric Types" do
|
39
|
-
|
40
|
-
before(:each) do
|
41
|
-
FnordMetric.reset_metrics
|
42
|
-
FnordMetric::Event.destroy_all
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should create a sum-metric if the sum-option is provided" do
|
46
|
-
FnordMetric.metric(:testmetric, :sum => :field_name)
|
47
|
-
report = FnordMetric.report(:range => (3.days.ago..Time.now))
|
48
|
-
report.testmetric.should be_a(FnordMetric::SumMetric)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should create avg-metric if the avg-option is provided" do
|
52
|
-
FnordMetric.metric(:testmetric, :average => :field_name)
|
53
|
-
report = FnordMetric.report(:range => (3.days.ago..Time.now))
|
54
|
-
report.testmetric.should be_a(FnordMetric::AverageMetric)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should create a count-metric if the count-option is provided" do
|
58
|
-
FnordMetric.metric(:testmetric, :count => true)
|
59
|
-
report = FnordMetric.report(:range => (3.days.ago..Time.now))
|
60
|
-
report.testmetric.should be_a(FnordMetric::CountMetric)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should create a sum-metric if the sum-option is provided" do
|
64
|
-
FnordMetric.metric(:testmetric, :combine => :lambda)
|
65
|
-
report = FnordMetric.report(:range => (3.days.ago..Time.now))
|
66
|
-
report.testmetric.should be_a(FnordMetric::CombineMetric)
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def build_car_report_for_test!
|
74
|
-
FnordMetric.metric(:colors_total, :count => true, :unique => :color, :types => ['car_seen'])
|
75
|
-
FnordMetric.metric(:cars_total, :count => true, :types => ['car_seen'])
|
76
|
-
FnordMetric.metric(:passengers_total, :sum => :passengers, :types => ['car_seen'])
|
77
|
-
FnordMetric.metric(:average_speed, :average => :speed, :types => ['car_seen'])
|
78
|
-
FnordMetric.track('car_seen', :color => "red", :speed => 130, :passengers => 2)
|
79
|
-
FnordMetric.track('car_seen', :color => "pink", :speed => 150, :passengers => 1)
|
80
|
-
FnordMetric.track('car_seen', :color => "red", :speed => 65, :passengers => 4)
|
81
|
-
FnordMetric.track('car_seen', :color => "blue", :speed => 100, :passengers => 2)
|
82
|
-
FnordMetric.track('car_seen', :color => "red", :speed => 123, :passengers => 2)
|
83
|
-
FnordMetric.track('car_seen', :color => "blue", :speed => 130, :passengers => 3)
|
84
|
-
FnordMetric.track('car_seen', :color => "red", :speed => 142, :passengers => 2)
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|