Forráskód Böngészése

Merge branch 'master' of https://bitbucket.org/ikflowdat/installer

Fernando Alonso 7 éve
szülő
commit
d19e29e0b5

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+tools/vendor
+statsd/endpoint/json/node_modules/
+statsd/endpoint/mongodb/node_modules/
+statsd/endpoint/mysql/node_modules/

+ 4 - 3
docker-compose.yml

@@ -93,8 +93,6 @@ services:
     volumes: 
       - ./stats/:/opt/stats/
  
- 
- 
   mysql:
     restart: always
     environment:
@@ -147,7 +145,7 @@ services:
 
   grafana:
     restart: always
-    image: grafana/grafana
+    image: grafana/grafana:master
     links:
      - jsonendpoint:endpoint
      - mysql_jsonendpoint:endpoint
@@ -176,6 +174,9 @@ services:
       - 9003:8000
     build: 
       context: ./statsd/endpoint/json
+    links:
+        - mysql_jsonendpoint:mysql_jsonendpoint
+        - mongodb_jsonendpoint:mongodb_jsonendpoint
     volumes:
       - ./statsd/endpoint/json:/opt/datasource
     environment:

+ 2 - 1
statsd/endpoint/json/Dockerfile

@@ -13,5 +13,6 @@ EXPOSE 8000
 
 RUN npm install -g nodemon
 
-CMD npm install && nodemon index.js
+RUN npm install
 
+CMD nodemon index.js

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 1945 - 0
statsd/endpoint/json/package-lock.json


+ 2 - 1
statsd/endpoint/mongodb/Dockerfile

@@ -13,5 +13,6 @@ EXPOSE 8000
 
 RUN npm install -g nodemon
 
-CMD npm install && nodemon index.js
+RUN npm install
 
+CMD nodemon index.js

+ 44 - 18
statsd/endpoint/mongodb/index.js

