fnordmetric 0.7.1 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ source :rubygems
3
3
  gemspec
4
4
 
5
5
  gem "rake"
6
- gem "yajl-ruby", :git => "git://github.com/brianmario/yajl-ruby.git"
6
+ gem "yajl-ruby", :git => "git://github.com/brianmario/yajl-ruby.git"
data/doc/full_example.rb CHANGED
@@ -15,14 +15,14 @@ FnordMetric.namespace :ulm do
15
15
  gauge :messages_read, :tick => 1.day.to_i, :title => "Messages (read)"
16
16
  gauge :winks_sent, :tick => 1.day.to_i, :title => "Winks sent"
17
17
 
18
- gauge :pageviews_per_url_daily,
19
- :tick => 1.day.to_i,
20
- :title => "Daily Pageviews per URL",
18
+ gauge :pageviews_per_url_daily,
19
+ :tick => 1.day.to_i,
20
+ :title => "Daily Pageviews per URL",
21
21
  :three_dimensional => true
22
22
 
23
- gauge :pageviews_per_url_monthly,
24
- :tick => 30.days.to_i,
25
- :title => "Monthly Pageviews per URL",
23
+ gauge :pageviews_per_url_monthly,
24
+ :tick => 30.days.to_i,
25
+ :title => "Monthly Pageviews per URL",
26
26
  :three_dimensional => true
27
27
 
28
28
  event :_pageview do
@@ -124,8 +124,8 @@ FnordMetric.namespace :ulm do
124
124
  :width => 67,
125
125
  :autoupdate => 30,
126
126
  :gauges => [
127
- :skip_votes, :yes_votes,
128
- :maybe_votes, :winks_sent, :messages_sent, :messages_read,
127
+ :skip_votes, :yes_votes,
128
+ :maybe_votes, :winks_sent, :messages_sent, :messages_read,
129
129
  ]
130
130
  }
131
131
 
@@ -235,7 +235,7 @@ FnordMetric.namespace :ulm do
235
235
  if %w(ry201112a ry201112b ry201112_ref).include?(data[:campaign_key])
236
236
  incr :rockyou1_requests
237
237
  end
238
- end
238
+ end
239
239
 
240
240
  widget 'Campaigns', {
241
241
  :title => "RockYou (1) - PPI vs. Requests vs. Refs",
@@ -263,38 +263,38 @@ FnordMetric.namespace :ulm do
263
263
 
264
264
 
265
265
 
266
- gauge :abtest_sidebar_btn_totals,
267
- :tick => 36000.days.to_i,
268
- :title => "(A/B) sidebar_btn: Totals",
266
+ gauge :abtest_sidebar_btn_totals,
267
+ :tick => 36000.days.to_i,
268
+ :title => "(A/B) sidebar_btn: Totals",
269
269
  :three_dimensional => true
270
270
 
271
- gauge :abtest_sidebar_btn_daily,
272
- :tick => 1.day.to_i,
273
- :title => "(A/B) sidebar_btn: Daily",
271
+ gauge :abtest_sidebar_btn_daily,
272
+ :tick => 1.day.to_i,
273
+ :title => "(A/B) sidebar_btn: Daily",
274
274
  :three_dimensional => true
275
275
 
276
- gauge :abtest_sidebar_btn_leute_treffen,
277
- :tick => 1.day.to_i,
276
+ gauge :abtest_sidebar_btn_leute_treffen,
277
+ :tick => 1.day.to_i,
278
278
  :title => "leute_treffen"
279
279
 
280
- gauge :abtest_sidebar_btn_jetzt_losflirten,
281
- :tick => 1.day.to_i,
280
+ gauge :abtest_sidebar_btn_jetzt_losflirten,
281
+ :tick => 1.day.to_i,
282
282
  :title => "jetzt_losflirten"
283
283
 
284
- gauge :abtest_sidebar_btn_dates_finden,
285
- :tick => 1.day.to_i,
284
+ gauge :abtest_sidebar_btn_dates_finden,
285
+ :tick => 1.day.to_i,
286
286
  :title => "dates_finden"
287
287
 
288
- gauge :abtest_sidebar_btn_leute_treffen_monthly,
289
- :tick => 1.month.to_i,
288
+ gauge :abtest_sidebar_btn_leute_treffen_monthly,
289
+ :tick => 1.month.to_i,
290
290
  :title => "leute_treffen"
291
291
 
292
- gauge :abtest_sidebar_btn_jetzt_losflirten_monthly,
293
- :tick => 1.month.to_i,
292
+ gauge :abtest_sidebar_btn_jetzt_losflirten_monthly,
293
+ :tick => 1.month.to_i,
294
294
  :title => "jetzt_losflirten"
295
295
 
296
- gauge :abtest_sidebar_btn_dates_finden_monthly,
297
- :tick => 1.month.to_i,
296
+ gauge :abtest_sidebar_btn_dates_finden_monthly,
297
+ :tick => 1.month.to_i,
298
298
  :title => "dates_finden"
299
299
 
300
300
 
@@ -428,46 +428,46 @@ FnordMetric.namespace :ulm do
428
428
  end
429
429
 
430
430
 
431
- gauge :competitors_badoo_mau,
431
+ gauge :competitors_badoo_mau,
432
432
  :tick => 1.day.to_i,
433
433
  :title => "Badoo (MAU)"
434
434
 
435
- gauge :competitors_badoo_dau,
435
+ gauge :competitors_badoo_dau,
436
436
  :tick => 1.day.to_i,
437
437
  :title => "Badoo (DAU)"
438
438
 
439
- gauge :competitors_zoosk_mau,
439
+ gauge :competitors_zoosk_mau,
440
440
  :tick => 1.day.to_i,
441
441
  :title => "zoosk (MAU)"
442
442
 
443
- gauge :competitors_zoosk_dau,
443
+ gauge :competitors_zoosk_dau,
444
444
  :tick => 1.day.to_i,
445
445
  :title => "zoosk (DAU)"
446
446
 
447
- gauge :competitors_areyouinterested_mau,
447
+ gauge :competitors_areyouinterested_mau,
448
448
  :tick => 1.day.to_i,
449
449
  :title => "areyouinterested (MAU)"
450
450
 
451
- gauge :competitors_areyouinterested_dau,
451
+ gauge :competitors_areyouinterested_dau,
452
452
  :tick => 1.day.to_i,
453
453
  :title => "areyouinterested (DAU)"
454
454
 
455
- gauge :competitors_onetwolike_mau,
455
+ gauge :competitors_onetwolike_mau,
456
456
  :tick => 1.day.to_i,
457
457
  :title => "onetwolike (MAU)"
458
458
 
459
- gauge :competitors_onetwolike_dau,
459
+ gauge :competitors_onetwolike_dau,
460
460
  :tick => 1.day.to_i,
461
461
  :title => "onetwolike (DAU)"
462
462
 
463
- gauge :competitors_kizzle_mau,
463
+ gauge :competitors_kizzle_mau,
464
464
  :tick => 1.day.to_i,
465
465
  :title => "kizzle (MAU)"
466
466
 
467
- gauge :competitors_kizzle_dau,
467
+ gauge :competitors_kizzle_dau,
468
468
  :tick => 1.day.to_i,
469
469
  :title => "kizzle (DAU)"
470
-
470
+
471
471
  event :competition_data do
472
472
  set_value(:competitors_badoo_mau, data[:badoo_mau]) if data[:badoo_mau]
473
473
  set_value(:competitors_badoo_dau, data[:badoo_dau]) if data[:badoo_dau]
@@ -557,7 +557,7 @@ FnordMetric.namespace :ulm do
557
557
  gauge :events_per_hour, :tick => 1.hour.to_i
558
558
  gauge :events_per_second, :tick => 1
559
559
  gauge :votes_per_second, :tick => 1
560
-
560
+
561
561
  event :"*" do
562
562
  incr :events_per_minute
563
563
  incr :events_per_hour
@@ -1,4 +1,3 @@
1
- require 'securerandom'
2
1
  class FnordMetric::API
3
2
  @@opts = nil
4
3
 
@@ -42,6 +41,6 @@ class FnordMetric::API
42
41
  end
43
42
 
44
43
  def get_next_uuid
45
- SecureRandom.uuid
44
+ rand(8**32).to_s(36)
46
45
  end
47
46
  end
@@ -10,9 +10,9 @@ class FnordMetric::App < Sinatra::Base
10
10
  "vendor/highcharts.js" => "application/x-javascript"
11
11
  }
