Skip to content

Instantly share code, notes, and snippets.

@krisclarkdev
Last active June 14, 2019 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisclarkdev/184c9db7d3e00e20dca047f97074c5c1 to your computer and use it in GitHub Desktop.
Save krisclarkdev/184c9db7d3e00e20dca047f97074c5c1 to your computer and use it in GitHub Desktop.
Boilerplate code for a telegraf plugin
/*
Step 1. Create a folder called "mycollector" inside telegraf/plugins/inputs
Step 2. Create a file named "mycollector.go" inside the above folder
Step 3. Add an entry for "mycollector" *alphabetically* in plugins/inputs/all/all.go
_ "github.com/influxdata/telegraf/plugins/inputs/mycollector"
*/
package mycollector
import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
)
type Mycollector struct {
Servers []string
Username string
Password string
}
func (m *Mycollector) Gather(acc telegraf.Accumulator) error {
// This does work
// At end of collector fil Accumulator
return nil
}
func (m *Mycollector) Description() string {
return ""
}
func (m *Mycollector) SampleConfig() string {
return ""
}
func init() {
inputs.Add("mycollector", func() telegraf.Input {
return &Mycollector{}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment