您好我想知道是否有人准备为Influxf 的telegraf添加插件。 我的go代码正在运行。接下来我需要什么以及放置这些文件的位置?
我发现我需要做这样的事情:
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{} })
}
但这是我的整个Go插件还是Go中的另一个文件来添加我的Go程序?
file.conf存储在哪里?
[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]
如果你有我需要的列表,如何构建它,我存储文件的位置或者一个例子可能真的很有帮助。
谢谢!
答案 0 :(得分:3)
- >我收到了这个,它给了我更好的理解,我认为它可能会有所帮助:
https://github.com/influxdata/telegraf/blob/master/CONTRIBUTING.md
"他的插件代码看起来不错。他需要将该文件放在$ GOPATH / src / github.com / Influxdata / telegraf / plugin / inputs / testPlugin / testPlugin.go
中他应该为插件编写测试并将其放在$ GOPATH / src / github.com / Influxdata / telegraf / plugin / inputs / testPlugin / testPlugin_test.go
完成此操作后,他需要在$ GOPATH / src / github.com / Influxdata / telegraf / plugin / inputs / all / all.go
注册插件然后他应该从$ GOPATH / src / github.com / Influxdata / telegraf运行
make
。这将把新的telegraf二进制文件放在$ GOPATH / bin / telegraf中。使用以下标志运行二进制文件以生成有效配置:
$ GOPATH / bin / telegraf -sample-config -input-filter testPlugin -output-filter Influxdb> testPlugin_config.conf
从那里你可以通过传递示例config:
来运行带有-test标志的二进制文件$ GOPATH / bin / telegraf -config testPlugin_config.conf -test
这将输出要插入数据库的行协议。"
- >他谈到的 testPlugin.go :
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{} })
}
答案 1 :(得分:1)
external plugin support有一个问题,可能是Telegraf 1.4.0的一部分。如果可能会加载external *.so files。
在此之前,所有插件都应该合并到主repository via PRs中。已经有很多插件在审核过程中等待。这个模型显然不是很容易扩展。