metrano v0.1.2
Metrano is an PostgreSQL backed HTTP server for time series aggregation.
This package provide both the server an a node.js library which exposes the server's functionality.
It is designed to scale to billions (untested) of records per server. If you need more capacity, you can either shard your data and run more DB instances or you can look into Hadoop.
Install
npm install metrano --save
Server
start with node metrano.js
options:
--cleanupto reset the config table
APIs
fetch data
GET /feeds/<feedName>/<deviceId>/<aggrFunction>/<fromTimestamp>/<toTimestamp>Where:
feedNameis the name of the feed to retrieve data fromdeviceIdis the unique id of the data of the feedaggrFunctionis the calculation function to apply to feed values when they need to be aggregated. Can be one of:sumavgcountmaxminstddev_poppopulation standard deviation of the input valuesstddev_sampsample standard deviation of the input valuesvar_poppopulation variance of the input values (square of the population standard deviation)var_sampsample variance of the input values (square of the sample standard deviation)
fromTimestampthe time in milliseconds since UTC Epoch from which data should be retrievedtoTimestampthe time in milliseconds since UTC Epoch until which the data should be retrieved
The data is automatically aggregated based on the feed configuration and the requested time interval.
push values
a single data point:
POST /api/feeds/<feedName>/<deviceId>
{
value: 123,
timestamp: 1414943636741
}The timestamp (in milliseconds) timezone is interpreted as UTC.
define a new metric
POST /api/feeds
{
name: 'temperature',
aggregateThresholds: {
minute: 0,
hour: (2 * 60 * 60 * 1000),
day: (2 * 24 * 60 * 60 * 1000),
month: (24 * 30 * 24 * 60 * 60 * 1000)
}
}The aggregateThresholds attribute contains the timestamps for which an
aggregate should kick off.
Depending on the amount of data you want to retrieve, Metrano will reduce it
based on the values in the configuration.
Available aggregates references are:
microsecondsmillisecondssecondminutehourdayweekmonthquarteryeardecadecenturymillennium
Client
var Metrano = require('metrano')
var metrano = new Metrano('http://localhost:3000/')
metrano.define({ name: 'temperature', aggregateThresholds: { minute: 0, hour: (2 60 60 1000), day: (2 24 60 60 1000), month: (24 30 24 60 60 1000) } }, function(err) { // metric ready })
metrano.remove(feed, function(err) { // feed removed })
metrano.save(, <device_id>, , <UTC_timestamp>, function(err) { // metric saved })