Node.js API for storing and querying time series in Redis
Convenient module for storing and querying time series statistics in Redis using Node.js.
The design (and even parts of the implementation) were picked from the ApiAxle project.
You can find basic usage examples in examples
. This module also powers a real-time dashboard written in Node.js. Check the sources out for more insight.
Dependencies
redis-timeseries
has no dependencies, and will work along the redis
module you'll install in your own project. redis@~0.9.0
versions are compatible.
Usage
var TimeSeries = redis = ; // Create the TimeSeries client // // "stats" is the Redis namespace which will be used // for storing all the TimeSeries related keys // // "granularities" encodes the granularities at which // you want to store statistics. More on that in the next section // var ts = redis "stats" granularities; // Recording hits // // This increments the counters for the // stats keys you provide // // "timestamp" defaults to the current time // "increment" defaults to 1 // ts … ; // Removing hits // // It's also possible to decrement the hits counter for // some key ts; // Querying statistics // // Returns "count" chunks of counters at the precision described by // "granularity_label" // ts;
Defining custom statistics granularities
For each key, TimeSeries
stores statistics at different granularities. For further information about this, please refer to the detailed blog post from the ApiAxle project.
The default granularities are:
'1second' : ttl: this duration: 1 '1minute' : ttl: this duration: this '5minutes' : ttl: this duration: this '10minutes': ttl: this duration: this '1hour' : ttl: this duration: this '1day' : ttl: this duration: this
This means that the number of hits per second
will be stored for 5 minutes
, and the corresponding hashset will expire afterwards. Likewise, the number of hits per minute
for a given key will be kept for an hour
. Daily
counters on the other hand are kept for a full year.
When querying for statistics, a granularity label is expected:
// Give me the hits/second for the last 3 minutes ts; // Give me the number of hits per day for the last 2 weeks ts; // And so on
When creating the TimeSeries
client, you can override the default granularities with your own.