fnordmetric 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.5.5
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "fnordmetric"
8
- s.version = "0.5.4"
8
+ s.version = "0.5.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Paul Asmuth"]
@@ -17,6 +17,7 @@ class FnordMetric::App < Sinatra::Base
17
17
  def initialize(namespaces, opts)
18
18
  @namespaces = {}
19
19
  @redis = Redis.new
20
+ @opts = opts
20
21
  namespaces.each do |key, block|
21
22
  @namespaces[key] = FnordMetric::Namespace.new(key, opts.clone)
22
23
  @namespaces[key].instance_eval(&block)
@@ -114,9 +115,8 @@ class FnordMetric::App < Sinatra::Base
114
115
  end
115
116
 
116
117
  post '/events' do
117
- halt 400, 'please specify the event_type' unless params["type"]
118
- event_type = params.delete("type")
119
- FnordMetric.track(event_type, parse_params(params))
118
+ halt 400, 'please specify the event_type (_type)' unless params["_type"]
119
+ track_event((8**32).to_s(36), parse_params(params))
120
120
  end
121
121
 
122
122
  private
@@ -134,5 +134,12 @@ private
134
134
  object
135
135
  end
136
136
 
137
+ def track_event(event_id, event_data)
138
+ @redis.hincrby "#{@opts[:redis_prefix]}-stats", "events_received", 1
139
+ @redis.set "#{@opts[:redis_prefix]}-event-#{event_id}", event_data.to_json
140
+ @redis.lpush "#{@opts[:redis_prefix]}-queue", event_id
141
+ @redis.expire "#{@opts[:redis_prefix]}-event-#{event_id}", @opts[:event_queue_ttl]
142
+ end
143
+
137
144
  end
138
145
 
@@ -80,18 +80,18 @@ or in your Gemfile:
80
80
 
81
81
  The slow way: HTTP-Post the json event to the fnordmetric webinterface
82
82
 
83
- POST http://localhost:2323/events _type=_set_name&name=Horst(..)
83
+ POST http://localhost:2323/events _type=unicorn_seen
84
84
 
85
- curl -X POST -d "_type=_set_name&name=Horst(..)" http://localhost:2323/events
85
+ curl -X POST -d "_type=unicorn_seen" http://localhost:4242/events
86
86
 
87
87
  The easy way: Stream one ore more newline-seperated json encoded events through a tcp connection.
88
88
 
89
- echo "\{\"_type\": \"foobar\"\}\n" | nc localhost 2323
89
+ echo "\{\"_type\": \"unicorn_seen\"\}\n" | nc localhost 2323
90
90
 
91
91
  The fast way: Add your event directly to the redis-based queue:
92
92
 
93
- uuid = "sobv67a9v73sba74"
94
- event = { :_type => "foobar" }.to_json
93
+ uuid = (8**32).to_s(36)
94
+ event = { :_type => "unicorn_seen" }.to_json
95
95
 
96
96
  redis.lpush("fnordmetric-queue", uuid)
97
97
  redis.set("fnordmetric-event-#{my_uuid}", event)
@@ -371,44 +371,16 @@ describe "app" do
371
371
 
372
372
  describe "events api: creating events" do
373
373
 
374
- it "should track an event without auth" do
375
- pending("fix this")
376
- #post "/events", :type => "myevent", :fnord => "foobar"
377
- #last_response.status.should == 200
378
- #FnordMetric::Event.last.type.should == "myevent"
379
- #FnordMetric::Event.last.fnord.should == "foobar"
374
+ it "should track an event without auth" do
375
+ post "/events", :_type => "myevent", :fnord => "foobar"
376
+ last_response.status.should == 200
380
377
  end
381
378
 
382
379
  it "should return 400 if no type is provided" do
383
380
  pending("fix this")
384
- #post "/events", :fnord => "foobar"
385
- #last_response.status.should == 400
386
- #last_response.body.should == "please specify the event_type"
387
- end
388
-
389
- it "should track an event in the past" do
390
- pending("fix this")
391
- #my_time = (Time.now-3.years).to_i
392
- #post "/events", :type => "myevent", :time => my_time
393
- #last_response.status.should == 200
394
- #FnordMetric::Event.last.type.should == "myevent"
395
- #FnordMetric::Event.last.time.should == my_time
396
- end
397
-
398
- it "should track an event with integer data" do
399
- pending("fix this")
400
- #post "/events", :type => "myevent", :blubb => "123"
401
- #last_response.status.should == 200
402
- #FnordMetric::Event.last.type.should == "myevent"
403
- #FnordMetric::Event.last.blubb.should == 123
404
- end
405
-
406
- it "should track an event with float data" do
407
- pending("fix this")
408
- #post "/events", :type => "myevent", :blubb => "42.23"
409
- #last_response.status.should == 200
410
- #FnordMetric::Event.last.type.should == "myevent"
411
- #FnordMetric::Event.last.blubb.should == 42.23
381
+ post "/events", :fnord => "foobar"
382
+ last_response.status.should == 400
383
+ last_response.body.should == "please specify the event_type"
412
384
  end
