Provide a -usage flag for printing the usage of a single plugin
Closes #136
This commit is contained in:
parent
50f902cb02
commit
42602a3f35
|
@ -13,13 +13,18 @@ import (
|
||||||
_ "github.com/influxdb/telegraf/plugins/all"
|
_ "github.com/influxdb/telegraf/plugins/all"
|
||||||
)
|
)
|
||||||
|
|
||||||
var fDebug = flag.Bool("debug", false, "show metrics as they're generated to stdout")
|
var fDebug = flag.Bool("debug", false,
|
||||||
|
"show metrics as they're generated to stdout")
|
||||||
var fTest = flag.Bool("test", false, "gather metrics, print them out, and exit")
|
var fTest = flag.Bool("test", false, "gather metrics, print them out, and exit")
|
||||||
var fConfig = flag.String("config", "", "configuration file to load")
|
var fConfig = flag.String("config", "", "configuration file to load")
|
||||||
var fVersion = flag.Bool("version", false, "display the version")
|
var fVersion = flag.Bool("version", false, "display the version")
|
||||||
var fSampleConfig = flag.Bool("sample-config", false, "print out full sample configuration")
|
var fSampleConfig = flag.Bool("sample-config", false,
|
||||||
|
"print out full sample configuration")
|
||||||
var fPidfile = flag.String("pidfile", "", "file to write our pid to")
|
var fPidfile = flag.String("pidfile", "", "file to write our pid to")
|
||||||
var fPLuginsFilter = flag.String("filter", "", "filter the plugins to enable, separator is :")
|
var fPLuginsFilter = flag.String("filter", "",
|
||||||
|
"filter the plugins to enable, separator is :")
|
||||||
|
var fUsage = flag.String("usage", "",
|
||||||
|
"print usage for a plugin, ie, 'telegraf -usage mysql'")
|
||||||
|
|
||||||
// Telegraf version
|
// Telegraf version
|
||||||
// -ldflags "-X main.Version=`git describe --always --tags`"
|
// -ldflags "-X main.Version=`git describe --always --tags`"
|
||||||
|
@ -39,6 +44,13 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *fUsage != "" {
|
||||||
|
if err := telegraf.PrintPluginConfig(*fUsage); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
config *telegraf.Config
|
config *telegraf.Config
|
||||||
err error
|
err error
|
||||||
|
|
12
config.go
12
config.go
|
@ -421,3 +421,15 @@ func PrintSampleConfig() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrintPluginConfig prints the config usage of a single plugin.
|
||||||
|
func PrintPluginConfig(name string) error {
|
||||||
|
if creator, ok := plugins.Plugins[name]; ok {
|
||||||
|
plugin := creator()
|
||||||
|
fmt.Printf("# %s\n[%s]\n", plugin.Description(), name)
|
||||||
|
fmt.Printf(strings.TrimSpace(plugin.SampleConfig()))
|
||||||
|
} else {
|
||||||
|
return errors.New(fmt.Sprintf("Plugin %s not found", name))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue