我想为OpenTSDB创建一个非常简单的收集器,例如我正在考虑创建一个写一些随机值的简单javascript文件。
我不明白的是那些随机值的格式。 我必须做一个写一个字符串的程序,例如metric.name timestamp value ,或者只是我的简单程序只写一个值?
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?
最满意答案
Javascript不是执行此类任务的最佳选择,我会使用Python,Bash,Perl或Ruby。 我不是JS的专家,但希望这个例子适合你。
首先,您需要创建生成输出的文件。 所以foo.js将生成随机数,并在几秒钟内将它们与度量标准名称和时间戳一起打印:
var randvar = Math.random(); var ts = Math.round(new Date().getTime() / 1000); print ("metric.name "+ts+" "+randvar);其次,你需要一个可执行文件来启动foo.js ,这个文件将是foo.sh。 你必须给它执行权限chmod +x foo.sh 我正在使用rhino运行JS代码,您可以使用任何其他解释器:
#!/bin/bash rhino rand_tsd.js最后,您必须将文件放在tcollector/collectors/NUM/文件夹下,其中NUM是两次执行之间的间隔(以秒为单位)。 然后启动tcollector守护进程。
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.jsFinally 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.
了解OpenTSDB时间戳(Understanding OpenTSDB timestamp)我想为OpenTSDB创建一个非常简单的收集器,例如我正在考虑创建一个写一些随机值的简单javascript文件。
我不明白的是那些随机值的格式。 我必须做一个写一个字符串的程序,例如metric.name timestamp value ,或者只是我的简单程序只写一个值?
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?
最满意答案
Javascript不是执行此类任务的最佳选择,我会使用Python,Bash,Perl或Ruby。 我不是JS的专家,但希望这个例子适合你。
首先,您需要创建生成输出的文件。 所以foo.js将生成随机数,并在几秒钟内将它们与度量标准名称和时间戳一起打印:
var randvar = Math.random(); var ts = Math.round(new Date().getTime() / 1000); print ("metric.name "+ts+" "+randvar);其次,你需要一个可执行文件来启动foo.js ,这个文件将是foo.sh。 你必须给它执行权限chmod +x foo.sh 我正在使用rhino运行JS代码,您可以使用任何其他解释器:
#!/bin/bash rhino rand_tsd.js最后,您必须将文件放在tcollector/collectors/NUM/文件夹下,其中NUM是两次执行之间的间隔(以秒为单位)。 然后启动tcollector守护进程。
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.jsFinally 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.
发布评论