fnordmetric 1.2.4 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ module FnordMetric::Enterprise
8
8
  next
9
9
  end
10
10
 
11
- if m = cmd.match(/^SAMPLE (.*)(delta|mean)-([0-9]+) ([0-9]+)$/)
11
+ if m = cmd.match(/^SAMPLE (.*)(delta|mean|sum)-([0-9]+) ([0-9]+)$/)
12
12
  gauge_type = m[2].to_sym
13
13
  gauge_tick = m[3].to_i
14
14
  gauge_key = :"#{m[1]}#{gauge_type}-#{gauge_tick}"
@@ -29,7 +29,7 @@ module FnordMetric::Enterprise
29
29
 
30
30
  case gauge_type
31
31
 
32
- when :delta
32
+ when :delta, :sum
33
33
  incr gauge, op_value
34
34
 
35
35
  when :mean
@@ -21,17 +21,18 @@ module FnordMetric::GaugeCalculations
21
21
  ticks << tick_at(range.last) if ticks.size == 0
22
22
  values_at(ticks)
23
23
  end
24
-
24
+
25
25
  def value_at(time, opts={}, &block)
26
26
  _t = tick_at(time)
27
27
 
28
28
  _v = if respond_to?(:_value_at)
29
29
  _value_at(key, _t)
30
30
  else
31
+ _c = sync_redis.hget(key(:"mean-counts"), _t)
31
32
  sync_redis.hget(key, _t)
32
33
  end
33
34
 
34
- calculate_value(_v, _t, opts, block)
35
+ calculate_value(_v, _t, opts, block, _c)
35
36
  end
36
37
 
37
38
  def values_at(times, opts={}, &block)
@@ -40,20 +41,22 @@ module FnordMetric::GaugeCalculations
40
41
  if respond_to?(:_values_at)
41
42
  _values_at(times, opts={}, &block)
42
43
  else
44
+ ret_counts = sync_redis.hmget(key(:"mean-counts"), *times)
43
45
  sync_redis.hmget(key, *times)
44
46
  end.each_with_index do |_v, _n|
45
47
  _t = times[_n]
46
- ret[_t] = calculate_value(_v, _t, opts, block)
48
+ _c = ret_counts ? ret_counts[_n] : nil
49
+ ret[_t] = calculate_value(_v, _t, opts, block, _c)
47
50
  end
48
51
  end
49
52
  end
50
53
 
51
- def calculate_value(_v, _t, opts, block)
52
- block = @@avg_per_count_proc if average?
53
- #block = @@count_per_session_proc if unique?
54
+ def calculate_value(_v, _t, opts, block, _c = nil)
54
55
  block = @@avg_per_session_proc if unique? && average?
55
56
 
56
- calc = if block
57
+ calc = if average? && _c
58
+ (_v.to_f / (_c||1).to_i)
59
+ elsif block
57
60
  instance_exec(_v, _t, &block)
58
61
  else
59
62
  _v
@@ -40,7 +40,7 @@ module FnordMetric::GaugeModifiers
40
40
  end
41
41
 
42
42
  def incr_avg(gauge, value)
43
- @redis.incr(gauge.tick_key(time, :"value-count")).callback do
43
+ @redis.hincrby(gauge.key(:"mean-counts"), gauge.tick_at(time), 1).callback do
44
44
  incr_tick(gauge, value)
45
45
  end
46
46
  end
@@ -1,3 +1,3 @@
1
1
  module FnordMetric
2
- VERSION = "1.2.4"
2
+ VERSION = "1.2.6"
3
3
  end
@@ -2,7 +2,13 @@ class FnordMetric::Reactor
2
2
 
3
3
  def initialize
4
4
  @redis = FnordMetric.mk_redis
5
- @namespaces = FnordMetric.namespaces
5
+ @namespaces = FnordMetric.namespaces.dup
6
+ end
7
+
8
+ def ready!
9
+ @namespaces.each do |key, ns|
10
+ ns.ready!(@redis)
11
+ end
6
12
  end
7
13
 
8
14
  def execute(*args)
@@ -13,7 +13,7 @@ class FnordMetric::WebSocket < Rack::WebSocket::Application
13
13
  end
14
14
 
15
15
  def on_open(env)
16
- # socket openened :)
16
+ @reactor.ready!
17
17
  end
18
18
 
19
19
  def on_message(env, message)
@@ -311,19 +311,19 @@ describe FnordMetric::GaugeModifiers do
311
311
  it "should increment_unique a non-progressive gauge" do
312
312
  gauge_key = "fnordmetrics-myns-gauge-mygauge_917-10"
