Last active
November 10, 2015 12:28
-
-
Save Unitech/76e4f37f964b24c49292 to your computer and use it in GitHub Desktop.
Timeseries spec proposal / RethinkDB
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 characters
var timeseries = require('timeseries'); | |
var incoming_data = { | |
client : 2, | |
events_1sec : 10, | |
events_1min : 65 | |
}; | |
/** | |
* The timeseries module 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 characters
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); | |
}); | |
/** | |
* 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...'] | |
* } | |
* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment