fnordmetric 1.0.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/Rakefile +1 -1
  2. data/fnordmetric.gemspec +1 -0
  3. data/lib/fnordmetric.rb +6 -13
  4. data/lib/fnordmetric/acceptors/acceptor.rb +20 -7
  5. data/lib/fnordmetric/acceptors/amqp_acceptor.rb +56 -0
  6. data/lib/fnordmetric/acceptors/fyrehose_acceptor.rb +43 -0
  7. data/lib/fnordmetric/acceptors/stomp_acceptor.rb +71 -0
  8. data/lib/fnordmetric/acceptors/tcp_acceptor.rb +1 -0
  9. data/lib/fnordmetric/acceptors/udp_acceptor.rb +2 -1
  10. data/lib/fnordmetric/context.rb +21 -9
  11. data/lib/fnordmetric/defaults.rb +16 -3
  12. data/lib/fnordmetric/gauge.rb +8 -3
  13. data/lib/fnordmetric/gauge_calculations.rb +8 -2
  14. data/lib/fnordmetric/gauge_modifiers.rb +5 -4
  15. data/lib/fnordmetric/gauges/server_health_gauge.rb +13 -0
  16. data/lib/fnordmetric/namespace.rb +53 -17
  17. data/lib/fnordmetric/util.rb +25 -0
  18. data/lib/fnordmetric/version.rb +1 -1
  19. data/lib/fnordmetric/web/app.rb +7 -66
  20. data/lib/fnordmetric/web/reactor.rb +32 -2
  21. data/lib/fnordmetric/web/websocket.rb +1 -1
  22. data/lib/fnordmetric/widgets/bars_widget.rb +1 -1
  23. data/lib/fnordmetric/widgets/numbers_widget.rb +28 -4
  24. data/lib/fnordmetric/widgets/timeseries_widget.rb +19 -9
  25. data/lib/fnordmetric/widgets/toplist_widget.rb +8 -4
  26. data/lib/fnordmetric/worker.rb +5 -1
  27. data/lib/fnordmetric/zero_config_gauge.rb +138 -0
  28. data/spec/context_spec.rb +4 -4
  29. data/spec/event_spec.rb +11 -11
  30. data/spec/gauge_modifiers_spec.rb +135 -29
  31. data/spec/gauge_spec.rb +7 -2
  32. data/spec/namespace_spec.rb +8 -19
  33. data/spec/util_spec.rb +46 -0
  34. data/web/.gitignore +4 -0
  35. data/web/build.sh +34 -0
  36. data/web/{fnordmetric.css → css/fnordmetric.core.css} +121 -58
  37. data/web/haml/app.haml +4 -22
  38. data/web/{loader.gif → img/loader.gif} +0 -0
  39. data/web/js/fnordmetric.bars_widget.js +3 -3
  40. data/web/js/fnordmetric.dashboard_view.js +1 -1
  41. data/web/js/fnordmetric.gauge_explorer.js +173 -0
  42. data/web/js/fnordmetric.js +93 -33
  43. data/web/js/fnordmetric.numbers_widget.js +15 -14
  44. data/web/js/fnordmetric.session_view.js +0 -1
  45. data/web/js/fnordmetric.timeline_widget.js +3 -3
  46. data/web/js/fnordmetric.timeseries_widget.js +46 -29
  47. data/web/js/fnordmetric.toplist_widget.js +23 -16
  48. data/web/js/fnordmetric.util.js +12 -8
  49. data/web/vendor/font-awesome/css/font-awesome-ie7.min.css +22 -0
  50. data/web/vendor/font-awesome/css/font-awesome.css +522 -221
  51. data/web/vendor/font-awesome/css/font-awesome.min.css +33 -0
  52. data/web/vendor/font-awesome/font/FontAwesome.otf +0 -0
  53. data/web/vendor/font-awesome/font/fontawesome-webfont.eot +0 -0
  54. data/web/vendor/font-awesome/font/fontawesome-webfont.svg +278 -169
  55. data/web/vendor/font-awesome/font/fontawesome-webfont.ttf +0 -0
  56. data/web/vendor/font-awesome/font/fontawesome-webfont.woff +0 -0
  57. data/web/vendor/jquery-ui.min.js +6 -413
  58. data/web/vendor/jquery.combobox.js +129 -0
  59. metadata +55 -48
  60. data/doc/V1.0-ROADMAP +0 -97
  61. data/doc/full_example.rb +0 -224
  62. data/doc/legacy_example.rb +0 -640
  63. data/doc/minimal_example.rb +0 -26
  64. data/doc/preview1.png +0 -0
  65. data/doc/preview2.png +0 -0
  66. data/doc/preview3.png +0 -0
  67. data/readme.md +0 -365
  68. data/web/vendor/d3.v2.js +0 -9382
  69. data/web/vendor/font-awesome/font/fontawesome-webfont.svgz +0 -0
  70. data/web/vendor/rickshaw.css +0 -286
  71. data/web/vendor/rickshaw.fnordmetric.js +0 -2700