313
313
  @redis.hset(gauge_key, "695280200", "54")
314
- @redis.set(gauge_key+"-695280200-value-count", 5)
314
+ @redis.hset(gauge_key + "-mean-counts", "695280200", "5")
315
315
  create_gauge_context({
316
- :key => "mygauge_917",
316
+ :key => "mygauge_917",
317
317
  :average => true,
318
318
  :tick => 10
319
319
  }, proc{
320
- incr(:mygauge_917, 30)
321
- }).tap do |context|
320
+ incr(:mygauge_917, 30)
321
+ }).tap do |context|
322
322
  event = { :_time => @now, :_session_key => "mysesskey" }
323
323
  context.call(event, @redis_wrap, @namespace)
324
324
  end
325
325
  @redis.hget(gauge_key, "695280200").should == "84"
326
- @redis.get(gauge_key+"-695280200-value-count").should == "6"
326
+ @redis.hget(gauge_key + "-mean-counts", "695280200").should == "6"
327
327
  end
328
328
 
329
329
  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: 1.2.4
4
+ version: 1.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
12
+ date: 2013-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &19052860 !ruby/object:Gem::Requirement
16
+ requirement: &21703020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.2.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19052860
24
+ version_requirements: *21703020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &19051780 !ruby/object:Gem::Requirement
27
+ requirement: &21702480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.2.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *19051780
35
+ version_requirements: *21702480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: eventmachine
38
- requirement: &19145540 !ruby/object:Gem::Requirement
38
+ requirement: &21702100 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *19145540
46
+ version_requirements: *21702100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: websocket-rack
49
- requirement: &19144880 !ruby/object:Gem::Requirement
49
+ requirement: &21701540 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.4.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *19144880
57
+ version_requirements: *21701540
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: em-hiredis
60
- requirement: &19144380 !ruby/object:Gem::Requirement
60
+ requirement: &21718000 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.1.1
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *19144380
68
+ version_requirements: *21718000
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: json
71
- requirement: &19143980 !ruby/object:Gem::Requirement
71
+ requirement: &21717440 !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: *19143980
79
+ version_requirements: *21717440
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: i18n
82
- requirement: &19143460 !ruby/object:Gem::Requirement
82
+ requirement: &21716580 !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: *19143460
90
+ version_requirements: *21716580
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: haml
93
- requirement: &19143020 !ruby/object:Gem::Requirement
93
+ requirement: &21716120 !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: *19143020
101
+ version_requirements: *21716120
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rack
104
- requirement: &19142600 !ruby/object:Gem::Requirement
104
+ requirement: &21715600 !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: *19142600
112
+ version_requirements: *21715600
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rack-test
115
- requirement: &19142180 !ruby/object:Gem::Requirement
115
+ requirement: &21714860 !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: *19142180
123
+ version_requirements: *21714860
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: yajl-ruby
126
- requirement: &19141720 !ruby/object:Gem::Requirement
126
+ requirement: &21714300 !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: *19141720
134
+ version_requirements: *21714300
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: thin
137
- requirement: &19141140 !ruby/object:Gem::Requirement
137
+ requirement: &21713440 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: 1.3.0
143
143
  type: :runtime
144
144
  prerelease: false
145
- version_requirements: *19141140
145
+ version_requirements: *21713440
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: activesupport
148
- requirement: &19140660 !ruby/object:Gem::Requirement
148
+ requirement: &21712940 !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: *19140660
156
+ version_requirements: *21712940
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: delorean
159
- requirement: &19140000 !ruby/object:Gem::Requirement
159
+ requirement: &21712360 !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: *19140000
167
+ version_requirements: *21712360
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: rspec
170
- requirement: &19138360 !ruby/object:Gem::Requirement
170
+ requirement: &21711640 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - ~>
@@ -175,10 +175,10 @@ dependencies:
175
175
  version: 2.8.0
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *19138360
178
+ version_requirements: *21711640
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: shoulda
181
- requirement: &19137900 !ruby/object:Gem::Requirement
181
+ requirement: &21710960 !ruby/object:Gem::Requirement
182
182
  none: false
183
183
  requirements:
184
184
  - - ! '>='
@@ -186,7 +186,7 @@ dependencies:
186
186
  version: '0'
187
187
  type: :development
188
188
  prerelease: false
189
- version_requirements: *19137900
189
+ version_requirements: *21710960
190
190
  description: FnordMetric is a Ruby Event-Tracking gem on steroids
191
191
  email:
192
192
  - paul@paulasmuth.com