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.