12
12
 
13
- Encoding.default_external = Encoding::UTF_8
14
-
15
- #use Rack::Reloader, 0
13
+ if RUBY_VERSION =~ /1.9.\d/
14
+ Encoding.default_external = Encoding::UTF_8
15
+ end
16
16
 
17
17
  enable :session
18
18
 
@@ -0,0 +1,3 @@
1
+ class Symbol
2
+ alias :intern :to_sym
3
+ end
@@ -0,0 +1,35 @@
1
+ class FnordMetric::InboundDatagram < EventMachine::Connection
2
+
3
+ class << self
4
+ attr_accessor :opts
5
+ end
6
+
7
+ def self.start(opts)
8
+ self.opts = opts
9
+ EM.open_datagram_socket(*opts[:inbound_stream], self, opts)
10
+ end
11
+
12
+ def receive_data(event)
13
+ events << event
14
+ push_next_event
15
+ end
16
+
17
+ def push_next_event
18
+ return true if events.empty?
19
+ api.event(@events.pop)
20
+ EM.next_tick(&method(:push_next_event))
21
+ end
22
+
23
+ def unbind
24
+ api.disconnect
25
+ end
26
+
27
+ def api
28
+ @api ||= FnordMetric::API.new(self.class.opts)
29
+ end
30
+
31
+ def events
32
+ @events ||= []
33
+ end
34
+
35
+ end
@@ -1,17 +1,17 @@
1
- class FnordMetric::InboundStream < EventMachine::Connection
1
+ class FnordMetric::InboundStream < EventMachine::Connection
2
2
  @@opts = nil
3
3
 
4
4
  def self.start(opts)
5
5
  @@opts = opts
6
- EM.start_server(*opts[:inbound_stream], self)
6
+ EM.start_server(*(opts[:inbound_stream] << self))
7
7
  end
8
8
 
9
9
  def self.options(opts)
10
10
  @@opts = opts
11
11
  end
12
12
 
13
- def receive_data(chunk)
14
- @buffer << chunk
13
+ def receive_data(chunk)
14
+ @buffer << chunk
15
15
  next_event
16
16
  end
17
17
 
@@ -19,12 +19,12 @@ class FnordMetric::InboundStream < EventMachine::Connection
19
19
  read_next_event
