plugins - 如何向 Telegraf 添加插件?

标签 plugins go influxdb

你好,我想知道是否有人已经准备好为 Influxdb 添加一个插件到 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

"His plugin code looks good to go. He needs to place that file in $GOPATH/src/github.com/influxdata/telegraf/plugin/inputs/testPlugin/testPlugin.go

He should write a test for the plugin and place it at $GOPATH/src/github.com/influxdata/telegraf/plugin/inputs/testPlugin/testPlugin_test.go

After this is complete he needs to register the plugin at $GOPATH/src/github.com/influxdata/telegraf/plugin/inputs/all/all.go

Then he should run make from $GOPATH/src/github.com/influxdata/telegraf. This will place the new telegraf binary in $GOPATH/bin/telegraf.

Run the binary with the following flags to generate the valid 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 by passing it the sample config:

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

This will output the line protocol that is to be inserted into the database."

-> 还有他说的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{} })
}

关于plugins - 如何向 Telegraf 添加插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37437090/

相关文章:

当注入(inject)的服务具有较旧的 Grails 版本时,Grails 服务注入(inject) null

go - 去获取不起作用

time-series - Riak TS/InfluxDB 系列数量限制

http - 将参数绑定(bind)到时间维度参数 InfluxDB

jQuery:尝试编写我的第一个插件,如何将选择器传递给我的函数?

firefox - 我应该如何以及通过什么为 Firefox 创建插件?

java - XJC 插件定制

nginx - Gorilla WebSocket 一分钟后断开连接

go - 我如何向 channel 发送者发出信号以退出 golang?

InfluxDB 按标签从组中选择前 n 个结果