繁体   English   中英

如何在Telegraf中添加插件?

[英]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{} })
}

外部插件支持已经出现问题,可能是Telegraf 1.4.0的一部分。 如果可能会加载外部* .so文件

在此之前,所有插件都应该通过PR合并到主存储库中 已经有很多插件在审​​核过程中等待。 这个模型显然不是很可扩展。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM