英文:
Bosun adding external collectors
问题
在Bosun中使用scollector定义新的外部收集器的步骤是什么?我们可以编写Python或Shell脚本来收集数据吗?
英文:
What is the procedure to define new external collectors in bosun using scollector.<br>
Can we write python or shell scripts to collect data?
答案1
得分: 7
关于这个问题的文档并不是最新的。你可以按照http://godoc.org/bosun.org/cmd/scollector#hdr-External_Collectors中描述的方式进行操作,但我们也支持更好的JSON输出。
无论哪种方式,你需要编写一个脚本或二进制文件,并将其放置在外部收集器目录中,然后是一个频率目录,类似这样的结构:
<external_collectors_dir>/<freq_sec>/foo.sh
。
如果频率目录为零0
,则脚本应该持续运行,并在代码中加入一个sleep语句(这是我首选的外部收集器方法)。脚本将输出Telnet格式或未记录的JSON格式到stdout。Scollector会捕获这些信息并将其排队发送。
我不久前创建了一个问题,以便将其记录下来:https://github.com/bosun-monitor/bosun/issues/1225。在我们有空处理之前,这是添加JSON的PR:https://github.com/bosun-monitor/bosun/commit/fced1642fd260bf6afa8cba169d84c60f2e23e92。
英文:
The documentation around this is not quite up to date. You can do it as described in http://godoc.org/bosun.org/cmd/scollector#hdr-External_Collectors , but we also support JSON output which is better.
Either way, you write something and put it in the external collectors directory, followed by a frequency directory, and then an executable script or binary. Something like:
<external_collectors_dir>/<freq_sec>/foo.sh
.
If the directory frequency is zero 0
, then the the script is expected to be continuously running, and you put a sleep inside the code (This is my preferred method for external collectors). The scripts outputs the telnet format, or the undocumented JSON format to stdout. Scollector picks it up, and queues that information for sending.
I created an issue to get this documented not long ago https://github.com/bosun-monitor/bosun/issues/1225. Until one of us gets around to that, here is the PR that added JSON https://github.com/bosun-monitor/bosun/commit/fced1642fd260bf6afa8cba169d84c60f2e23e92
答案2
得分: 2
根据Kyle的说法,你可以查看一些现有的外部收集器,看看它们的输出。这里是一个用Java编写的示例,我们的一位同事编写了它来监控JVM相关的内容。它使用文本格式,格式如下:
metricname timestamp value tag1=foo tag2=bar
如果你想使用JSON格式,这里有一个我们的收集器的示例:
{"metric":"exceptional.exceptions.count","timestamp":1438788720,"value":0,"tags":{"application":"AdServer","machine":"ny-web03","source":"NY_Status"}}
你还可以发送元数据:
{"Metric":"exceptional.exceptions.count","Name":"rate","Value":"counter"}
{"Metric":"exceptional.exceptions.count","Name":"unit","Value":"errors"}
{"Metric":"exceptional.exceptions.count","Name":"desc","Value":"每秒应用程序和机器抛出的异常数量。数据从多个来源查询。有关异常的详细信息,请参阅状态实例。"}`
或者将错误消息发送到标准错误输出:
2015/08/05 15:32:00 lookup OR-SQL03: no such host
英文:
Adding to what Kyle said, you can take a look at some existing external collectors to see what they output. here is one written in java that one of our colleagues wrote to monitor jvm stuff. It uses the text format, which is simply:
metricname timestamp value tag1=foo tag2=bar
If you want to use the JSON format, here is an example from one of our collectors:
{"metric":"exceptional.exceptions.count","timestamp":1438788720,"value":0,"tags":{"application":"AdServer","machine":"ny-web03","source":"NY_Status"}}
And you can also send metadata:
{"Metric":"exceptional.exceptions.count","Name":"rate","Value":"counter"}
{"Metric":"exceptional.exceptions.count","Name":"unit","Value":"errors"}
{"Metric":"exceptional.exceptions.count","Name":"desc","Value":"The number of exceptions thrown per second by applications and machines. Data is queried from multiple sources. See status instances for details on exceptions."}`
Or send error messages to stderror:
2015/08/05 15:32:00 lookup OR-SQL03: no such host
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论