@@ -6,18 +6,20 @@ class FnordMetric::ToplistWidget < FnordMetric::Widget
6
6
  return false unless event["gauge"]
7
7
 
8
8
  resp = if event["cmd"] == "values_for"
9
+ vals = execute_values_for(namespace.gauges[event["gauge"].to_sym], t)
10
+
9
11
  {
10
12
  :cmd => :values_for,
11
13
  :gauge => event["gauge"],
12
- :values => execute_values_for(namespace.gauges[event["gauge"].to_sym], t),
13
- :count => namespace.gauges[event["gauge"].to_sym].field_values_total(t)
14
+ :values => vals,
15
+ :count => vals.inject(0){ |m, (k,c)| m + c }
14
16
  }
15
17
  end
16
18
 
17
19
  return false unless resp
18
20
 
19
21
  resp.merge(
20
- :class => "widget_response",
22
+ :type => "widget_response",
21
23
  :widget_key => event["widget_key"]
22
24
  )
23
25
  end
@@ -38,7 +40,9 @@ class FnordMetric::ToplistWidget < FnordMetric::Widget
38
40
  :ticks => @opts[:ticks],
39
41
  :click_callback => @opts[:click_callback],
40
42
  :async_chart => true,
41
- :tick => tick
43
+ :tick => tick,
44
+ :limit => @opts[:limit],
45
+ :no_min_height => @opts[:no_min_height]
42
46
  ).tap do |dat|
