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

node2opentsdb

v0.0.2

Published

Interfaces Node with OpenTSDB

Downloads

8

Readme

Node2OpenTSDB

Node2Opentsdb is a utility module which provides straight-forward functions to interact with OpenTSDB using node.js.

Quick Examples

Inserting DataPoints

var Node2OpenTSDB = require('node2opentsdb');

//Create a new client by specifying the host and port number on which OpenTSDB is running
var client = new Node2OpenTSDB({
host:"localhost",
port:4247
});

//You can pass array of data points to store in OpenTSDB at once
var dps =[ ];

var tags = {"host":"serv1","loc":"PHX"};

var metric1="mymetric.avg";
var metric2="mymetric.total_count";

var dp1 = {"metric":metric1,"timestamp":1397922972,"value":10,"tags":tags};
var dp2 = {"metric":metric2,"timestamp":1397923000,"value":20,"tags":tags};

dps.push(dp1);
dps.push(dp2);

//This function stores data points in opentsdb
client.store(dps);

Retrieving DataPoints

var Node2OpenTSDB = require('node2opentsdb');

//Create a new client by specifying the host and port number on which OpenTSDB is running
var client = new Node2OpenTSDB({
host:"localhost",
port:4247
});
var tags = {"host":"serv1","loc":"PHX"};

//Contruct Query Object
var queryObject = {
    start:"2014/04/24-12:00:00",
    end:"2014/04/25-12:00:00",
    metric:"mymetric.avg",
    aggregator:"sum",
    downsampler:"60m-avg",
    tags:tags
};

client.getDataPoints(queryObject,function(dataPoints,error){
    
    if(error)
        console.log(error);
    else
        console.log(dataPoints);

/*Sample response

dataPoints is an object with the following fields

[{"metric":"mymetric.avg","tags":{"host":"web1","loc":"phx"},"aggregateTags":[],"dps":{"1398324400":4025.0,"1398328400":4065.0,"1398332400":4105.0,"1398336400":4145.0,"1398340400":4185.0,"1398344400":4225.0,"1398348400":4265.0,"1398352400":4305.0,"1398356400":4345.0,"1398360400":4385.0,"1398364400":4425.0,"1398368400":4465.0,"1398372400":4505.0,"1398376400":4545.0,"1398380400":4585.0,"1398384400":4625.0,"1398388400":4665.0,"1398392400":4705.0,"1398396400":4745.0,"1398400400":4785.0,"1398404400":4825.0}}]

see http://opentsdb.net/docs/build/html/api_http/query/index.html for detailed explanation
*/

});

Construction of queryObject

While constructing queryObject to retrieve Data Points only start,metric,aggregator fields are 
necessary.The rest of the fields are optional.

//Example 1
var queryObject = {
    start:"2014/04/24-12:00:00",
    metric:"mymetric.avg",
    aggregator:"sum"
    }
In this case end time will be taken as current time.No downsampling is applied and no tags are also considered

//Example 2
var queryObject2={
    start:"2014/04/24-12:00:00",
    end:"2014/04/25-12:00:00",
    metric:"mymetric.avg",
    aggregator:"sum",
    downsampler:"60m-avg"
    }
In this case downsampling is applied on the metric between the given start date and end date.

//Example 3
var queryObject = {
    start:"5d-ago",
    end:"3d-ago",
    metric:"mymetric.avg",
    aggregator:"sum",
    downsampler:"60m-avg",
    tags:{"host":"serv1","loc":"PHX"}
};
This is a complete queryObject

see http://opentsdb.net/docs/build/html/user_guide/query/dates.html for date time format in OpenTSDB

Download

You can install using Node Package Manager (npm):

npm install node2opentsdb