npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sparkpost/redis-timeseries

v1.0.0

Published

Manage timeseries data storage in Redis with ease

Downloads

2

Readme

Node.js API for storing and querying time series in Redis

Build Status

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 = require('redis-timeseries'),
		redis = require('redis').createClient();
		
	// 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 = new TimeSeries(redis, "stats", granularities);
	
	// Recording hits
	//
	// This increments the counters for the
	// stats keys you provide
	//
	// "timestamp" defaults to the current time. If providing
	// a timestamp, it should be in unix timestamp format (seconds
	// since epoch).
    // "increment" defaults to 1
	//
	// .exec takes an optional callback with no arguments.
	ts.recordHit('your_stats_key')
	  .recordHit('another_stats_key', timestamp)
      .recordHit('another_stats_key', timestamp2, increment)
	  …
	  .exec(callback);

    // Removing hits
    //
    // Decrements the hits for a specified point in time.
    ts.removeHit('your_stats_key', [timestamp]).exec();
    
    // Decrement defaults to 1, but can be specified explicitly (below).
    ts.removeHit('your_stats_key', [timestamp], 5).exec();
	  
	// Querying statistics
	//
	// Returns "count" chunks of counters at the precision described by
	// "granularity_label"
	// 
	ts.getHits('your_stats_key', granularity_label, count, function(err, data) {
		// data.length == count
		// data = [ [ts1, count1], [ts2, count2]... ]
	});

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.minutes(5), duration: 1 },
    '1minute'  : { ttl: this.hours(1)  , duration: this.minutes(1) },
    '5minutes' : { ttl: this.days(1)   , duration: this.minutes(5) },
    '10minutes': { ttl: this.days(1)   , duration: this.minutes(10) },
    '1hour'    : { ttl: this.days(7)   , duration: this.hours(1) },
    '1day'     : { ttl: this.weeks(52) , duration: this.days(1) }
}

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.getHits('your_stats_key', '1second', ts.minutes(3), function(err, data){
		//process the data
	});
	
	// Give me the number of hits per day for the last 2 weeks
	ts.getHits('your_stats_key', '1day', 14, function(err, data){
		//process the data
	});
	
	// And so on

When creating the TimeSeries client, you can override the default granularities with your own.

Bitdeli Badge