@@ -25,9 +25,11 @@ app.use(morgan('combined'));
 app.use(bodyParser.json());
 
 function setCORSHeaders(res) {
-  res.setHeader("Access-Control-Allow-Origin", "*");
-  res.setHeader("Access-Control-Allow-Methods", "POST");
-  res.setHeader("Access-Control-Allow-Headers", "accept, content-type");  
+    if (res) {        
+        res.setHeader("Access-Control-Allow-Origin", "*");
+        res.setHeader("Access-Control-Allow-Methods", "POST");
+        res.setHeader("Access-Control-Allow-Headers", "accept, content-type");  
+    }
 }
 
 app.all('/', function(req, res) {
@@ -37,6 +39,8 @@ app.all('/', function(req, res) {
 });
 
 app.all('/search', function (req, res) {
+    var target = req.body.target;
+    
     mongo.connect("mongodb://" + options.host + "/" + options.name, function (err, db) {
         if (err) {
             console.log(err);
@@ -47,7 +51,7 @@ app.all('/search', function (req, res) {
         db.listCollections().toArray(function(err, collInfos) {
             var mongo_search_result = [];
             _.each(collInfos, function(collInfo) {
-                if (mongo_search_result.indexOf(collInfo.name) === -1) {
+                if (collInfo.name.indexOf(target) && mongo_search_result.indexOf(collInfo.name) === -1) {
                     mongo_search_result.push(collInfo.name);
                 }
             });
@@ -59,6 +63,12 @@ app.all('/search', function (req, res) {
     });
 });
 
+// vars global
+var global_result;
+var global_res;
+var global_names;
+var checkInterval;
+
 app.all('/query', function (req, res) {
     var mongo_query_result = [];
     var from = new Date(req.body.range.from);
@@ -68,6 +78,8 @@ app.all('/query', function (req, res) {
     var names = _.map(req.body.targets, function (t) {
         return t.target;
     });
+    global_names = names;
+    global_res = res;
     var interval = req.body.intervalMs / 1000;
     var maxDataPoints = req.body.maxDataPoints;
 
@@ -96,26 +108,40 @@ app.all('/query', function (req, res) {
                     }
                     (result[name]).push([value, 1000 * doc.time]);
                 });
-
-                _.each(_.keys(result), function (key) {
-                    var data = {
-                        target: key,
-                        datapoints: result[key]
-                    };
-                    mongo_query_result.push(data);
-                });
-                
-                if (index === names.length -1) {
-                    setCORSHeaders(res);
-                    res.json(mongo_query_result);
-                    res.end();
-                }
+                var data = {
+                    target: name,
+                    datapoints: result[name]
+                };
+                mongo_query_result.push(data);
+                global_result = mongo_query_result;
             });
+            if (index === names.length -1) {
+                checkInterval = setInterval(checkResult, 1000);
+            }
         });
         
     });
 });
 
+function checkResult()
+{
+    if (global_result.length !== global_names.length) {
+        return false;
+    }
+    
+    clearInterval(checkInterval);
+    
+    if (global_res) {
+        setCORSHeaders(global_res);
+        global_res.json(global_result);
+        global_res.end();
+    }
+    
+    global_res = null;
+    
+    return true;
+}
+
 app.listen(8000);
 
 console.log("Server is listening to port 8000");

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 1758 - 0
statsd/endpoint/mongodb/package-lock.json


+ 1 - 0
statsd/endpoint/mongodb/package.json

@@ -4,6 +4,7 @@
   "description": "",
   "main": "index.js",
   "dependencies": {
+    "async": "^2.5.0",
     "body-parser": "^1.15.1",
     "express": "^4.15.3",
     "lodash": "^4.13.1",

+ 2 - 1
statsd/endpoint/mysql/Dockerfile

@@ -13,5 +13,6 @@ EXPOSE 8000
 
 RUN npm install -g nodemon
 
-CMD npm install && nodemon index.js
+RUN npm install
 
+CMD nodemon index.js

+ 28 - 28
statsd/endpoint/mysql/index.js

@@ -29,9 +29,10 @@ app.all('/', function(req, res) {
   res.end();
 });
 
-function search(table, res)
+function search(table, mysql_search_result, value, res)
 {
-    connection.query('SELECT DISTINCT(`name`) FROM `' + table + '` WHERE `name` NOT IN ("' + mysql_search_result.join('", "') + '") ORDER BY `name`', function (err, rows, fields) {
+//    connection.query('SELECT DISTINCT(`name`) FROM `' + table + '` WHERE `name` NOT IN ("' + mysql_search_result.join('", "') + '") ORDER BY `name`', function (err, rows, fields) {
+    connection.query('SELECT DISTINCT(`name`) FROM `' + table + '` WHERE `name` LIKE ("%' + value + '%") ORDER BY `name`', function (err, rows, fields) {
         if (err) {
             console.log(err);
             throw err;
@@ -41,28 +42,25 @@ function search(table, res)
                 mysql_search_result.push(rows[i].name);
             }
         }
+        if (res) {
+            setCORSHeaders(res);
+            res.json(mysql_search_result);
+            res.end();
+        }
     });
 }
 
-var mysql_search_result = [];
-
-search('gauges_statistics');
-search('counters_statistics');
-search('timers_statistics');
-search('sets_statistics');
-
 app.all('/search', function (req, res) {
-    setCORSHeaders(res);
-    res.json(mysql_search_result);
-    res.end();
+    var mysql_search_result = [];
+    var target = req.body.target; // metric
     
-    search('gauges_statistics');
-    search('counters_statistics');
-    search('timers_statistics');
-    search('sets_statistics');
+    search('gauges_statistics', mysql_search_result, target);
+    search('counters_statistics', mysql_search_result, target);
+    search('timers_statistics', mysql_search_result, target);
+    search('sets_statistics', mysql_search_result, target, res);
 });
 
-function query(table, req, res)
+function query(table, req, mysql_query_result, res)
 {
     var from = new Date(req.body.range.from);
     var to = new Date(req.body.range.to);
@@ -91,12 +89,14 @@ function query(table, req, res)
         }
         
         var result = [];
-        for (var i = 0; i < rows.length; i++) {
-            if (rows[i].name !== undefined) {
-                if (result.indexOf(rows[i].name) === -1) {
-                    result[rows[i].name] = new Array();   
+        var results = rows[1];
+        for (var i = 0; i < results.length; i++) {
+            var name = results[i].name;
+            if (name !== undefined) {
+                if (result[name] === undefined) {
+                    result[name] = [];
                 }
-                (result[rows[i].name]).push([rows[i].value, 1000 * rows[i].timestamp]);
+                result[name].push([results[i].value, 1000 * results[i].timestamp]);
             }
         }
         var keys = _.keys(result);
@@ -115,13 +115,13 @@ function query(table, req, res)
     });
 }
 
-var mysql_query_result = [];
 app.all('/query', function (req, res) {
-    mysql_query_result = [];
-    query('gauges_statistics', req);
-    query('counters_statistics', req);
-    query('timers_statistics', req);
-    query('sets_statistics', req, res);
+    var mysql_query_result = [];
+    
+    query('gauges_statistics', req, mysql_query_result);
+    query('counters_statistics', req, mysql_query_result);
+    query('timers_statistics', req, mysql_query_result);
+    query('sets_statistics', req, mysql_query_result, res);
 });
 
 app.listen(8000);

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 1584 - 0
statsd/endpoint/mysql/package-lock.json