Skip to content
This repository
Browse code

fnordmetric-ui + fnordmetric-enterprise integration :)

  • Loading branch information...
commit f3c3df59a6cda2df2f308f193be5945fcda08f2c 1 parent fc9dbd8
Paul Asmuth authored March 05, 2013
58  fnordmetric-ui/js/fnordmetric.js
@@ -2,6 +2,8 @@ var FnordMetric = (function(pre){
2 2
 
3 3
   var wsAddress, socket, currentNamespace,
4 4
      continuations = {},
  5
+     continuation = false,
  6
+     stack = [],
5 7
      widgets = {},
6 8
      enterprise = false;
7 9
 
@@ -71,6 +73,16 @@ var FnordMetric = (function(pre){
71 73
       if (data.substr(0,5) == "ERROR")
72 74
         return console.log("[FnordMetric] error: " + data.substr(6));
73 75
 
  76
+      else if (continuation) {
  77
+        continuation(data);
  78
+        continuation = false;
  79
+
  80
+        if (stack.length > 0) {
  81
+          var nxt = stack.shift();
  82
+          execute(nxt[0], nxt[1])
  83
+        }
  84
+      }
  85
+
74 86
     } else {
75 87
       var n, evt = JSON.parse(raw.data);
76 88
 
@@ -110,13 +122,46 @@ var FnordMetric = (function(pre){
110 122
     }
111 123
   }
112 124
 
  125
+  function execute(cmd, cb) {
  126
+    if (continuation === false) {
  127
+      socket.send(cmd);
  128
+      continuation = cb;
  129
+    } else {
  130
+      stack.push([cmd, cb]);
  131
+    }
  132
+  }
  133
+
113 134
   function values_in(gauges, since, until, callback) {
114 135
     if (enterprise) {
115  
-      continuation = function() {
116  
-        console.log("FFFUBAR", this);
  136
+      var all_resp = {};
  137
+
  138
+      function values_in_fetch_next() {
  139
+        var this_resp = gauges.shift();
  140
+
  141
+        execute(
  142
+          "VALUESIN " + this_resp + " " + since + " " + until,
  143
+          function(resp) {
  144
+            var vals = {},
  145
+                parts = resp.split(" ");
  146
+
  147
+            if (parts[0] != "null")
  148
+              for (ind in parts) {
  149
+                var tuple = parts[ind].split(":");
  150
+                tuple[0] = parseInt(tuple[0], 10) / 1000;
  151
+                vals[tuple[0]] = tuple[1];
  152
+              }
  153
+
  154
+            all_resp[this_resp] = vals;
  155
+
  156
+            if (gauges.length == 0)
  157
+              callback.apply(FnordMetric.util.zeroFill(all_resp));
  158
+            else
  159
+              values_in_fetch_next();
  160
+          }
  161
+        );
117 162
       }
118 163
 
119  
-      socket.send("VALUESIN " + gauges.first + " " + since + " " + until);
  164
+      values_in_fetch_next();
120 165
     }
121 166
 
122 167
     else {
@@ -145,7 +190,12 @@ var FnordMetric = (function(pre){
145 190
 
146 191
   function value_at(gauge, at, callback) {
147 192
     if (enterprise) {
148  
-
  193
+      execute(
  194
+        "VALUEAT " + gauge + " " + at,
  195
+        function(resp) {
  196
+          callback.apply({ "value": eval(resp) });
  197
+        }
  198
+      );
149 199
     }
150 200
 
151 201
     else {
5  fnordmetric-ui/js/fnordmetric.util.js
@@ -109,3 +109,8 @@ FnordMetric.util.parseTime = function(str) {
109 109
     console.log("[FnordMetric] invalid time specifiation: " + str);
110 110
   }
111 111
 }
  112
+
  113
+FnordMetric.util.zeroFill = function(obj) {
  114
+  console.log("FIXPAUL", obj);
  115
+  return obj;
  116
+}

0 notes on commit f3c3df5

Please sign in to comment.
Something went wrong with that request. Please try again.