20
20
  push_next_event
21
21
  end
22
-
22
+
23
23
  def read_next_event
24
24
  while (event = @buffer.slice!(/^(.*)\n/))
25
25
  @events_buffered += 1
26
26
  @events << event
27
- end
27
+ end
28
28
  end
29
29
 
30
30
  def push_next_event
@@ -32,11 +32,11 @@ class FnordMetric::InboundStream < EventMachine::Connection
32
32
  @events_buffered -= 1
33
33
  @api.event(@events.pop)
34
34
  close_connection?
35
- EM.next_tick(&method(:push_next_event))
35
+ EM.next_tick(&method(:push_next_event))
36
36
  end
37
37
 
38
38
  def close_connection?
39
- @api.disconnect unless @streaming || (@events_buffered!=0)
39
+ @api.disconnect unless @streaming || (@events_buffered!=0)
40
40
  end
41
41
 
42
42
  def post_init
@@ -97,8 +97,8 @@ class FnordMetric::Session
97
97
  end
98
98
 
99
99
  def add_event_data(event)
100
- event.each do |key,value|
101
- add_data(key, value) unless key[0]=="_"
100
+ event.each do |key, value|
101
+ add_data(key, value) unless key.to_s.starts_with?("_")
102
102
  end
103
103
  end
104
104
 
@@ -109,7 +109,7 @@ class FnordMetric::Session
109
109
  def fetch_data!
110
110
  @data = Hash.new
111
111
  @redis.hgetall(redis_key(:data)).each do |key, value|
112
- if key[0]=="_"
112
+ if key.to_s.starts_with?("_")
113
113
  fetch_meta_key(key, value)
114
114
  else
115
115
  @data[key.intern] = value
@@ -5,6 +5,15 @@ task :run do
5
5
  FnordMetric.run
6
6
  end
7
7
 
8
+ task :worker do
9
+ FnordMetric.server_configuration = {
10
+ :web_interface => false,
11
+ :inbound_stream => false,
12
+ :start_worker => true
13
+ }
14
+ FnordMetric.run
15
+ end
16
+
8
17
  task :log do
9
18
  FnordMetric::Logger.start(dump_file_path)
10
19
  end
@@ -14,16 +23,16 @@ task :import do
14
23
  end
15
24
 
16
25
  task :help do
17
- puts "usage: #{$0} {run|log|import} [DUMP_FILE=fm_dump.json]"
26
+ puts "usage: #{$0} {run|worker|log|import} [DUMP_FILE=fm_dump.json]"
18
27
  end
19
28
 
20
29
  task :default => :help
21
30
 
22
31
  def dump_file_path
23
32
  if ENV["DUMP_FILE"].blank?
24
- Rake::Task[:help].execute; exit!
33
+ Rake::Task[:help].execute; exit!
25
34
  else
26
- ::File.expand_path(ENV["DUMP_FILE"], ::File.dirname($0))
35
+ ::File.expand_path(ENV["DUMP_FILE"], ::File.dirname($0))
27
36
  end
28
37
  end
29
38
 
@@ -0,0 +1,22 @@
1
+ class FnordMetric::UDPClient
2
+
3
+ def initialize(host, port)
4
+ @sock = UDPSocket.new
5
+ @sock.connect(host, port)
6
+ end
7
+
8
+ def event(event_data)
9
+ begin
10
+ if event_data.is_a?(Hash)
11
+ event_data = event_data.to_json
12
+ else
13
+ JSON.parse(event_data) # void ;)
14
+ end
15
+ rescue JSON::ParserError
16
+ FnordMetric.log("event_lost: can't parse json")
17
+ else
18
+ @sock.send(event_data, 0)
19
+ end
20
+ end
21
+
22
+ end
@@ -1,3 +1,3 @@
1
1
  module FnordMetric
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.3"
3
3
  end
data/lib/fnordmetric.rb CHANGED
@@ -7,11 +7,13 @@ require 'sinatra/base'
7
7
  require 'haml'
8
8
  require 'rack/server'
9
9
 
10
+ require "fnordmetric/ext"
10
11
  require "fnordmetric/version"
11
12
 
12
13
  module FnordMetric
13
14
 
14
15
  @@namespaces = {}
16
+ @@server_configuration = nil
15
17
 
16
18
  def self.namespace(key=nil, &block)
17
19
  @@namespaces[key] = block
@@ -26,6 +28,7 @@ module FnordMetric
26
28
  :redis_url => "redis://localhost:6379",
27
29
  :redis_prefix => "fnordmetric",
28
30
  :inbound_stream => ["0.0.0.0", "1337"],
31
+ :inbound_protocol => :tcp,
29
32
  :web_interface => ["0.0.0.0", "4242"],
30
33
  :web_interface_server => "thin",
31
34
  :start_worker => true,
@@ -75,6 +78,7 @@ module FnordMetric
75
78
  def self.run
76
79
  start_em
77
80
  rescue Exception => e
81
+ raise e
78
82
  log "!!! eventmachine died, restarting... #{e.message}"
79
83
  sleep(1); run
80
84
  end
@@ -122,11 +126,12 @@ module FnordMetric
122
126
  end
123
127
 
124
128
  if opts[:inbound_stream]
129
+ inbound_class = opts[:inbound_protocol] == :udp ? InboundDatagram : InboundStream
125
130
  begin
126
- inbound_stream = InboundStream.start(opts)
127
- log "listening on tcp##{opts[:inbound_stream].join(":")}"
131
+ inbound_stream = inbound_class.start(opts)
132
+ log "listening on #{opts[:inbound_protocol]}##{opts[:inbound_stream].join(":")}"
128
133
  rescue
129
- log "cant start FnordMetric::InboundStream. port in use?"
134
+ log "cant start #{inbound_class.name}. port in use?"
130
135
  end
131
136
  end
132
137
 
@@ -144,7 +149,9 @@ module FnordMetric
144
149
  end
145
150
 
146
151
  require "fnordmetric/api"
152
+ require "fnordmetric/udp_client"
147
153
  require "fnordmetric/inbound_stream"
154
+ require "fnordmetric/inbound_datagram"
148
155
  require "fnordmetric/worker"
149
156
  require "fnordmetric/widget"
150
157
  require "fnordmetric/timeline_widget"
data/spec/api_spec.rb CHANGED
@@ -17,7 +17,7 @@ describe FnordMetric::Event do
17
17
  :redis_prefix => "fnordmetric-test",
18
18
  :redis => @redis
19
19
  }
20
- @api = API.new @opts
20
+ @api = FnordMetric::API.new @opts
21
21
  end
22
22
 
23
23
  describe "creating events using API" do
@@ -32,7 +32,7 @@ describe FnordMetric::Event do
32
32
  :_time => @now
33
33
  }.to_json
34
34
  event_id = @api.event(json_string)
35
- event = Event.find(event_id, @opts)
35
+ event = FnordMetric::Event.find(event_id, @opts)
36
36
  event.type.should == "Fn0rd123"
37
37
  end
38
38
 
@@ -41,7 +41,7 @@ describe FnordMetric::Event do
41
41
  :_type => "Fn0rd234",
42
42
  :_time => @now
43
43
  )
44
- event = Event.find(event_id, @opts)
44
+ event = FnordMetric::Event.find(event_id, @opts)
45
45
  event.type.should == "Fn0rd234"
46
46
  end
47
47
 
data/spec/ext_spec.rb ADDED
@@ -0,0 +1,14 @@
1
+ require ::File.expand_path('../spec_helper.rb', __FILE__)
2
+
3
+ describe "core extensions" do
4
+
5
+ include FnordMetric
6
+
7
+ describe Symbol do
8
+ it "should return self when intern was called" do
9
+ sym = :fnord
10
+ sym.intern.should == sym
11
+ end
12
+ end
13
+
14
+ end
data/spec/gauge_spec.rb CHANGED
@@ -28,25 +28,25 @@ describe FnordMetric::Gauge do
28
28
  end
29
29
 
30
30
  it "should raise an error when initialize without key" do
31
- lambda{
32
- FnordMetric::Gauge.new({:key_prefix => "foo"})
33
- }.should raise_error(KeyError)
31
+ lambda{
32
+ FnordMetric::Gauge.new({:key_prefix => "foo"})
33
+ }.should raise_error(key_error_klass)
34
34
  end
35
35
 
36
36
  it "should raise an error when initialize without key_prefix" do
37
- lambda{
38
- FnordMetric::Gauge.new({:key => "foo"})
39
- }.should raise_error(KeyError)
37
+ lambda{
38
+ FnordMetric::Gauge.new({:key => "foo"})
39
+ }.should raise_error(key_error_klass)
40
40
  end
41
41
 
42
42
  it "should generate the correct key without append" do
43
- gauge = FnordMetric::Gauge.new({:key_prefix => "fnordmetrics-myns", :key => "mygauge", :tick => 23})
44
- gauge.key.should == "fnordmetrics-myns-gauge-mygauge-23"
43
+ gauge = FnordMetric::Gauge.new({:key_prefix => "fnordmetrics-myns", :key => "mygauge", :tick => 23})
44
+ gauge.key.should == "fnordmetrics-myns-gauge-mygauge-23"
45
45
  end
46
46
 
47
47
  it "should generate the correct key with append" do
48
- gauge = FnordMetric::Gauge.new({:key_prefix => "fnordmetrics-myns", :key => "mygauge", :tick => 23})
49
- gauge.key(:fnord).should == "fnordmetrics-myns-gauge-mygauge-23-fnord"
48
+ gauge = FnordMetric::Gauge.new({:key_prefix => "fnordmetrics-myns", :key => "mygauge", :tick => 23})
49
+ gauge.key(:fnord).should == "fnordmetrics-myns-gauge-mygauge-23-fnord"
50
50
  end
51
51
 
52
52
  describe "ticks" do
@@ -93,7 +93,7 @@ describe FnordMetric::Gauge do
93
93
  it "should retrieve a gauge value at the current tick"
94
94
 
95
95
  it "should call the value calculation block and return the result" do
96
- @gauge.value_at(@now){ |v| v.to_i + 123 }.should == 177
96
+ @gauge.value_at(@now){ |v, t| v.to_i + 123 }.should == 177
97
97
  end
98
98
 
99
99
  it "should return the correct value_at per session" do
@@ -166,7 +166,7 @@ describe FnordMetric::Gauge do
166
166
  end
167
167
 
168
168
  it "should receive gauge values with custom calculation for multiple ticks" do
