riemann-dash 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +52 -0
- data/README.markdown +29 -5
- data/Rakefile.rb +11 -0
- data/bin/riemann-dash +2 -2
- data/example/config.rb +17 -0
- data/lib/riemann/dash/app.rb +32 -0
- data/lib/riemann/dash/config.rb +154 -0
- data/lib/riemann/dash/controller/css.rb +1 -1
- data/lib/riemann/dash/controller/index.rb +6 -36
- data/lib/riemann/dash/public/dash.js +44 -18
- data/lib/riemann/dash/public/format.js +3 -3
- data/lib/riemann/dash/public/persistence.js +2 -2
- data/lib/riemann/dash/public/subs.js +63 -48
- data/lib/riemann/dash/public/util.js +37 -44
- data/lib/riemann/dash/public/vendor/backbone.js +1571 -0
- data/lib/riemann/dash/public/vendor/jquery/jquery-1.9.1.min.js +5 -0
- data/lib/riemann/dash/public/{jquery-ui-1.9.0.custom.min.js → vendor/jquery/jquery-ui-1.9.0.custom.min.js} +0 -0
- data/lib/riemann/dash/public/{jquery.quickfit.js → vendor/jquery/jquery.quickfit.js} +0 -0
- data/lib/riemann/dash/public/vendor/jquery/jquery.simplemodal.1.4.4.min.js +26 -0
- data/lib/riemann/dash/public/vendor/lodash.min.js +40 -0
- data/lib/riemann/dash/public/vendor/smoothie.js +376 -0
- data/lib/riemann/dash/public/{toastr.css → vendor/toastr/toastr.css} +1 -1
- data/lib/riemann/dash/public/{toastr.js → vendor/toastr/toastr.js} +0 -0
- data/lib/riemann/dash/public/views/gauge.js +8 -5
- data/lib/riemann/dash/public/views/grid.js +138 -67
- data/lib/riemann/dash/public/views/timeseries.js +230 -0
- data/lib/riemann/dash/public/views/title.js +6 -3
- data/lib/riemann/dash/version.rb +2 -2
- data/lib/riemann/dash/views/css.scss +52 -2
- data/lib/riemann/dash/views/index.erubis +38 -192
- data/lib/riemann/dash.rb +3 -97
- data/riemann-dash.gemspec +28 -0
- data/sh/c +1 -0
- data/sh/env.rb +2 -0
- data/sh/test +1 -0
- data/test/config_test.rb +114 -0
- data/test/fixtures/config/basic_config.rb +2 -0
- data/test/fixtures/config/ws_config.rb +1 -0
- data/test/fixtures/ws_config/dummy_config.json +1 -0
- data/test/fixtures/ws_config/pretty_printed_config.json +6 -0
- data/test/test_helper.rb +10 -0
- metadata +43 -18
- data/lib/riemann/dash/public/jquery-1.7.2.min.js +0 -4
- data/lib/riemann/dash/public/jquery.json-2.2.min.js +0 -31
- data/lib/riemann/dash/public/jquery.simplemodal.1.4.3.min.js +0 -26
- data/lib/riemann/dash/public/mustache.js +0 -597
- data/lib/riemann/dash/public/underscore-min.js +0 -5
@@ -1,4 +1,5 @@
|
|
1
1
|
var subs = (function() {
|
2
|
+
|
2
3
|
// What server shall we connect to by default?
|
3
4
|
var server;
|
4
5
|
|
@@ -25,18 +26,13 @@ var subs = (function() {
|
|
25
26
|
|
26
27
|
// Close a subscription's websocket channel.
|
27
28
|
var close = function(sub) {
|
28
|
-
|
29
|
-
return sub;
|
30
|
-
}
|
31
|
-
sub.ws.close();
|
32
|
-
sub.ws == null;
|
33
|
-
return sub;
|
29
|
+
return sub.close();
|
34
30
|
}
|
35
31
|
|
36
32
|
// Closes a subscription and deletes it from the subscription manager.
|
37
33
|
var unsubscribe = function(sub) {
|
38
34
|
delete subs[sub.id];
|
39
|
-
close(
|
35
|
+
return sub.close();
|
40
36
|
}
|
41
37
|
|
42
38
|
// Unsubscribe from all subscriptions.
|
@@ -46,61 +42,80 @@ var subs = (function() {
|
|
46
42
|
|
47
43
|
// Open a subscription's websocket channel.
|
48
44
|
var open = function(sub) {
|
49
|
-
|
50
|
-
|
51
|
-
}
|
45
|
+
return sub.open();
|
46
|
+
}
|
52
47
|
|
53
|
-
|
54
|
-
var queryString = "query=" + encodeURI(sub.query);
|
55
|
-
var uri = "ws://" + server + "/index?subscribe=true&" + queryString;
|
56
|
-
sub.ws = new WebSocket(uri);
|
57
|
-
var $ws = $(sub.ws);
|
58
|
-
|
59
|
-
$ws.bind('open', function() {
|
60
|
-
console.log("Socket opened", sub.query);
|
61
|
-
});
|
48
|
+
var Subscription = Backbone.Model.extend({
|
62
49
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
50
|
+
initialize: function(id, query, f) {
|
51
|
+
this.id = id;
|
52
|
+
this.query = query;
|
53
|
+
this.f = f;
|
54
|
+
},
|
67
55
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
});
|
56
|
+
isOpen: function() {
|
57
|
+
return this.ws && (this.ws.readyState != WebSocket.CLOSED)
|
58
|
+
},
|
59
|
+
isClosed: function() { return !this.isOpen() },
|
73
60
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
}
|
79
|
-
load1(t1, Date.now());
|
80
|
-
load5(t1, Date.now());
|
81
|
-
});
|
61
|
+
url: function() {
|
62
|
+
var queryString = "query=" + encodeURI(this.query);
|
63
|
+
return "ws://" + server + "/index?subscribe=true&" + queryString;
|
64
|
+
},
|
82
65
|
|
83
|
-
|
84
|
-
|
66
|
+
open: function() {
|
67
|
+
if (this.isOpen()) return this;
|
68
|
+
var ws = this.ws = new WebSocket(this.url());
|
69
|
+
|
70
|
+
ws.onopen = _.bind(function() {
|
71
|
+
console.log("Socket opened", this.query);
|
72
|
+
}, this);
|
73
|
+
|
74
|
+
ws.onclose = _.bind(function(e) {
|
75
|
+
console.log("Socket closed", this.query);
|
76
|
+
this.ws = null;
|
77
|
+
}, this);
|
78
|
+
|
79
|
+
ws.onerror = _.bind(function(e) {
|
80
|
+
console.log("Socket error", this.query);
|
81
|
+
errorQueue.push(e);
|
82
|
+
this.close();
|
83
|
+
}, this);
|
84
|
+
|
85
|
+
ws.onmessage = _.bind(function(e) {
|
86
|
+
t1 = Date.now();
|
87
|
+
if (active) {
|
88
|
+
this.f(JSON.parse(e.data));
|
89
|
+
}
|
90
|
+
load1(t1, Date.now());
|
91
|
+
load5(t1, Date.now());
|
92
|
+
}, this);
|
93
|
+
|
94
|
+
return this;
|
95
|
+
|
96
|
+
},
|
97
|
+
|
98
|
+
close: function() {
|
99
|
+
if (this.ws) {
|
100
|
+
this.ws.close();
|
101
|
+
this.ws = void 0;
|
102
|
+
}
|
103
|
+
return this;
|
104
|
+
}
|
105
|
+
});
|
85
106
|
|
86
107
|
// Add a subscription. Returns a subscription object. Subscriptions are
|
87
108
|
// opened immediately.
|
88
109
|
var subscribe = function(query, f) {
|
89
|
-
var sub =
|
90
|
-
id: newId(),
|
91
|
-
query: query,
|
92
|
-
f: f,
|
93
|
-
ws: null
|
94
|
-
}
|
110
|
+
var sub = new Subscription(newId(), query, f).open();
|
95
111
|
subs[sub.id] = sub;
|
96
|
-
open(sub);
|
97
112
|
return sub;
|
98
113
|
}
|
99
114
|
|
100
115
|
// Reconnect all inactive subs.
|
101
116
|
var converge = function() {
|
102
117
|
var closed = _.filter(subs, function(sub) {
|
103
|
-
return
|
118
|
+
return sub.isClosed();
|
104
119
|
});
|
105
120
|
if (_.isEmpty(closed)) {
|
106
121
|
// Done here.
|
@@ -108,7 +123,7 @@ var subs = (function() {
|
|
108
123
|
}
|
109
124
|
|
110
125
|
// Display reconnection notice
|
111
|
-
toastr.warning(_.size(closed) + " lost connections");
|
126
|
+
toastr.warning(_.size(closed) + " lost connections—check the server field above.");
|
112
127
|
|
113
128
|
// Reopen
|
114
129
|
_.each(closed, function(sub) {
|
@@ -120,7 +135,7 @@ var subs = (function() {
|
|
120
135
|
if (errorQueue.length == 0) {
|
121
136
|
return;
|
122
137
|
}
|
123
|
-
|
138
|
+
toastr.warning(errorQueue.length + " socket errors");
|
124
139
|
errorQueue.length = 0;
|
125
140
|
converge();
|
126
141
|
}
|
@@ -1,53 +1,46 @@
|
|
1
1
|
var util = (function() {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
}
|
11
|
-
|
12
|
-
// Merge two maps nondestructively.
|
13
|
-
var merge = function(m1, m2) {
|
14
|
-
return _.extend(_.clone(m1), m2);
|
15
|
-
}
|
2
|
+
return {
|
3
|
+
merge: function(m1, m2) {
|
4
|
+
// Merge two maps nondestructively.
|
5
|
+
return _.extend({}, m1, m2)
|
6
|
+
},
|
7
|
+
slur: function(period, f) {
|
8
|
+
// Wraps a function in another, which calls f at most once every period
|
9
|
+
// milliseconds. Tries to minimize latency.
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
lastRun = new Date();
|
26
|
-
queued = false;
|
27
|
-
};
|
11
|
+
var lastRun = new Date();
|
12
|
+
lastRun.setYear(0);
|
13
|
+
var queued = false;
|
14
|
+
var execute = function(context, args) {
|
15
|
+
f.apply(context, args);
|
16
|
+
lastRun = new Date();
|
17
|
+
queued = false;
|
18
|
+
};
|
28
19
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
return function() {
|
21
|
+
// If queued, do nothing
|
22
|
+
if (queued) {
|
23
|
+
return;
|
24
|
+
}
|
34
25
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
26
|
+
var dt = (new Date()) - lastRun;
|
27
|
+
if (period <= dt) {
|
28
|
+
// We're free to go
|
29
|
+
execute(this, arguments);
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
// Too soon, enqueue a new job.
|
33
|
+
window.setTimeout(execute, period - dt, this, arguments);
|
34
|
+
}
|
42
35
|
}
|
36
|
+
},
|
37
|
+
uniqueId: function(length) {
|
38
|
+
// Unique-ish IDs as a length sized string of hex
|
39
|
+
var id = '', hex = '0123456789abcdef';
|
40
|
+
_(length || 40).times(function() { id += hex[_.random(15)]; });
|
41
|
+
return id;
|
43
42
|
}
|
44
|
-
}
|
45
|
-
|
46
|
-
return {
|
47
|
-
merge: merge,
|
48
|
-
slur: slur,
|
49
|
-
uniqueId: uniqueId
|
50
|
-
}
|
43
|
+
};
|
51
44
|
})();
|
52
45
|
|
53
46
|
$(function() {
|