What is the procedure to define new external collectors in bosun using scollector.
Can we write python or shell scripts to collect data?
2 Answers
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

- 26,938
- 37
- 124
- 165
-
Thanks Kyle. How do we specify that a directory is an external collecters' directory ? I'm running a docker container. – sbose Aug 05 '15 at 18:01
-
@sbose ColDir the the .toml configuration file, it is in the documentation I linked. I don't ever use the docker image, so not sure how to get that in there. – Kyle Brandt Aug 05 '15 at 18:17
-
OK, added a basic external collector which prints timestamps and random numbers. https://gist.github.com/sbose78/4be0a77fd7e950dec3a6 However I do not see the metric in the ITEMS page. :( – sbose Aug 06 '15 at 05:24
-
OpenTSDB spec requires at least one tag value pair as per it's specification – Kyle Brandt Aug 06 '15 at 05:32
-
Thanks, here it said they were optional ( http://godoc.org/bosun.org/cmd/scollector#hdr-External_Collectors ). Anyway I added a random tag https://gist.github.com/sbose78/4be0a77fd7e950dec3a6 :) but Still the metric doesn't turn up in the "ITEMS". Also, /var/logsyslog doesnt say anything. – sbose Aug 06 '15 at 05:37
-
Worked - the trick was to run a new scollector instance with the relevant parameters. – sbose Aug 06 '15 at 06:12
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

- 14,929
- 12
- 80
- 104

- 22,118
- 17
- 108
- 151