fnordmetric 0.6.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +14 -8
- data/haml/app.haml +6 -6
- data/lib/fnordmetric.rb +22 -26
- data/lib/fnordmetric/api.rb +11 -10
- data/lib/fnordmetric/dashboard.rb +3 -1
- data/lib/fnordmetric/html_widget.rb +28 -0
- data/lib/fnordmetric/version.rb +1 -1
- data/lib/fnordmetric/widget.rb +3 -1
- data/pub/fnordmetric.js +26 -1
- data/spec/dashboard_spec.rb +6 -0
- data/spec/fnordmetric_spec.rb +56 -0
- metadata +5 -2
data/README.md
CHANGED
@@ -5,7 +5,7 @@ FnordMetric is a highly configurable (and pretty fast) realtime app/event
|
|
5
5
|
tracking thing based on ruby eventmachine and redis. You define your own
|
6
6
|
plotting and counting functions as ruby blocks!
|
7
7
|
|
8
|
-
[  ](http://travis-ci.org/paulasmuth/fnordmetric)
|
8
|
+
[  ](http://travis-ci.org/paulasmuth/fnordmetric)
|
9
9
|
|
10
10
|
[SCREENCAST][2]: the FnordMetric-instance we use to track our social dating app.
|
11
11
|
|
@@ -105,8 +105,8 @@ The fast way: Add your event directly to the redis-based queue.
|
|
105
105
|
uuid = (8**32).to_s(36)
|
106
106
|
event = { :_type => "unicorn_seen" }.to_json
|
107
107
|
|
108
|
-
redis.set("fnordmetric-event-#{
|
109
|
-
redis.expire("fnordmetric-event-#{
|
108
|
+
redis.set("fnordmetric-event-#{uuid}", event)
|
109
|
+
redis.expire("fnordmetric-event-#{uuid}", 60)
|
110
110
|
redis.lpush("fnordmetric-queue", uuid)
|
111
111
|
```
|
112
112
|
|
@@ -163,10 +163,6 @@ Call these methods from the event-handler block
|
|
163
163
|
|
164
164
|
----
|
165
165
|
|
166
|
-
### Options: Gauges ###
|
167
|
-
|
168
|
-
----
|
169
|
-
|
170
166
|
### Options: Widgets ###
|
171
167
|
|
172
168
|
+ `[autoupdate]` auto-refresh the timeline every n secs (0 turns autoupdate off)
|
@@ -185,7 +181,15 @@ BarsWidget
|
|
185
181
|
|
186
182
|
----
|
187
183
|
|
188
|
-
|
184
|
+
|
185
|
+
Resources
|
186
|
+
----------
|
187
|
+
|
188
|
+
+ [PHP API for FnordMetric (github.com/leemachin/fnordmetric-php-api)](https://github.com/leemachin/fnordmetric-php-api)
|
189
|
+
+ [Python API for FnordMetric (github.com/sholiday/pyfnordmetric)](https://github.com/sholiday/pyfnordmetric)
|
190
|
+
+ [FnordMetric and C (Blog/Howto)](http://johnmurray.io/log/2012/01/19/FnordMetrics-and-C%23.md)
|
191
|
+
|
192
|
+
+ [The "fnordmetric" google group](http://groups.google.com/group/fnordmetric)
|
189
193
|
|
190
194
|
|
191
195
|
Examples
|
@@ -343,6 +347,8 @@ Contributors
|
|
343
347
|
+ Kacper Bielecki (http://github.com/kazjote)
|
344
348
|
+ John Murray (http://github.com/JohnMurray)
|
345
349
|
+ Lars Gierth (http://github.com/lgierth)
|
350
|
+
+ Ross Kaffenberger (http://github.com/rossta)
|
351
|
+
+ Kunal Modi (http://github.com/kunalmodi)
|
346
352
|
|
347
353
|
To contribute, please fork this repository, make your changes and run the
|
348
354
|
specs, commit them to your github repository and send me a pull request.
|
data/haml/app.haml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
!!!
|
1
|
+
!!!
|
2
2
|
%html
|
3
3
|
|
4
4
|
%head
|
@@ -18,7 +18,7 @@
|
|
18
18
|
%ul
|
19
19
|
-namespaces.each do |key,namespace|
|
20
20
|
%li{:class => namespace.token == current_namespace.token ? 'active' : nil}
|
21
|
-
%a{:href=>"/#{namespace.token}"}=h namespace.title
|
21
|
+
%a{:href=> "#{path_prefix}/#{namespace.token}"}=h namespace.title
|
22
22
|
|
23
23
|
#wrap
|
24
24
|
#tabs
|
@@ -35,7 +35,7 @@
|
|
35
35
|
|
36
36
|
#viewport
|
37
37
|
.viewport_inner.clearfix
|
38
|
-
|
38
|
+
|
39
39
|
|
40
40
|
:javascript
|
41
41
|
$(document).ready(function(){
|
@@ -56,9 +56,9 @@
|
|
56
56
|
$(this).addClass('active').siblings().removeClass('active');
|
57
57
|
});
|
58
58
|
|
59
|
-
function resizeViewport(){
|
59
|
+
function resizeViewport(){
|
60
60
|
var viewport_width = window.innerWidth-220
|
61
|
-
$('#viewport').width(viewport_width);
|
61
|
+
$('#viewport').width(viewport_width);
|
62
62
|
FnordMetric.resizeView();
|
63
63
|
}
|
64
64
|
|
@@ -68,7 +68,7 @@
|
|
68
68
|
if(!#{current_namespace.active_users_available.to_s}) {
|
69
69
|
$('#tabs li:first').trigger('click');
|
70
70
|
}
|
71
|
-
|
71
|
+
|
72
72
|
if(window.location.hash){
|
73
73
|
$('#tabs li.dashboard[rel="'+window.location.hash.slice(1)+'"]').trigger('click');
|
74
74
|
}
|
data/lib/fnordmetric.rb
CHANGED
@@ -20,37 +20,33 @@ module FnordMetric
|
|
20
20
|
def self.server_configuration=(configuration)
|
21
21
|
@@server_configuration = configuration
|
22
22
|
end
|
23
|
-
|
24
|
-
def self.default_options(opts)
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
opts[:event_data_ttl] ||= 3600*24*30
|
41
|
-
|
42
|
-
# session data is kept for one month
|
43
|
-
opts[:session_data_ttl] ||= 3600*24*30
|
24
|
+
def self.default_options(opts = {})
|
25
|
+
{
|
26
|
+
:redis_url => "redis://localhost:6379",
|
27
|
+
:redis_prefix => "fnordmetric",
|
28
|
+
:inbound_stream => ["0.0.0.0", "1337"],
|
29
|
+
:web_interface => ["0.0.0.0", "4242"],
|
30
|
+
:web_interface_server => "thin",
|
31
|
+
:start_worker => true,
|
32
|
+
:print_stats => 3,
|
33
|
+
:event_queue_ttl => 120,
|
34
|
+
:event_data_ttl => 3600*24*30,
|
35
|
+
:session_data_ttl => 3600*24*30
|
36
|
+
}.merge(opts)
|
37
|
+
end
|
44
38
|
|
45
|
-
|
39
|
+
def self.options(opts = {})
|
40
|
+
default_options(@@server_configuration || {}).merge(opts)
|
46
41
|
end
|
47
42
|
|
48
|
-
def self.start_em(opts)
|
43
|
+
def self.start_em(opts = {})
|
49
44
|
EM.run do
|
50
45
|
|
51
46
|
trap("TERM", &method(:shutdown))
|
52
47
|
trap("INT", &method(:shutdown))
|
53
48
|
|
49
|
+
opts = options(opts)
|
54
50
|
app = embedded(opts)
|
55
51
|
|
56
52
|
if opts[:web_interface]
|
@@ -77,11 +73,10 @@ module FnordMetric
|
|
77
73
|
end
|
78
74
|
|
79
75
|
def self.run
|
80
|
-
|
81
|
-
start_em(opts)
|
76
|
+
start_em
|
82
77
|
rescue Exception => e
|
83
78
|
log "!!! eventmachine died, restarting... #{e.message}"
|
84
|
-
sleep(1); run
|
79
|
+
sleep(1); run
|
85
80
|
end
|
86
81
|
|
87
82
|
def self.shutdown
|
@@ -113,7 +108,7 @@ module FnordMetric
|
|
113
108
|
# `:inbound_stream` starts the TCP interface
|
114
109
|
# `:print_stats` periodicaly prints worker stats
|
115
110
|
def self.embedded(opts={})
|
116
|
-
opts =
|
111
|
+
opts = options(opts)
|
117
112
|
app = nil
|
118
113
|
|
119
114
|
if opts[:rack_app] or opts[:web_interface]
|
@@ -157,6 +152,7 @@ require "fnordmetric/numbers_widget"
|
|
157
152
|
require "fnordmetric/bars_widget"
|
158
153
|
require "fnordmetric/toplist_widget"
|
159
154
|
require "fnordmetric/pie_widget"
|
155
|
+
require "fnordmetric/html_widget"
|
160
156
|
require "fnordmetric/namespace"
|
161
157
|
require "fnordmetric/gauge_modifiers"
|
162
158
|
require "fnordmetric/gauge_calculations"
|
data/lib/fnordmetric/api.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
class FnordMetric::API
|
3
3
|
@@opts = nil
|
4
|
+
|
4
5
|
def initialize opts
|
5
6
|
@@opts = FnordMetric.default_options(opts)
|
6
7
|
connect
|
7
8
|
end
|
8
|
-
|
9
|
+
|
9
10
|
def connect
|
10
11
|
@redis = Redis.connect(:url => @@opts[:redis_url])
|
11
12
|
end
|
12
|
-
|
13
|
+
|
13
14
|
def event(event_data)
|
14
15
|
begin
|
15
16
|
if event_data.is_a?(Hash)
|
16
|
-
event_data = event_data.to_json
|
17
|
+
event_data = event_data.to_json
|
17
18
|
else
|
18
19
|
JSON.parse(event_data) # void ;)
|
19
20
|
end
|
@@ -27,19 +28,19 @@ class FnordMetric::API
|
|
27
28
|
def disconnect
|
28
29
|
@redis.quit
|
29
30
|
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def push_event(event_id, event_data)
|
34
|
-
prefix = @@opts[:redis_prefix]
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def push_event(event_id, event_data)
|
35
|
+
prefix = @@opts[:redis_prefix]
|
35
36
|
@redis.hincrby "#{prefix}-testdata", "events_received", 1
|
36
37
|
@redis.hincrby "#{prefix}-stats", "events_received", 1
|
37
38
|
@redis.set "#{prefix}-event-#{event_id}", event_data
|
38
|
-
@redis.lpush "#{prefix}-queue", event_id
|
39
|
+
@redis.lpush "#{prefix}-queue", event_id
|
39
40
|
@redis.expire "#{prefix}-event-#{event_id}", @@opts[:event_queue_ttl]
|
40
41
|
event_id
|
41
42
|
end
|
42
|
-
|
43
|
+
|
43
44
|
def get_next_uuid
|
44
45
|
SecureRandom.uuid
|
45
46
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class FnordMetric::HtmlWidget < FnordMetric::Widget
|
2
|
+
def data
|
3
|
+
super.merge(
|
4
|
+
:html => @opts[:html]
|
5
|
+
)
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_gauges(gauges)
|
9
|
+
@gauges = []
|
10
|
+
@tick = 0
|
11
|
+
|
12
|
+
if !gauges.blank?
|
13
|
+
error! "initializing a html widget with gauges is void"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def data_gauges
|
18
|
+
{}
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_range(now=Time.now)
|
22
|
+
0..0
|
23
|
+
end
|
24
|
+
|
25
|
+
def has_tick?
|
26
|
+
false
|
27
|
+
end
|
28
|
+
end
|
data/lib/fnordmetric/version.rb
CHANGED
data/lib/fnordmetric/widget.rb
CHANGED
data/pub/fnordmetric.js
CHANGED
@@ -178,6 +178,31 @@ var FnordMetric = (function(){
|
|
178
178
|
|
179
179
|
};
|
180
180
|
|
181
|
+
var htmlWidget = function(){
|
182
|
+
function render(opts){
|
183
|
+
|
184
|
+
opts.elem.append(
|
185
|
+
$('<div class="headbar small"></div>').html(opts.title)
|
186
|
+
).css({
|
187
|
+
'marginBottom': 20,
|
188
|
+
'overflow': 'hidden'
|
189
|
+
});
|
190
|
+
|
191
|
+
var container = $('<div></div>')
|
192
|
+
.addClass('html_container')
|
193
|
+
.html(opts.html);
|
194
|
+
|
195
|
+
opts.elem.append(container);
|
196
|
+
}
|
197
|
+
|
198
|
+
function updateValues(opts){}
|
199
|
+
function updatedisplay(opts, diff_factor){}
|
200
|
+
|
201
|
+
return {
|
202
|
+
render: render
|
203
|
+
};
|
204
|
+
}
|
205
|
+
|
181
206
|
var numbersWidget = function(){
|
182
207
|
|
183
208
|
|
@@ -604,7 +629,6 @@ var FnordMetric = (function(){
|
|
604
629
|
|
605
630
|
};
|
606
631
|
|
607
|
-
|
608
632
|
var pieWidget = function(){
|
609
633
|
|
610
634
|
function render(opts){
|
@@ -1078,6 +1102,7 @@ var FnordMetric = (function(){
|
|
1078
1102
|
if(widget.klass=='NumbersWidget'){ numbersWidget().render(widget); }
|
1079
1103
|
if(widget.klass=='ToplistWidget'){ toplistWidget().render(widget); }
|
1080
1104
|
if(widget.klass=='PieWidget'){ pieWidget().render(widget); }
|
1105
|
+
if(widget.klass=="HtmlWidget") { htmlWidget().render(widget); }
|
1081
1106
|
};
|
1082
1107
|
|
1083
1108
|
function resizeWidget(wkey){
|
data/spec/dashboard_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require ::File.expand_path('../spec_helper.rb', __FILE__)
|
2
3
|
|
3
4
|
describe FnordMetric::Dashboard do
|
@@ -20,6 +21,11 @@ describe FnordMetric::Dashboard do
|
|
20
21
|
dashboard.token.should == 'MyF00barDash_board'
|
21
22
|
end
|
22
23
|
|
24
|
+
it "should build the correct token if the dashboard name contains non-english characters" do
|
25
|
+
dashboard = FnordMetric::Dashboard.new(:title => 'Новая статистика!'){ |dash| }
|
26
|
+
dashboard.token.should_not be_empty
|
27
|
+
end
|
28
|
+
|
23
29
|
it "should add a widget" do
|
24
30
|
pending("fix this")
|
25
31
|
#dashboard = FnordMetric::Dashboard.new(:title => 'My!F00bar-.Dash_board'){ |dash| }
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FnordMetric do
|
4
|
+
after { FnordMetric.server_configuration = nil }
|
5
|
+
|
6
|
+
it "has default_options" do
|
7
|
+
opts = FnordMetric.default_options
|
8
|
+
opts[:redis_url].should eq("redis://localhost:6379")
|
9
|
+
opts[:redis_prefix].should eq("fnordmetric")
|
10
|
+
opts[:inbound_stream].should eq(["0.0.0.0", "1337"])
|
11
|
+
opts[:web_interface].should eq(["0.0.0.0", "4242"])
|
12
|
+
opts[:web_interface_server].should eq("thin")
|
13
|
+
opts[:start_worker].should be_true
|
14
|
+
opts[:print_stats].should == 3
|
15
|
+
opts[:event_queue_ttl].should == 120
|
16
|
+
opts[:event_data_ttl].should == 3600*24*30
|
17
|
+
opts[:session_data_ttl].should == 3600*24*30
|
18
|
+
end
|
19
|
+
|
20
|
+
it "default_options can be overriden" do
|
21
|
+
opts = FnordMetric.default_options({
|
22
|
+
:redis_url => "redis://example.com:6379",
|
23
|
+
:redis_prefix => "foobar",
|
24
|
+
:inbound_stream => ["0.0.0.0", "7331"],
|
25
|
+
:web_interface => ["0.0.0.0", "2424"],
|
26
|
+
:web_interface_server => "hatetepe",
|
27
|
+
:start_worker => false,
|
28
|
+
:print_stats => false,
|
29
|
+
:event_queue_ttl => 10,
|
30
|
+
:event_data_ttl => 20,
|
31
|
+
:session_data_ttl => 30,
|
32
|
+
})
|
33
|
+
opts[:redis_url].should eq("redis://example.com:6379")
|
34
|
+
opts[:redis_prefix].should eq("foobar")
|
35
|
+
opts[:inbound_stream].should eq(["0.0.0.0", "7331"])
|
36
|
+
opts[:web_interface].should eq(["0.0.0.0", "2424"])
|
37
|
+
opts[:web_interface_server].should eq("hatetepe")
|
38
|
+
opts[:start_worker].should be_false
|
39
|
+
opts[:print_stats].should be_false
|
40
|
+
opts[:event_queue_ttl].should == 10
|
41
|
+
opts[:event_data_ttl].should == 20
|
42
|
+
opts[:session_data_ttl].should == 30
|
43
|
+
end
|
44
|
+
|
45
|
+
it "merges default, server configuration, and given opts as options" do
|
46
|
+
FnordMetric.server_configuration = { :web_interface_server => "hatetepe", :print_stats => true }
|
47
|
+
opts = FnordMetric.options(:redis_url => "redis://example.com:6379", :print_stats => false)
|
48
|
+
|
49
|
+
opts[:redis_url].should eq("redis://example.com:6379")
|
50
|
+
opts[:redis_prefix].should eq("fnordmetric")
|
51
|
+
opts[:web_interface_server].should eq("hatetepe")
|
52
|
+
opts[:print_stats].should be_false
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: fnordmetric
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.7.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Paul Asmuth
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-04-21 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- lib/fnordmetric/gauge.rb
|
225
225
|
- lib/fnordmetric/gauge_calculations.rb
|
226
226
|
- lib/fnordmetric/gauge_modifiers.rb
|
227
|
+
- lib/fnordmetric/html_widget.rb
|
227
228
|
- lib/fnordmetric/inbound_stream.rb
|
228
229
|
- lib/fnordmetric/logger.rb
|
229
230
|
- lib/fnordmetric/metric.rb
|
@@ -250,6 +251,7 @@ files:
|
|
250
251
|
- spec/context_spec.rb
|
251
252
|
- spec/dashboard_spec.rb
|
252
253
|
- spec/event_spec.rb
|
254
|
+
- spec/fnordmetric_spec.rb
|
253
255
|
- spec/gauge_modifiers_spec.rb
|
254
256
|
- spec/gauge_spec.rb
|
255
257
|
- spec/inbound_stream_spec.rb
|
@@ -292,6 +294,7 @@ test_files:
|
|
292
294
|
- spec/context_spec.rb
|
293
295
|
- spec/dashboard_spec.rb
|
294
296
|
- spec/event_spec.rb
|
297
|
+
- spec/fnordmetric_spec.rb
|
295
298
|
- spec/gauge_modifiers_spec.rb
|
296
299
|
- spec/gauge_spec.rb
|
297
300
|
- spec/inbound_stream_spec.rb
|