169
- @gauge.values_at([@now, @now+8]){ |val|
169
+ @gauge.values_at([@now, @now+8]){ |val, time|
170
170
  val.to_i + 30
171
171
  }.should == {
172
172
  695280200 => 84,
@@ -230,7 +230,7 @@ describe FnordMetric::Gauge do
230
230
  end
231
231
 
232
232
  it "should call the value calculation block and return the result" do
233
- vals = @gauge.field_values_at(1323691200){ |v| v.to_i + 123 }
233
+ vals = @gauge.field_values_at(1323691200){ |v, t| v.to_i + 123 }
234
234
  vals.should be_a(Array)
235
235
  vals.length.should == 2
236
236
  vals[0].should == ["uberfoo", 146]
@@ -0,0 +1,34 @@
1
+ require ::File.expand_path('../spec_helper.rb', __FILE__)
2
+
3
+ describe FnordMetric::InboundDatagram do
4
+
5
+ let(:inbound_datagram) { FnordMetric::InboundDatagram.new(nil) }
6
+
7
+ before(:all) do
8
+ @redis = Redis.new
9
+ @redis_wrap = RedisWrap.new(@redis)
10
+ FnordMetric::InboundDatagram.opts = {
11
+ :redis_url => "redis://localhost:6379",
12
+ :redis_prefix => "fnordmetric-test",
13
+ :event_queue_ttl => 120
14
+ }
15
+ end
16
+
17
+ describe "pushing new events" do
18
+ it "should add parsable event to the queue" do
19
+ data = %Q{{"_type": "started"}}
20
+
21
+ lambda {
22
+ inbound_datagram.receive_data data
23
+ }.should change { @redis.llen("fnordmetric-test-queue") }.by +1
24
+ end
25
+
26
+ it "should reject non parsable events" do
27
+ broken_data = %Q{{"_type" => "started"}}
28
+
29
+ lambda {
30
+ inbound_datagram.receive_data broken_data
31
+ }.should_not change { @redis.llen("fnordmetric-test-queue") }
32
+ end
33
+ end
34
+ end
@@ -24,7 +24,7 @@ describe FnordMetric::InboundStream do
24
24
 
25
25
  it "should reject non parsable events" do
26
26
  broken_data = %Q{{"_type": \n"started"}\n}
27
-
27
+
28
28
  lambda {
29
29
  @inbound_stream.receive_data broken_data
30
30
  }.should_not change { @redis.llen("fnordmetric-test-queue") }
data/spec/session_spec.rb CHANGED
@@ -25,7 +25,7 @@ describe FnordMetric::Session do
25
25
  end
26
26
 
27
27
  it "should add a new session on intialize" do
28
- Session.create(
28
+ FnordMetric::Session.create(
29
29
  :namespace_prefix => @namespace,
30
30
  :event => @event,
31
31
  :session_data_ttl => 10,
@@ -35,7 +35,7 @@ describe FnordMetric::Session do
35
35
  end
36
36
 
37
37
  it "should add a new session on intialize and hash the session token" do
38
- Session.create(
38
+ FnordMetric::Session.create(
39
39
  :namespace_prefix => @namespace,
40
40
  :event => @event,
41
41
  :session_data_ttl => 10,
@@ -45,7 +45,7 @@ describe FnordMetric::Session do
45
45
  end
46
46
 
47
47
  it "should add a new session on intialize and set the timestamp as score" do
48
- Session.create(
48
+ FnordMetric::Session.create(
49
49
  :namespace_prefix => @namespace,
50
50
  :event => @event,
51
51
  :session_data_ttl => 10,
@@ -57,7 +57,7 @@ describe FnordMetric::Session do
57
57
  it "should update the timestamp on a existing session" do
58
58
  @redis.zadd(@sessions, @now-10, @md5_key)
59
59
  @redis.zscore(@sessions, @md5_key).to_i.should == @now-10
60
- Session.create(
60
+ FnordMetric::Session.create(
61
61
  :namespace_prefix => @namespace,
62
62
  :event => @event,
63
63
  :session_data_ttl => 10,
@@ -67,7 +67,7 @@ describe FnordMetric::Session do
67
67
  end
68
68
 
69
69
  it "should add the event_id to the session-event set on a new session" do
70
- Session.create(
70
+ FnordMetric::Session.create(
71
71
  :namespace_prefix => @namespace,
72
72
  :event => @event,
73
73
  :session_data_ttl => 10,
@@ -82,7 +82,7 @@ describe FnordMetric::Session do
82
82
  :_type => "_set_name",
83
83
  :name => "Horst Mayer"
84
84
  )
85
- Session.create(
85
+ FnordMetric::Session.create(
86
86
  :namespace_prefix => @namespace,
87
87
  :event => event_data,
88
88
  :session_data_ttl => 10,
@@ -97,7 +97,7 @@ describe FnordMetric::Session do
97
97
  :_type => "_set_picture",
98
98
  :url => "http://myhost/mypic.jpg"
99
99
  )
100
- Session.create(
100
+ FnordMetric::Session.create(
101
101
  :namespace_prefix => @namespace,
102
102
  :event => event_data,
103
103
  :session_data_ttl => 10,
@@ -113,7 +113,7 @@ describe FnordMetric::Session do
113
113
  :fnord => "blubb",
114
114
  :foobar => "123"
115
115
  )
116
- Session.create(
116
+ FnordMetric::Session.create(
117
117
  :namespace_prefix => @namespace,
118
118
  :event => event_data,
119
119
  :session_data_ttl => 10,
@@ -130,7 +130,7 @@ describe FnordMetric::Session do
130
130
  :fnord => "blubb",
131
131
  :foobar => "123"
132
132
  )
133
- Session.create(
133
+ FnordMetric::Session.create(
134
134
  :namespace_prefix => @namespace,
135
135
  :event => event_data,
136
136
  :session_data_ttl => 10,
@@ -159,24 +159,24 @@ describe FnordMetric::Session do
159
159
  it "should find all sessions" do
160
160
  create_session("sess533", @now, {})
161
161
  create_session("sess343", @now, {})
162
- Session.all(@opts).length.should == 2
162
+ FnordMetric::Session.all(@opts).length.should == 2
163
163
  end
164
164
 
165
165
  it "should find all sessions and return session objects" do
166
166
  create_session("sess523", @now, {})
167
- Session.all(@opts).first.should be_a(FnordMetric::Session)
167
+ FnordMetric::Session.all(@opts).first.should be_a(FnordMetric::Session)
168
168
  end
169
169
 
170
170
  it "should find a session and return a session object" do
171
171
  create_session("sess223", @now, {})
172
- sess = Session.find(Digest::MD5.hexdigest("sess223"), @opts)
172
+ sess = FnordMetric::Session.find(Digest::MD5.hexdigest("sess223"), @opts)
173
173
  sess.should be_a(FnordMetric::Session)
174
174
  sess.session_key.should == Digest::MD5.hexdigest("sess223")
175
175
  end
176
176
 
177
177
  it "should find a sessions and return a session object with data" do
178
178
  create_session("sess123", @now, { :fnord => "blubb" })
179
- sess = Session.find(Digest::MD5.hexdigest("sess123"), @opts)
179
+ sess = FnordMetric::Session.find(Digest::MD5.hexdigest("sess123"), @opts)
180
180
  sess.fetch_data!
181
181
  sess.data(:fnord).should == "blubb"
182
182
  end
@@ -184,7 +184,7 @@ describe FnordMetric::Session do
184
184
  it "should not include special attributes in data" do
185
185
  event_data = { :_name => "Horst Mayer", :_picture => "http://myhost/mypic.jpg" }
186
186
  create_session("sess173", @now, event_data)
187
- sess = Session.find(Digest::MD5.hexdigest("sess173"), @opts)
187
+ sess = FnordMetric::Session.find(Digest::MD5.hexdigest("sess173"), @opts)
188
188
  sess.fetch_data!
189
189
  sess.data(:_name).should == nil
190
190
  sess.data(:_picture).should == nil
@@ -193,7 +193,7 @@ describe FnordMetric::Session do
193
193
  it "should find a session and return a session object with picture" do
194
194
  event_data = { :_name => "Horst Mayer", :_picture => "http://myhost/mypic.jpg" }
195
195
  create_session("sess163", @now, event_data)
196
- sess = Session.find(Digest::MD5.hexdigest("sess163"), @opts)
196
+ sess = FnordMetric::Session.find(Digest::MD5.hexdigest("sess163"), @opts)
197
197
  sess.fetch_data!
198
198
  sess.picture.should == "http://myhost/mypic.jpg"
199
199
  end
@@ -201,7 +201,7 @@ describe FnordMetric::Session do
201
201
  it "should find a session and return a session object with name" do
202
202
  event_data = { :_name => "Horst Mayer", :_picture => "http://myhost/mypic.jpg" }
203
203
  create_session("sess143", @now, event_data)
204
- sess = Session.find(Digest::MD5.hexdigest("sess143"), @opts)
204
+ sess = FnordMetric::Session.find(Digest::MD5.hexdigest("sess143"), @opts)
205
205
  sess.fetch_data!
206
206
  sess.name.should == "Horst Mayer"
207
207
  end
@@ -210,7 +210,7 @@ describe FnordMetric::Session do
210
210
  sesshash = create_session("sess923", @now, {})
211
211
  @redis_wrap.zadd("#{@namespace}-session-#{sesshash}-events", @now, "shmoo")
212
212
  @redis_wrap.zadd("#{@namespace}-session-#{sesshash}-events", @now, "fnord")
213
- sess = Session.find(sesshash, @opts)
213
+ sess = FnordMetric::Session.find(sesshash, @opts)
214
214
  sess.fetch_event_ids!
215
215
  sess.event_ids.should include("shmoo")
216
216
  sess.event_ids.should include("fnord")
data/spec/spec_helper.rb CHANGED
@@ -36,3 +36,7 @@ class RedisWrap
36
36
  end
37
37
 
38
38
  end
39
+
40
+ def key_error_klass
41
+ RUBY_VERSION =~ /1.9.\d/ ? KeyError : IndexError
42
+ end
metadata CHANGED
@@ -1,204 +1,199 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: fnordmetric
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.3
4
5
  prerelease:
5
- version: 0.7.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Paul Asmuth
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-04-21 00:00:00 +02:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: bson_ext
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &83157930 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
24
21
  version: 1.4.0
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: sinatra
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *83157930
25
+ - !ruby/object:Gem::Dependency
26
+ name: sinatra
27
+ requirement: &83157680 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
35
32
  version: 1.2.6
36
33
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: redis
40
34
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *83157680
36
+ - !ruby/object:Gem::Dependency
37
+ name: redis
38
+ requirement: &83157420 !ruby/object:Gem::Requirement
42
39
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
46
43
  version: 2.2.2
47
44
  type: :runtime
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: eventmachine
51
45
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *83157420
47
+ - !ruby/object:Gem::Dependency
48
+ name: eventmachine
49
+ requirement: &83157230 !ruby/object:Gem::Requirement
53
50
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
58
55
  type: :runtime
59
- version_requirements: *id004
60
- - !ruby/object:Gem::Dependency
61
- name: em-hiredis
62
56
  prerelease: false
63
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *83157230
58
+ - !ruby/object:Gem::Dependency
59
+ name: em-hiredis
60
+ requirement: &83156900 !ruby/object:Gem::Requirement
64
61
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
69
66
  type: :runtime
70
- version_requirements: *id005
71
- - !ruby/object:Gem::Dependency
72
- name: json
73
67
  prerelease: false
74
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *83156900
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: &83156630 !ruby/object:Gem::Requirement
75
72
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
80
77
  type: :runtime
81
- version_requirements: *id006
82
- - !ruby/object:Gem::Dependency
83
- name: i18n
84
78
  prerelease: false
85
- requirement: &id007 !ruby/object:Gem::Requirement
79
+ version_requirements: *83156630
80
+ - !ruby/object:Gem::Dependency
81
+ name: i18n
82
+ requirement: &83156340 !ruby/object:Gem::Requirement
86
83
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: "0"
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
91
88
  type: :runtime
92
- version_requirements: *id007
93
- - !ruby/object:Gem::Dependency
94
- name: haml
95
89
  prerelease: false
96
- requirement: &id008 !ruby/object:Gem::Requirement
90
+ version_requirements: *83156340
91
+ - !ruby/object:Gem::Dependency
92
+ name: haml
93
+ requirement: &83174100 !ruby/object:Gem::Requirement
97
94
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: "0"
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
102
99
  type: :runtime
103
- version_requirements: *id008
104
- - !ruby/object:Gem::Dependency
105
- name: rack
106
100
  prerelease: false
107
- requirement: &id009 !ruby/object:Gem::Requirement
101
+ version_requirements: *83174100
102
+ - !ruby/object:Gem::Dependency
103
+ name: rack
104
+ requirement: &83173890 !ruby/object:Gem::Requirement
108
105
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: "0"
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
113
110
  type: :runtime
114
- version_requirements: *id009
115
- - !ruby/object:Gem::Dependency
116
- name: rack-test
117
111
  prerelease: false
118
- requirement: &id010 !ruby/object:Gem::Requirement
112
+ version_requirements: *83173890
113
+ - !ruby/object:Gem::Dependency
114
+ name: rack-test
115
+ requirement: &83173650 !ruby/object:Gem::Requirement
119
116
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: "0"
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
124
121
  type: :runtime
125
- version_requirements: *id010
126
- - !ruby/object:Gem::Dependency
127
- name: yajl-ruby
128
122
  prerelease: false
129
- requirement: &id011 !ruby/object:Gem::Requirement
123
+ version_requirements: *83173650
124
+ - !ruby/object:Gem::Dependency
125
+ name: yajl-ruby
126
+ requirement: &83173430 !ruby/object:Gem::Requirement
130
127
  none: false
131
- requirements:
132
- - - ">="
133
- - !ruby/object:Gem::Version
134
- version: "0"
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
135
132
  type: :runtime
136
- version_requirements: *id011
137
- - !ruby/object:Gem::Dependency
138
- name: thin
139
133
  prerelease: false
140
- requirement: &id012 !ruby/object:Gem::Requirement
134
+ version_requirements: *83173430
135
+ - !ruby/object:Gem::Dependency
136
+ name: thin
137
+ requirement: &83173150 !ruby/object:Gem::Requirement
141
138
  none: false
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: "0"
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
146
143
  type: :runtime
147
- version_requirements: *id012
148
- - !ruby/object:Gem::Dependency
149
- name: activesupport
150
144
  prerelease: false
151
- requirement: &id013 !ruby/object:Gem::Requirement
145
+ version_requirements: *83173150
146
+ - !ruby/object:Gem::Dependency
147
+ name: activesupport
148
+ requirement: &83172890 !ruby/object:Gem::Requirement
152
149
  none: false
153
- requirements:
154
- - - ">="
155
- - !ruby/object:Gem::Version
156
- version: "0"
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
157
154
  type: :runtime
158
- version_requirements: *id013
159
- - !ruby/object:Gem::Dependency
160
- name: delorean
161
155
  prerelease: false
162
- requirement: &id014 !ruby/object:Gem::Requirement
156
+ version_requirements: *83172890
157
+ - !ruby/object:Gem::Dependency
158
+ name: delorean
159
+ requirement: &83172580 !ruby/object:Gem::Requirement
163
160
  none: false
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- version: "0"
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
168
165
  type: :development
169
- version_requirements: *id014
170
- - !ruby/object:Gem::Dependency
171
- name: rspec
172
166
  prerelease: false
173
- requirement: &id015 !ruby/object:Gem::Requirement
167
+ version_requirements: *83172580
168
+ - !ruby/object:Gem::Dependency
169
+ name: rspec
170
+ requirement: &83172090 !ruby/object:Gem::Requirement
174
171
  none: false
175
- requirements:
172
+ requirements:
176
173
  - - ~>
177
- - !ruby/object:Gem::Version
174
+ - !ruby/object:Gem::Version
178
175
  version: 2.8.0
179
176
  type: :development
180
- version_requirements: *id015
181
- - !ruby/object:Gem::Dependency
182
- name: shoulda
183
177
  prerelease: false
184
- requirement: &id016 !ruby/object:Gem::Requirement
178
+ version_requirements: *83172090
179
+ - !ruby/object:Gem::Dependency
180
+ name: shoulda
181
+ requirement: &83171880 !ruby/object:Gem::Requirement
185
182
  none: false
186
- requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- version: "0"
183
+ requirements:
184
+ - - ! '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
190
187
  type: :development
191
- version_requirements: *id016
188
+ prerelease: false
189
+ version_requirements: *83171880
192
190
  description: FnordMetric is a Ruby Event-Tracking gem on steroids
193
- email:
191
+ email:
194
192
  - paul@paulasmuth.com
195
193
  executables: []
196
-
197
194
  extensions: []
198
-
199
195
  extra_rdoc_files: []
200
-
201
- files:
196
+ files:
202
197
  - Gemfile
203
198
  - README.md
204
199
  - Rakefile
@@ -220,11 +215,13 @@ files:
220
215
  - lib/fnordmetric/count_metric.rb
221
216
  - lib/fnordmetric/dashboard.rb
222
217
  - lib/fnordmetric/event.rb
218
+ - lib/fnordmetric/ext.rb
223
219
  - lib/fnordmetric/funnel_widget.rb
224
220
  - lib/fnordmetric/gauge.rb
225
221
  - lib/fnordmetric/gauge_calculations.rb
226
222
  - lib/fnordmetric/gauge_modifiers.rb
227
223
  - lib/fnordmetric/html_widget.rb
224
+ - lib/fnordmetric/inbound_datagram.rb
228
225
  - lib/fnordmetric/inbound_stream.rb
229
226
  - lib/fnordmetric/logger.rb
230
227
  - lib/fnordmetric/metric.rb
@@ -238,6 +235,7 @@ files:
238
235
  - lib/fnordmetric/sum_metric.rb
239
236
  - lib/fnordmetric/timeline_widget.rb
240
237
  - lib/fnordmetric/toplist_widget.rb
238
+ - lib/fnordmetric/udp_client.rb
241
239
  - lib/fnordmetric/version.rb
242
240
  - lib/fnordmetric/widget.rb
243
241
  - lib/fnordmetric/worker.rb
@@ -251,55 +249,57 @@ files:
251
249
  - spec/context_spec.rb
252
250
  - spec/dashboard_spec.rb
253
251
  - spec/event_spec.rb
252
+ - spec/ext_spec.rb
254
253
  - spec/fnordmetric_spec.rb
255
254
  - spec/gauge_modifiers_spec.rb
256
255
  - spec/gauge_spec.rb
256
+ - spec/inbound_datagram_spec.rb
257
257
  - spec/inbound_stream_spec.rb
258
258
  - spec/namespace_spec.rb
259
259
  - spec/session_spec.rb
260
260
  - spec/spec_helper.rb
261
261
  - spec/widget_spec.rb
262
262
  - spec/worker_spec.rb
263
- has_rdoc: true
264
263
  homepage: http://github.com/paulasmuth/fnordmetric
265
- licenses:
264
+ licenses:
266
265
  - MIT
267
266
  post_install_message:
268
267
  rdoc_options: []
269
-
270
- require_paths:
268
+ require_paths:
271
269
  - lib
272
- required_ruby_version: !ruby/object:Gem::Requirement
270
+ required_ruby_version: !ruby/object:Gem::Requirement
273
271
  none: false
274
- requirements:
275
- - - ">="
276
- - !ruby/object:Gem::Version
277
- version: "0"
278
- required_rubygems_version: !ruby/object:Gem::Requirement
272
+ requirements:
273
+ - - ! '>='
274
+ - !ruby/object:Gem::Version
275
+ version: '0'
276
+ required_rubygems_version: !ruby/object:Gem::Requirement
279
277
  none: false
280
- requirements:
281
- - - ">="
282
- - !ruby/object:Gem::Version
283
- version: "0"
278
+ requirements:
279
+ - - ! '>='
280
+ - !ruby/object:Gem::Version
281
+ version: '0'
284
282
  requirements: []
285
-
286
283
  rubyforge_project:
287
- rubygems_version: 1.6.2
284
+ rubygems_version: 1.8.6
288
285
  signing_key:
289
286
  specification_version: 3
290
287
  summary: FnordMetric is a Ruby Event-Tracking gem on steroids
291
- test_files:
288
+ test_files:
292
289
  - spec/api_spec.rb
293
290
  - spec/app_spec.rb
294
291
  - spec/context_spec.rb
295
292
  - spec/dashboard_spec.rb
296
293
  - spec/event_spec.rb
294
+ - spec/ext_spec.rb
297
295
  - spec/fnordmetric_spec.rb
298
296
  - spec/gauge_modifiers_spec.rb
299
297
  - spec/gauge_spec.rb
298
+ - spec/inbound_datagram_spec.rb
300
299
  - spec/inbound_stream_spec.rb
301
300
  - spec/namespace_spec.rb
302
301
  - spec/session_spec.rb
303
302
  - spec/spec_helper.rb
304
303
  - spec/widget_spec.rb
305
304
  - spec/worker_spec.rb
305
+ has_rdoc: