[英]How to add a plugin to Telegraf?
您好我想知道是否有人已准備好為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]
如果你有一個我需要的列表,如何構建它,我存儲文件的位置或者一個例子可能真的很有幫助。
謝謝!!
- >我收到了這個,它給了我一個更好的理解,我認為它可能會有所幫助:
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
從那里你可以通過傳遞示例配置來運行帶有-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{} })
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.