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

nsone-opentsdb-mock-server

v0.2.0

Published

Mock OpenTSDB server, edited for ns1.

Downloads

3

Readme

Mock Server

NPM version Build Status Coverage Status Dependencies

Mock OpenTSDB server.

NOTE: this server is not comprehensive and does not mock all aspects of OpenTSDB. The server mainly mocks the REST API and provides some useful routes when testing response handlers.

Install

For use in Node.js,

$ npm install opentsdb-mock-server

For use in the browser, use browserify.

Usage

To use the module,

var createApp = require( 'opentsdb-mock-server' );

To create a new mock OpenTSDB application,

var db = createApp();

The mock OpenTSDB application has the following attributes and methods...

db.url

The mock OpenTSDB URL endpoint.

console.log( db.url );

db.query

A mock OpenTSDB HTTP request query URL.

console.log( db.query );

db.aggregators

Mock OpenTSDB aggregation functions.

console.log( db.aggregators );
// returns [...]

db.metrics

Mock OpenTSDB metrics.

console.log( db.metrics );
// returns [...]

db.config

Mock OpenTSDB configuration.

console.log( db.config );
// returns {...}

db.version

Mock OpenTSDB version information.

console.log( db.version );
// returns {...}

db.dropcaches

Mock OpenTSDB response to a request to drop caches.

console.log( db.dropcaches );
// returns {...}

db.createServer( clbk )

Creates a mock OpenTSDB application HTTP server. The provided callback is invoked once the server is listening and ready to receive HTTP requests.

var server = db.createServer( function onListen() {
	console.log( '...listening...' );
});

Routes

The application has the following routes...

GET /api/query

Mocks the OpenTSDB query API.

var request = require( 'request' );

request({
	'method': 'GET',
	'uri': db.query
}, function onResponse( error, response, body ) {
	console.log( body );
});

GET /api/aggregators

Returns the list of aggregators supported by the mock OpenTSDB.

var request = require( 'request' );

request({
	'method': 'GET',
	'uri': db.url + '/api/aggregators'
}, function onResponse( error, response, body ) {
	console.log( body );
});

GET /api/suggest

Returns a list of metrics.

var request = require( 'request' );

request({
	'method': 'GET',
	'uri': db.url + '/api/suggest'
}, function onResponse( error, response, body ) {
	console.log( body );
});

GET /api/config

Returns a mock OpenTSDB configuration.

var request = require( 'request' );

request({
	'method': 'GET',
	'uri': db.url + '/api/config'
}, function onResponse( error, response, body ) {
	console.log( body );
});

GET /api/version

Returns mock OpenTSDB version information.

var request = require( 'request' );

request({
	'method': 'GET',
	'uri': db.url + '/api/version'
}, function onResponse( error, response, body ) {
	console.log( body );
});

GET /api/dropcaches

Returns a mock OpenTSDB response to a drop cache request.

var request = require( 'request' );

request({
	'method': 'GET',
	'uri': db.url + '/api/dropcaches'
}, function onResponse( error, response, body ) {
	console.log( body );
});

GET /bad_body

Returns an empty body; useful when testing HTTP response handling.

var request = require( 'request' );

request({
	'method': 'GET',
	'uri': db.url + '/bad_body'
}, function onResponse( error, response, body ) {
	console.log( body );
});

GET /bad_json

Returns improperly formatted JSON; useful when testing HTTP response handling.

var request = require( 'request' );

request({
	'method': 'GET',
	'uri': db.url + '/bad_json'
}, function onResponse( error, response, body ) {
	try {
		JSON.parse( body );
	} catch ( err ) {
		console.log( err );
	}
});

GET /no_data

Returns an empty array; useful when testing HTTP response handling in the event of no data.

var request = require( 'request' );

request({
	'method': 'GET',
	'uri': db.url + '/no_data'
}, function onResponse( error, response, body ) {
	console.log( body );
});

GET /good_data

Returns a sample successful data response.

var request = require( 'request' );

request({
	'method': 'GET',
	'uri': db.url + '/good_data'
}, function onResponse( error, response, body ) {
	console.log( body );
});

Examples

var createApp = require( 'opentsdb-mock-server' ),
	request = require( 'request' );

// Create a new mock OpenTSDB application:
var db = createApp();

// Get the mock version:
console.log( db.version );

// Get the mock URL:
console.log( db.url );

// Start the mock server:
var server = db.createServer( function onListen() {
	console.log( '...listening...' );

	request({
		'method': 'GET',
		'uri': db.query
	}, function onResponse( error, response, body ) {
		console.log( body );

		// Close the server:
		server.close();
	});
});

To run the example code from the top-level application directory,

$ node ./examples/index.js

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

License

MIT license.


Copyright

Copyright © 2014. Athan Reines.