Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fnordmetric ui: prepare fnordmetric enterprise integration

  • Loading branch information...
commit 1c318500b37c3545e7fc0367475373e429e310c5 1 parent 92ca338
@paulasmuth authored
View
62 fnordmetric-ui/js/fnordmetric.js
@@ -1,6 +1,7 @@
var FnordMetric = (function(pre){
var wsAddress, socket, currentNamespace,
+ continuations = {},
widgets = {},
enterprise = false;
@@ -69,7 +70,10 @@ var FnordMetric = (function(pre){
if (evt.error)
return console.log("[FnordMetric] error: " + evt.error);
- if (evt.widget_key && widgets[evt.widget_key])
+ if (evt.widget_key && continuations[evt.widget_key])
+ continuations[evt.widget_key].apply(evt);
+
+ else if (evt.widget_key && widgets[evt.widget_key])
widgets[evt.widget_key].send(evt);
}
@@ -93,11 +97,65 @@ var FnordMetric = (function(pre){
}
}
+ function values_in(gauges, since, until, callback) {
+ if (enterprise) {
+
+ }
+
+ else {
+ var txid = FnordMetric.util.generateUUID();
+
+ continuations[txid] = function(){
+ var result = {};
+
+ for (ind in this.gauges)
+ result[this.gauges[ind].key] = this.gauges[ind].vals;
+
+ callback.apply(result);
+ }
+
+ FnordMetric.publish({
+ "type": "widget_request",
+ "klass": "generic",
+ "gauges": gauges,
+ "cmd": "values_at",
+ "since": since,
+ "until": until,
+ "widget_key": txid
+ });
+ }
+ }
+
+ function value_at(gauge, at, callback) {
+ if (enterprise) {
+
+ }
+
+ else {
+ var txid = FnordMetric.util.generateUUID();
+
+ continuations[txid] = function(){
+ callback.apply({ "value": this.value });
+ }
+
+ FnordMetric.publish({
+ "type": "widget_request",
+ "klass": "generic",
+ "cmd": "values_for",
+ "gauge": gauge,
+ "at": at,
+ "widget_key": txid
+ })
+ }
+ }
+
return {
setup: setup,
publish: publish,
refresh: refresh,
- resize: resize
+ resize: resize,
+ value_at: value_at,
+ values_in: values_in
};
})(FnordMetric);
View
12 fnordmetric-ui/js/fnordmetric.widgets.counter.js
@@ -38,14 +38,10 @@ FnordMetric.widgets.counter = function(elem){
}
function requestDataAsync() {
- FnordMetric.publish({
- "type": "widget_request",
- "klass": "generic",
- "cmd": "values_for",
- "gauge": gauge,
- "at": at,
- "widget_key": widget_key
- })
+ FnordMetric.value_at(gauge, at, function(){
+ elem.attr('data-value', this.value);
+ updateDisplay();
+ });
}
function destroy() {
View
34 fnordmetric-ui/js/fnordmetric.widgets.timeseries.js
@@ -185,15 +185,31 @@ FnordMetric.widgets.timeseries = function(elem){
}
function requestDataAsync() {
- FnordMetric.publish({
- "type": "widget_request",
- "klass": "generic",
- "gauges": gauges,
- "cmd": "values_at",
- "tick": 30,
- "since": elem.attr("data-since"),
- "until": elem.attr("data-until"),
- "widget_key": widget_key
+ var since = elem.attr("data-since"),
+ until = elem.attr("data-until");
+
+ FnordMetric.values_in(gauges, since, until, function(){
+
+ var gauges = Object.keys(this)
+ gconfig.series = [];
+
+ for (ind in gauges) {
+ var gauge = gauges[ind];
+
+ gconfig.series.push({
+ name: gauge,
+ color: colors[ind],
+ data: []
+ });
+
+ for(_time in this[gauge]){
+ gconfig.series[ind].data.push(
+ { x: parseInt(_time), y: parseInt(this[gauge][_time] || 0) }
+ );
+ }
+ }
+
+ renderChart();
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.