Question

I want to create a very simple collector for OpenTSDB, For instance I'm thinking of creating a simple javascript file that writes some random values.

What I don't understand is the format of those random values. I must do a program that writes a string, for example metric.name timestamp value , or it's enough that my simple program writes only a value?

Was it helpful?

Solution

Javascript is not the best option for doing this type of task, I would use Python, Bash, Perl or Ruby. I'm not an expert in JS, but hopes this example works for you.

Firstly you will need to create the file that generates the output. So foo.js, will generate random numbers and print them along with metric name and timestamp in seconds:

var randvar = Math.random();
var ts = Math.round(new Date().getTime() / 1000);
print ("metric.name "+ts+" "+randvar);

Secondly you will need an executable file that launches foo.js, this file would be foo.sh. You have to give it execute permission chmod +x foo.sh. I'm running the JS code using rhino, you can use any other interpreter:

#!/bin/bash
rhino rand_tsd.js

Finally you have to put the files under the tcollector/collectors/NUM/ folder where NUM is the interval in seconds between two executions. Then launch tcollector daemon.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top