413
385
 
414
386
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fnordmetric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
16
- requirement: &84790870 !ruby/object:Gem::Requirement
16
+ requirement: &81646210 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.4.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *84790870
24
+ version_requirements: *81646210
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sinatra
27
- requirement: &84790360 !ruby/object:Gem::Requirement
27
+ requirement: &81645630 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.2.6
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *84790360
35
+ version_requirements: *81645630
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: redis
38
- requirement: &84789850 !ruby/object:Gem::Requirement
38
+ requirement: &81645130 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.2.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *84789850
46
+ version_requirements: *81645130
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: eventmachine
49
- requirement: &84789450 !ruby/object:Gem::Requirement
49
+ requirement: &81644700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *84789450
57
+ version_requirements: *81644700
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: em-hiredis
60
- requirement: &84788980 !ruby/object:Gem::Requirement
60
+ requirement: &81644350 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *84788980
68
+ version_requirements: *81644350
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: json
71
- requirement: &84788680 !ruby/object:Gem::Requirement
71
+ requirement: &81643990 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *84788680
79
+ version_requirements: *81643990
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: i18n
82
- requirement: &84788410 !ruby/object:Gem::Requirement
82
+ requirement: &82478780 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *84788410
90
+ version_requirements: *82478780
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: haml
93
- requirement: &84733550 !ruby/object:Gem::Requirement
93
+ requirement: &82478540 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *84733550
101
+ version_requirements: *82478540
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rack
104
- requirement: &84733040 !ruby/object:Gem::Requirement
104
+ requirement: &82478300 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *84733040
112
+ version_requirements: *82478300
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rack-test
115
- requirement: &84732470 !ruby/object:Gem::Requirement
115
+ requirement: &82478060 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *84732470
123
+ version_requirements: *82478060
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: yajl-ruby
126
- requirement: &84731710 !ruby/object:Gem::Requirement
126
+ requirement: &82477820 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *84731710
134
+ version_requirements: *82477820
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: thin
137
- requirement: &84730670 !ruby/object:Gem::Requirement
137
+ requirement: &82477580 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :runtime
144
144
  prerelease: false
145
- version_requirements: *84730670
145
+ version_requirements: *82477580
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: activesupport
148
- requirement: &84730280 !ruby/object:Gem::Requirement
148
+ requirement: &82477340 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :runtime
155
155
  prerelease: false
156
- version_requirements: *84730280
156
+ version_requirements: *82477340
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: delorean
159
- requirement: &84729890 !ruby/object:Gem::Requirement
159
+ requirement: &82477100 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,10 +164,10 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *84729890
167
+ version_requirements: *82477100
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: rspec
170
- requirement: &84729450 !ruby/object:Gem::Requirement
170
+ requirement: &82476860 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - ~>
@@ -175,10 +175,10 @@ dependencies:
175
175
  version: 2.6.0
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *84729450
178
+ version_requirements: *82476860
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: shoulda
181
- requirement: &84728530 !ruby/object:Gem::Requirement
181
+ requirement: &82476620 !ruby/object:Gem::Requirement
182
182
  none: false
183
183
  requirements:
184
184
  - - ! '>='
@@ -186,10 +186,10 @@ dependencies:
186
186
  version: '0'
187
187
  type: :development
188
188
  prerelease: false
189
- version_requirements: *84728530
189
+ version_requirements: *82476620
190
190
  - !ruby/object:Gem::Dependency
191
191
  name: bundler
192
- requirement: &84727640 !ruby/object:Gem::Requirement
192
+ requirement: &82476380 !ruby/object:Gem::Requirement
193
193
  none: false
194
194
  requirements:
195
195
  - - ~>
@@ -197,10 +197,10 @@ dependencies:
197
197
  version: 1.0.0
198
198
  type: :development
199
199
  prerelease: false
200
- version_requirements: *84727640
200
+ version_requirements: *82476380
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: jeweler
203
- requirement: &84602760 !ruby/object:Gem::Requirement
203
+ requirement: &82476140 !ruby/object:Gem::Requirement
204
204
  none: false
205
205
  requirements:
206
206
  - - ~>
@@ -208,7 +208,7 @@ dependencies:
208
208
  version: 1.5.2
209
209
  type: :development
210
210
  prerelease: false
211
- version_requirements: *84602760
211
+ version_requirements: *82476140
212
212
  description: FnordMetric is a Ruby Event-Tracking gem on steroids
213
213
  email: paul@paulasmuth.com
214
214
  executables: []