Last active
August 29, 2015 14:06
-
-
Save Unitech/8d61538a0311f1be19e9 to your computer and use it in GitHub Desktop.
Revisions
-
Unitech revised this gist
Sep 28, 2014 . 1 changed file with 13 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,13 @@ var timeseries = require('timeseries')({ rethinkdb : { port : 28015, host : 'localhost', auth_key : null }, redis : { port : 6379, host : 'localhost' } }); /** @@ -9,6 +16,7 @@ var timeseries = require('timeseries')({ timeseries.put({ uid : 'specific-key', table : 'websocket-monitoring', rdb_database : 'specific-database', fields : ['clients', 'events_1sec', 'events_1min'], data : [ { @@ -55,9 +63,10 @@ timeseries.put({ timeseries.get({ uid : 'specific-key', table : 'websocket-monitoring', rdb_database : 'specific-database', fields : ['clients', 'events_1sec', 'events_1min'], from : moment().toDate(), to : moment().subtract(7, 'days').toDate(), }, function(err, data) { if(err){ throw err; -
vodolaz095 revised this gist
Sep 24, 2014 . 2 changed files with 0 additions and 70 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,47 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,23 +0,0 @@ -
vodolaz095 revised this gist
Sep 24, 2014 . 1 changed file with 79 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,79 @@ var timeseries = require('timeseries')({ 'rethinkConnectionString':"rethinkdb://username:[email protected]:57012/databasename", 'redisConnectionString':"redis://redistogo:[email protected]:10833/" }); /** * The timeseries module must be state-less */ timeseries.put({ uid : 'specific-key', table : 'websocket-monitoring', fields : ['clients', 'events_1sec', 'events_1min'], data : [ { clients : 2, events_1sec : 10, events_1min : 65 }, { clients : 2, events_1sec : 10, events_1min : 65 } ] }, function(error, elementsStored){}); /** * 1- The data is first aggregated every minutes (in memory or Redis, memory should be enough) * * { * clients : [0, 0, 14, 15, 43, 30], * events_1sec : [0, 0, 30, 50, 89, 90], * events_1min : [0, 0, 130, 400, 599, 300] * } * * 2- When the current minute is reached a simple mean calculation is made and we append the uid and the minute: * * { * clients : 25, * events_1sec : 40, * events_1min : 380, * at : 'Wed Sep 24 2014 17:29:00 GMT+0200 (CEST)', * uid : 'specific-key' * } * * 3 - The data is then flushed to database * * r.db(opts.db_name) * .table(opts.table) * .insert(data_object) * .run(opts.connection, function(err, cursor) { } * */ timeseries.get({ uid : 'specific-key', table : 'websocket-monitoring', fields : ['clients', 'events_1sec', 'events_1min'], from : new Date(Date.now() - 6*60*1000), //6 minutes ago? to : new Date(Date.now()) //hour ago }, function(err, data) { if(err){ throw err; } else { console.log(data); } }); /** * The outputted data should look like this: * * { * clients : [0, 0, 14, 15, 43, 30], //you mean 1 batch for every minute? * events_1sec : [0, 0, 30, 50, 89, 90], * events_1min : [0, 0, 130, 400, 599, 300] * time : ['Wed Sep 24 2014 17:29:00 GMT+0200 (CEST)', 'Wed Sep 24 2014 17:30:00 GMT+0200 (CEST)', '...every min...'] * } * */ -
Unitech revised this gist
Sep 24, 2014 . 2 changed files with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,6 +42,6 @@ timeseries.put({ * r.db(opts.db_name) * .table(opts.table) * .insert(data_object) * .run(opts.connection, function(err, cursor) { } * */ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,11 @@ var timeseries = require('timeseries'); timeseries.get({ uid : 'specific-key', db_name : 'database-name', connection : connection_to_rethinkdb_database, table : 'websocket-monitoring', fields : ['clients', 'events_1sec', 'events_1min'] }, function(err, data) { return console.log(data); }); -
Unitech revised this gist
Sep 24, 2014 . 2 changed files with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ var incoming_data = { }; /** * The timeseries module must be state-less */ timeseries.put({ uid : 'specific-key', File renamed without changes. -
Unitech created this gist
Sep 24, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ var timeseries = require('timeseries'); var incoming_data = { client : 2, events_1sec : 10, events_1min : 65 }; /** * The put method must be state-less */ timeseries.put({ uid : 'specific-key', db_name : 'database-name', connection : connection_to_rethinkdb_database, table : 'websocket-monitoring', fields : ['clients', 'events_1sec', 'events_1min'], data : incoming_data }); /** * 1- The data is first aggregated every minutes (in memory or Redis, memory should be enough) * * { * clients : [0, 0, 14, 15, 43, 30], * events_1sec : [0, 0, 30, 50, 89, 90], * events_1min : [0, 0, 130, 400, 599, 300] * } * * 2- When the current minute is reached a simple mean calculation is made and we append the uid and the minute: * * { * clients : 25, * events_1sec : 40, * events_1min : 380, * at : 'Wed Sep 24 2014 17:29:00 GMT+0200 (CEST)', * uid : 'specific-key' * } * * 3 - The data is then flushed to database * * r.db(opts.db_name) * .table(opts.table) * .insert(data_object) * .run(opts.connection, function(err, cursor) { /*...*/ } * */ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ var timeseries = require('timeseries'); timeseries.get({ uid : 'specific-key', db : connection_to_database, table : 'websocket-monitoring', fields : ['clients', 'events_1sec', 'events_1min'] }, function(err, data) { return console.log(data); }); /** * The outputted data should look like this: * * { * clients : [0, 0, 14, 15, 43, 30], * events_1sec : [0, 0, 30, 50, 89, 90], * events_1min : [0, 0, 130, 400, 599, 300] * time : ['Wed Sep 24 2014 17:29:00 GMT+0200 (CEST)', 'Wed Sep 24 2014 17:30:00 GMT+0200 (CEST)', '...every min...'] * } * */