metrano
v0.1.2
Published
Real-time metrics datastore & server
Downloads
8
Readme
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:
--cleanup
to reset the config table
APIs
fetch data
GET /feeds/<feedName>/<deviceId>/<aggrFunction>/<fromTimestamp>/<toTimestamp>
Where:
feedName
is the name of the feed to retrieve data fromdeviceId
is the unique id of the data of the feedaggrFunction
is the calculation function to apply to feed values when they need to be aggregated. Can be one of:sum
avg
count
max
min
stddev_pop
population standard deviation of the input valuesstddev_samp
sample standard deviation of the input valuesvar_pop
population variance of the input values (square of the population standard deviation)var_samp
sample variance of the input values (square of the sample standard deviation)
fromTimestamp
the time in milliseconds since UTC Epoch from which data should be retrievedtoTimestamp
the 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:
microseconds
milliseconds
second
minute
hour
day
week
month
quarter
year
decade
century
millennium
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 })