influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.63k stars 5.58k forks source link

The input plugin I developed cannot be found through the input-list after make all #13572

Closed darianJmy closed 1 year ago

darianJmy commented 1 year ago

Please direct all support questsions to slack or the forums. Thank you.

The following is the copied demo

This is the directory structure in the plugins/inputs/alice

README.md
sample.conf
alice.go

cat alice.go

//go:generate ../../../tools/readme_config_includer/generator
package alice

import (
    _ "embed"

    "github.com/influxdata/telegraf"
    "github.com/influxdata/telegraf/plugins/inputs"
)

//go:embed sample.conf
var sampleConfig string

type Simple struct {
    Ok  bool            `toml:"ok"`
    Log telegraf.Logger `toml:"-"`
}

func (*Simple) SampleConfig() string {
    return sampleConfig
}

// Init is for setup, and validating config.
func (s *Simple) Init() error {
    return nil
}

func (s *Simple) Gather(acc telegraf.Accumulator) error {
    if s.Ok {
        acc.AddFields("state", map[string]interface{}{"value": "pretty good"}, nil)
    } else {
        acc.AddFields("state", map[string]interface{}{"value": "not great"}, nil)
    }

    return nil
}

func init() {
    inputs.Add("simple", func() telegraf.Input { return &Simple{} })
}

cat sample.conf

[[inputs.alice]]
  ok = true

This is the directory structure in the plugins/inputs/all/

cat alice.go

//go:build !custom || inputs || inputs.alice

package all

import _ "github.com/influxdata/telegraf/plugins/inputs/alice" // register plugin

Why can't I find the plugin in the binary file after I execute make all

./telegraf --input-list | grep alice
telegraf-tiger[bot] commented 1 year ago

Hello! I recommend posting this question in our Community Slack or Community Forums, we have a lot of talented community members there who could help answer your question more quickly. You can also learn more about Telegraf by enrolling at InfluxDB University for free!

Heads up, this issue will be automatically closed after 7 days of inactivity. Thank you!

darianJmy commented 1 year ago

i found the problem, inputs.Add name is plugin name

func init() {
    inputs.Add("simple", func() telegraf.Input { return &Simple{} })
}