How to add a plugin to Telegraf?

Hello, I would like to know if anyone has any ready to add a plugin to telegraf for Influxdb . I have a go go code that works. What do I need next and where to put my abstract files?

I found that I need to do something like this:

type ReadFile struct { //buf []byte //MemoryBytes int64 //PID int } func (s *ReadFile) Description() string { return "This is a test plugin to read data from a file and send them to influxdb" } func (s *ReadFile) SampleConfig() string { return "ok = true # indicate if everything is fine" } func Gather(acc plugins.Accumulator) error { readFile(alarmFile) acc.Add("alarm", result_of_readFile_here, tags) } } func init() { plugins.Add("readFile", func() plugins.Plugin { &ReadFile{} }) } 

But is it my whole Go plugin or another file in Go to add with my Go program?

And where is the file.conf file stored?

 [tags] dc = "alarm" [agent] interval = "10s" # OUTPUTS [outputs] [outputs.influxdb] url = "http://127.0.0.1:8086" # required. database = "summer" # required. precision = "s" # PLUGINS [readFile] 

If you have a list of what I need, how to structure it, where I store the file, or maybe an example can be really useful.

Thanks!!

+2
source share
2 answers

-> I get this, it gave me a better understanding, I think it might be useful:

https://github.com/influxdata/telegraf/blob/master/CONTRIBUTING.md

"His plugin code looks pretty good. He should put this file in $ GOPATH / src / github.com / infuxdata / telegraf / plugin / entries / testPlugin / testPlugin.go

He should write a test for the plugin and put it in $ GOPATH / src / github.com / infuxdata / telegraf / plugin / entries / testPlugin / testPlugin_test.go

After that, he should register the plugin in $ GOPATH / src / github.com / infuxdata / telegraf / plugin / input / all / all.go

Then it should run make from $ GOPATH / src / github.com / infuxdata / telegraf. This will put the new telegraf binary in $ GOPATH / bin / telegraf.

Run the binary file with the following flags to create the correct configuration:

$ GOPATH / bin / telegraf -sample-config -input-filter testPlugin -output-filter influxdb> testPlugin_config.conf

From there, you can run the binary with the -test flag, passing it the config sample:

$ GOPATH / bin / telegraf -config testPlugin_config.conf -test

This will lead to the output of the string protocol, which must be inserted into the database.

-> And testPlugin.go , which he is talking about:

 package testPlugin import ( "time" ) type ReadFile struct { counter int64 } func (s *TestPlugin) Description() string { return "This is a test plugin to write data to influxdb with a plugin" } func (s *TestPlugin) SampleConfig() string { return "ok = true # indicate if everything is fine" } func Gather(acc telegraf.Accumulator) error { c := time.Tick(10 * time.Second) for now := range c { counter := counter + 1 acc.Add("counter",counter, tags) } } func init() { inputs.Add("testPlugin", func() telegraf.Input { return &TestPlugin{} }) } 
+2
source

There is an open problem for supporting an external plugin , which may be part of Telegraf 1.4.0. If, possibly, external * .so files are loaded.

Until then, all plugins should be integrated into the master repository via PR . There are already many plugins in the process of viewing. Obviously, this model is not very scalable.

+1
source

Source: https://habr.com/ru/post/1260898/


All Articles