node2opentsdb
v0.0.2
Published
Interfaces Node with OpenTSDB
Downloads
3
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