43
47
  dat.merge!(
44
48
  :gauges => @opts[:_gauges]
@@ -55,7 +55,7 @@ class FnordMetric::Worker
55
55
  end
56
56
 
57
57
  def announce_event(event)
58
- namespace(event[:_namespace]).ready!(redis).announce(event)
58
+ namespace(event[:_namespace]).ready!(redis, sync_redis).announce(event)
59
59
  end
60
60
 
61
61
  def expire_event(event_id)
@@ -82,4 +82,8 @@ class FnordMetric::Worker
82
82
  @redis ||= EM::Hiredis.connect(FnordMetric.options[:redis_url]) # FIXPAUL
83
83
  end
84
84
 
85
+ def sync_redis
86
+ @sync_redis ||= FnordMetric.mk_redis
87
+ end
88
+
85
89
  end
@@ -0,0 +1,138 @@
1
+ class FnordMetric::ZeroConfigGauge
2
+
3
+ TYPES = [:_incr, :_decr, :_avg, :_min, :_max, :_set]
4
+
5
+ Handler = proc do
6
+ if data[:gauge]
7
+ gauge_key = data[:gauge].to_sym
8
+ else
9
+ FnordMetric.error("missing key for zero config event: gauge")
10
+ next
11
+ end
12
+
13
+ unless data[:value]
14
+ FnordMetric.error("missing key for zero config event: value")
15
+ next
16
+ end
17
+
18
+ gauge = if namespace.gauges.has_key?(gauge_key)
19
+ namespace.gauges[gauge_key]
20
+ else
21
+ namespace.opt_gauge(gauge_key,
22
+ :flush_interval => data[:flush_interval],
23
+ :average => (type == :_avg),
24
+ :zero_config => true)
25
+ end
26
+
27
+ case type
28
+
29
+ when :_set
30
+ set_value gauge, data[:value].to_i
31
+
32
+ when :_incr
33
+ incr_tick gauge, data[:value].to_i
34
+
35
+ when :_decr
36
+ FnordMetric.error("_decr is not yet implemented")
37
+
38
+ when :_avg
39
+ incr_avg gauge, data[:value].to_i
40
+
41
+ when :_min, :_max
42
+ FnordMetric.error("_min/_max is not yet implemented")
43
+
44
+ end
45
+ end
46
+
47
+ class EmtpyGauge
48
+
49
+ def self.tick
50
+ FnordMetric.options[:default_flush_interval]
51
+ end
52
+
53
+ def self.retention
54
+ tick * 10
55
+ end
56
+
57
+ def self.tick_at(time, _tick=tick)
58
+ (time/_tick.to_f).floor*_tick
59
+ end
60
+
61
+ def group
62
+ "Gauges"
63
+ end
64
+
65
+ def unit
66
+ nil
67
+ end
68
+
69
+ def key_nouns
70
+ ["Key", "Keys"]
71
+ end
72
+
73
+ def key(_append=nil)
74
+ "----empty-gauge----"
75
+ end
76
+
77
+ def tick_key(_time, _append=nil)
78
+ "----empty-gauge----"
79
+ end
80
+
81
+ def tick_keys(_range, _append=nil)
82
+ ["----empty-gauge----"]
83
+ end
84
+
85
+ def retention_key(_time, _append=nil)
86
+ "----empty-gauge----"
87
+ end
88
+
89
+ def two_dimensional?
90
+ true
91
+ end
92
+
93
+ def three_dimensional?
94
+ false
95
+ end
96
+
97
+ def progressive?
98
+ false
99
+ end
100
+
101
+ def unique?
102
+ false
103
+ end
104
+
105
+ def average?
106
+ false
107
+ end
108
+
109
+ def has_series?
110
+ false
111
+ end
112
+
113
+ end
114
+
115
+ def initialize(key, namespace)
116
+ @key = key
117
+ @namespace = namespace
118
+ end
119
+
120
+ def name
121
+ @key
122
+ end
123
+
124
+ def title
125
+ @key
126
+ end
127
+
128
+ def method_missing(*msg)
129
+ gauge = @namespace.gauges[@key]
130
+
131
+ if gauge
132
+ gauge.send(*msg)
133
+ else
134
+ EmtpyGauge.send(*msg)
135
+ end
136
+ end
137
+
138
+ end
data/spec/context_spec.rb CHANGED
@@ -18,12 +18,12 @@ describe FnordMetric::Context do
18
18
  it "should expose the current session_key" do
19
19
  ns = FnordMetric::Namespace.new(
20
20
  :myns_253,
21
- :redis_prefix => "fnordmetrictest"
21
+ :redis_prefix => "fnordmetrictest"
22
22
  )
23
23
  ns.opt_event(:fnordbar, {}) do
24
24
  session_key.should == "145d3f6dee1a770e3a3c550b3993dc81"
25
25
  end
26
- ns.ready!(@redis_wrap).announce(
26
+ ns.ready!(@redis_wrap, @redis).announce(
27
27
  :_eid => "35r2423",
28
28
  :_time => Time.now.to_i,
29
29
  :_type => "fnordbar",
@@ -35,8 +35,8 @@ describe FnordMetric::Context do
35
35
  Thread.current["fnord_123"] = false
36
36
  my_block = proc{ Thread.current["fnord_123"] = "35r25" }
37
37
  context = FnordMetric::Context.new({}, my_block)
38
- context.call({}, nil)
38
+ context.call({}, nil, nil)
39
39
  Thread.current["fnord_123"].should == "35r25"
40
40
  end
41
41
 
42
- end
42
+ end
data/spec/event_spec.rb CHANGED
@@ -6,24 +6,24 @@ describe FnordMetric::Event do
6
6
  include FnordMetric
7
7
 
8
8
  before(:all) do
9
- @now = Time.utc(1992,01,13,5,23,23).to_i
9
+ @now = Time.utc(1992,01,13,5,23,23).to_i
10
10
  @redis = Redis.new
11
11
  @redis_wrap = RedisWrap.new(@redis)
12
12
 
13
- @namespace = "fnordmetric-test-ns123"
13
+ @namespace = "fnordmetric-test-ns123"
14
14
  @timeline = "#{@namespace}-timeline"
15
15
 
16
- @opts = {
16
+ @opts = {
17
17
  :namespace_prefix => "#{@namespace}",
18
18
  :redis_prefix => "fnordmetric-test",
19
19
  :redis => @redis
20
- }
20
+ }
21
21
  end
22
22
 
23
23
  describe "finding events" do
24
24
 
25
- before(:each) do
26
- @redis.keys("fnordmetric-test-*").each { |k| @redis.del(k) }
25
+ before(:each) do
26
+ @redis.keys("fnordmetric-test-*").each { |k| @redis.del(k) }
27
27
  end
28
28
 
29
29
  it "should find all events" do
@@ -101,15 +101,15 @@ describe FnordMetric::Event do
101
101
 
102
102
  it "should find all events by type" do
103
103
  namespace = Namespace.new(:ns123, :redis_prefix => "fnordmetric-test")
104
- namespace.ready!(@redis_wrap).announce(
104
+ namespace.ready!(@redis_wrap, @redis).announce(
105
105
  :_type => "fn0rd",
106
106
  :_time => @now
107
107
  )
108
- namespace.ready!(@redis_wrap).announce(
108
+ namespace.ready!(@redis_wrap, @redis).announce(
109
109
  :_type => "f00bar",
110
110
  :_time => @now
111
111
  )
112
- namespace.ready!(@redis_wrap).announce(
112
+ namespace.ready!(@redis_wrap, @redis).announce(
113
113
  :_type => "fn0rd",
114
114
  :_time => @now
115
115
  )
@@ -132,9 +132,9 @@ describe FnordMetric::Event do
132
132
 
133
133
  before do
134
134
  created_events_data.each do |(event_id, session)|
135
- event_data = { :_time => @now + event_id, :_eid => event_id }
135
+ event_data = { :_time => @now + event_id, :_eid => event_id, :_type => "fnord" }
136
136
  event_data[:_session] = session if session
137
- namespace.ready!(@redis_wrap).announce event_data
137
+ namespace.ready!(@redis_wrap, @redis).announce event_data
138
138
  end
139
139
  end
140
140
 
@@ -2,14 +2,122 @@ require ::File.expand_path('../spec_helper.rb', __FILE__)
2
2
 
3
3
  describe FnordMetric::GaugeModifiers do
4
4
 
5
- before(:all) do
6
- @now = Time.utc(1992,01,13,5,23,23).to_i
5
+ before(:all) do
6
+ @now = Time.utc(1992,01,13,5,23,23).to_i
7
7
  @redis = Redis.new
8
8
  @redis_wrap = RedisWrap.new(@redis)
9
+ @namespace = FnordMetric::Namespace.new(:myns_213,
10
+ :redis_prefix => "fnordmetric")
11
+ @namespace.ready!(@redis_wrap, @redis)
9
12
  end
10
13
 
11
14
  before(:each) do
12
- @redis.keys("fnordmetrics-myns*").each { |k| @redis.del(k) }
15
+ @redis.keys("fnordmetrics-myns*").each { |k| @redis.del(k) }
16
+ @redis.keys("fnordmetric-myns*").each { |k| @redis.del(k) }
17
+ end
18
+
19
+ describe "increment zero-config gauges" do
20
+
21
+ it "should create and increment zero-config gauges" do
22
+ @namespace.announce(
23
+ :_type => "_incr",
24
+ :_eid => 1234,
25
+ :_time => 1360584960,
26
+ :value => 42,
27
+ :gauge => "sales-per-second",
28
+ :flush_interval => 20
29
+ )
30
+
31
+ @namespace.gauges[:"sales-per-second"].should be_a(Gauge)
32
+
33
+ gauge_key = "fnordmetric-myns_213-gauge-sales-per-second-20"
34
+ @redis.hget(gauge_key, "1360584960").should == "42"
35
+
36
+ @namespace.announce(
37
+ :_type => "_incr",
38
+ :_eid => 1234,
39
+ :_time => 1360584960,
40
+ :value => 11,
41
+ :gauge => "sales-per-second",
42
+ :flush_interval => 20
43
+ )
44
+
45
+ @redis.hget(gauge_key, "1360584960").should == "53"
46
+ @namespace.gauges[:"sales-per-second"].value_at(1360584961).should == "53"
47
+ end
48
+
49
+ it "should create and increment zero-config gauges with the default flush interval" do
50
+ @namespace.announce(
51
+ :_type => "_incr",
52
+ :_eid => 1234,
53
+ :_time => 1360584960,
54
+ :value => 42,
55
+ :gauge => "sales-per-second-default"
56
+ )
57
+
58
+ @namespace.gauges[:"sales-per-second-default"].should be_a(Gauge)
59
+
60
+ gauge_key = "fnordmetric-myns_213-gauge-sales-per-second-default-10"
61
+ @redis.hget(gauge_key, "1360584960").should == "42"
62
+ end
63
+
64
+ it "should create and set zero-config gauges" do
65
+ @namespace.announce(
66
+ :_type => "_set",
67
+ :_eid => 1234,
68
+ :_time => 1360584960,
69
+ :value => 123,
70
+ :gauge => "sales-per-second-set",
71
+ :flush_interval => 10
72
+ )
73
+
74
+ @namespace.gauges[:"sales-per-second-set"].should be_a(Gauge)
75
+
76
+ gauge_key = "fnordmetric-myns_213-gauge-sales-per-second-set-10"
77
+ @redis.hget(gauge_key, "1360584960").should == "123"
78
+
79
+ @namespace.announce(
80
+ :_type => "_set",
81
+ :_eid => 1234,
82
+ :_time => 1360584960,
83
+ :value => 555,
84
+ :gauge => "sales-per-second-set",
85
+ :flush_interval => 10
86
+ )
87
+
88
+ @redis.hget(gauge_key, "1360584960").should == "555"
89
+ @namespace.gauges[:"sales-per-second-set"].value_at(1360584961).should == "555"
90
+ end
91
+
92
+ it "should create and increment-average zero-config gauges" do
93
+ @namespace.announce(
94
+ :_type => "_avg",
95
+ :_eid => 1234,
96
+ :_time => 1360584960,
97
+ :value => 5,
98
+ :gauge => "sales-per-second-avg",
99
+ :flush_interval => 10
100
+ )
101
+
102
+ @namespace.gauges[:"sales-per-second-avg"].should be_a(Gauge)
103
+ @namespace.gauges[:"sales-per-second-avg"].average?.should be_true
104
+
105
+ gauge_key = "fnordmetric-myns_213-gauge-sales-per-second-avg-10"
106
+ @redis.hget(gauge_key, "1360584960").should == "5"
107
+
108
+ @namespace.announce(
109
+ :_type => "_avg",
110
+ :_eid => 1234,
111
+ :_time => 1360584960,
112
+ :value => 10,
113
+ :gauge => "sales-per-second-avg",
114
+ :flush_interval => 10
115
+ )
116
+
117
+ @redis.hget(gauge_key, "1360584960").should == "15"
118
+ @namespace.gauges[:"sales-per-second-avg"].value_at(1360584961).should == 7.5
119
+ end
120
+
13
121
  end
14
122
 
15
123
  describe "increment non-progressive gauges" do
@@ -24,7 +132,7 @@ describe FnordMetric::GaugeModifiers do
24
132
  incr(:mygauge_234, 1)
25
133
  }).tap do |context|
26
134
  event = { :_time => @now }
27
- context.call(event, @redis_wrap)
135
+ context.call(event, @redis_wrap, @namespace)
28
136
  end
29
137
  @redis.hget(gauge_key, "695280200").should == "13"
30
138
  end
@@ -39,7 +147,7 @@ describe FnordMetric::GaugeModifiers do
39
147
  incr(:mygauge_224, 5)
40
148
  }).tap do |context|
41
149
  event = { :_time => @now }
42
- context.call(event, @redis_wrap)
150
+ context.call(event, @redis_wrap, @namespace)
43
151
  end
44
152
  @redis.hget(gauge_key, "695280200").should == "23"
45
153
  end
@@ -54,13 +162,12 @@ describe FnordMetric::GaugeModifiers do
54
162
  incr(:mygauge_253, data[:myval].to_i)
55
163
  }).tap do |context|
56
164
  event = { :_time => @now, :myval => "25" }
57
- context.call(event, @redis_wrap)
165
+ context.call(event, @redis_wrap, @namespace)
58
166
  end
59
167
  @redis.hget(gauge_key, "695280200").should == "36"
60
168
  end
61
169
 
62
170
  end
63
-
64
171
 
65
172
  describe "increment progressive gauges" do
66
173
 
@@ -76,7 +183,7 @@ describe FnordMetric::GaugeModifiers do
76
183
  incr(:mygauge_123, 1)
77
184
  }).tap do |context|
78
185
  event = { :_time => @now }
79
- context.call(event, @redis_wrap)
186
+ context.call(event, @redis_wrap, @namespace)
80
187
  end
81
188
  @redis.hget(gauge_key, "695280200").should == "24"
82
189
  @redis.get(gauge_key+"-head").should == "24"
@@ -94,7 +201,7 @@ describe FnordMetric::GaugeModifiers do
94
201
  incr(:mygauge_125, 5)
95
202
  }).tap do |context|
96
203
  event = { :_time => @now }
97
- context.call(event, @redis_wrap)
204
+ context.call(event, @redis_wrap, @namespace)
98
205
  end
99
206
  @redis.hget(gauge_key, "695280200").should == "27"
100
207
  @redis.get(gauge_key+"-head").should == "27"
@@ -112,7 +219,7 @@ describe FnordMetric::GaugeModifiers do
112
219
  incr(:mygauge_128, 3)
113
220
  }).tap do |context|
114
221
  event = { :_time => @now }
115
- context.call(event, @redis_wrap)
222
+ context.call(event, @redis_wrap, @namespace)
116
223
  end
117
224
  @redis.hget(gauge_key, "695280200").should == "20"
118
225
  @redis.get(gauge_key+"-head").should == "20"
@@ -130,7 +237,7 @@ describe FnordMetric::GaugeModifiers do
130
237
  incr(:mygauge_121, 6)
131
238
  }).tap do |context|
132
239
  event = { :_time => @now }
133
- context.call(event, @redis_wrap)
240
+ context.call(event, @redis_wrap, @namespace)
134
241
  end
135
242
  @redis.hget(gauge_key, "695280200").should == "25"
136
243
  @redis.get(gauge_key+"-head").should == "25"
@@ -147,7 +254,7 @@ describe FnordMetric::GaugeModifiers do
147
254
  }).tap do |context|
148
255
  event = { :_time => @now }
149
256
  lambda{
150
- context.call(event, @redis_wrap)
257
+ context.call(event, @redis_wrap, @namespace)
151
258
  }.should raise_error(RuntimeError)
152
259
  end
153
260
  end
@@ -168,7 +275,7 @@ describe FnordMetric::GaugeModifiers do
168
275
  incr(:mygauge_917, 30)
169
276
  }).tap do |context|
170
277
  event = { :_time => @now, :_session_key => "mysesskey" }
171
- context.call(event, @redis_wrap)
278
+ context.call(event, @redis_wrap, @namespace)
172
279
  end
173
280
  @redis.hget(gauge_key, "695280200").should == "84"
174
281
  @redis.get(gauge_key+"-695280200-value-count").should == "6"
@@ -190,7 +297,7 @@ describe FnordMetric::GaugeModifiers do
190
297
  incr(:mygauge_963, 30)
191
298
  }).tap do |context|
192
299
  event = { :_time => @now, :_session_key => "mysesskey" }
193
- context.call(event, @redis_wrap)
300
+ context.call(event, @redis_wrap, @namespace)
194
301
  end
195
302
  @redis.hget(gauge_key, "695280200").should == "84"
196
303
  @redis.get(gauge_key+"-695280200-sessions-count").should == "6"
@@ -210,7 +317,7 @@ describe FnordMetric::GaugeModifiers do
210
317
  incr(:mygauge_966, 30)
211
318
  }).tap do |context|
212
319
  event = { :_time => @now, :_session_key => "mysesskey" }
213
- context.call(event, @redis_wrap)
320
+ context.call(event, @redis_wrap, @namespace)
214
321
  end
215
322
  @redis.hget(gauge_key, "695280200").should == "54"
216
323
  @redis.get(gauge_key+"-695280200-sessions-count").should == "5"
@@ -229,7 +336,7 @@ describe FnordMetric::GaugeModifiers do
229
336
  incr(:mygauge_966, 30)
230
337
  }).tap do |context|
231
338
  event = { :_time => @now }
232
- context.call(event, @redis_wrap)
339
+ context.call(event, @redis_wrap, @namespace)
233
340
  end
234
341
  @redis.hget(gauge_key, "695280200").should == "54"
235
342
  @redis.get(gauge_key+"-695280200-sessions-count").should == "5"
@@ -250,7 +357,7 @@ describe FnordMetric::GaugeModifiers do
250
357
  incr(:mygauge_963, 30)
251
358
  }).tap do |context|
252
359
  event = { :_time => @now, :_session_key => "mysesskey" }
253
- context.call(event, @redis_wrap)
360
+ context.call(event, @redis_wrap, @namespace)
254
361
  end
255
362
  @redis.hget(gauge_key, "695280200").should == "84"
256
363
  @redis.get(gauge_key+"-progressive-sessions-count").should == "6"
@@ -271,7 +378,7 @@ describe FnordMetric::GaugeModifiers do
271
378
  incr(:mygauge_966, 30)
272
379
  }).tap do |context|
273
380
  event = { :_time => @now, :_session_key => "mysesskey" }
274
- context.call(event, @redis_wrap)
381
+ context.call(event, @redis_wrap, @namespace)
275
382
  end
276
383
  @redis.hget(gauge_key, "695280200").should == "54"
277
384
  @redis.get(gauge_key+"-progressive-sessions-count").should == "5"
@@ -293,7 +400,7 @@ describe "increment three-dimensional gagues" do
293
400
  incr_field(:mygauge_434, "whoopwhoop", 1)
294
401
  }).tap do |context|
295
402
  event = { :_time => @now }
296
- context.call(event, @redis_wrap)
403
+ context.call(event, @redis_wrap, @namespace)
297
404
  end
298
405
  @redis.zscore(gauge_key, "whoopwhoop").to_f.should == 13.0
299
406
  @redis.get(gauge_key+"-count").should == "1"
@@ -310,7 +417,7 @@ describe "increment three-dimensional gagues" do
310
417
  incr_field(:mygauge_634, "whoopwhoop", 5)
311
418
  }).tap do |context|
312
419
  event = { :_time => @now }
313
- context.call(event, @redis_wrap)
420
+ context.call(event, @redis_wrap, @namespace)
314
421
  end
315
422
  @redis.zscore(gauge_key, "whoopwhoop").to_f.should == 5.0
316
423
  @redis.get(gauge_key+"-count").should == "7"
@@ -327,7 +434,7 @@ describe "increment three-dimensional gagues" do
327
434
  incr_field(:mygauge_634, data[:myfield], 5)
328
435
  }).tap do |context|
329
436
  event = { :_time => @now, :myfield => "fnordybar" }
330
- context.call(event, @redis_wrap)
437
+ context.call(event, @redis_wrap, @namespace)
331
438
  end
332
439
  @redis.zscore(gauge_key, "fnordybar").to_f.should == 16.0
333
440
  end
@@ -345,7 +452,7 @@ describe "increment three-dimensional gagues" do
345
452
  incr_field(:mygauge_1263, "mykey", 30)
346
453
  }).tap do |context|
347
454
  event = { :_time => @now, :_session_key => "mysesskey" }
348
- context.call(event, @redis_wrap)
455
+ context.call(event, @redis_wrap, @namespace)
349
456
  end
350
457
  @redis.zscore(gauge_key, "mykey").to_f.should == 84.0
351
458
  @redis.get(gauge_key+"-sessions-count").should == "6"
@@ -366,7 +473,7 @@ describe "increment three-dimensional gagues" do
366
473
  incr_field(:mygauge_1266, "otherkey", 30)
367
474
  }).tap do |context|
368
475
  event = { :_time => @now, :_session_key => "mysesskey" }
369
- context.call(event, @redis_wrap)
476
+ context.call(event, @redis_wrap, @namespace)
370
477
  end
371
478
  @redis.zscore(gauge_key, "otherkey").to_f.should == 54.0
372
479
  @redis.get(gauge_key+"-sessions-count").should == "5"
@@ -389,7 +496,7 @@ describe "increment three-dimensional gagues" do
389
496
  set_value(:mygauge_5463, 17)
390
497
  }).tap do |context|
391
498
  event = { :_time => @now, :_session_key => "mysesskey" }
392
- context.call(event, @redis_wrap)
499
+ context.call(event, @redis_wrap, @namespace)
393
500
  end
394
501
  @redis.hget(gauge_key, "695280200").should == "17"
395
502
  end
@@ -407,7 +514,7 @@ describe "increment three-dimensional gagues" do
407
514
  set_field(:mygauge_1463, "asdasdkey", 23)
408
515
  }).tap do |context|
409
516
  event = { :_time => @now, :_session_key => "mysesskey" }
410
- context.call(event, @redis_wrap)
517
+ context.call(event, @redis_wrap, @namespace)
411
518
  end
412
519
  @redis.zscore(gauge_key, "asdasdkey").to_f.should == 23.0
413
520
  end
@@ -422,10 +529,9 @@ private
422
529
  def create_gauge_context(opts, block)
423
530
  gauge = FnordMetric::Gauge.new({
424
531
  :key_prefix => "fnordmetrics-myns"
425
- }.merge(opts))
426
- FnordMetric::Context.new({
427
- :gauges => { opts[:key].intern => gauge }
428
- }, block)
532
+ }.merge(opts))
533
+ @namespace.instance_variable_set(:"@gauges", { opts[:key].intern => gauge })
534
+ FnordMetric::Context.new({}, block)
429
535
  end
430
536
 
431
537