Support default config paths
precedence will be: 1. --config command-line option 2. $TELEGRAF_CONFIG_PATH 3. $HOME/.telegraf/telegraf.conf 4. /etc/telegraf/telegraf.conf
This commit is contained in:
parent
5d3c582ecf
commit
cbe32c7482
|
@ -66,8 +66,7 @@ based on _prefix_ in addition to globs. This means that a filter like
|
||||||
- [#1096](https://github.com/influxdata/telegraf/pull/1096): Performance refactor of running output buffers.
|
- [#1096](https://github.com/influxdata/telegraf/pull/1096): Performance refactor of running output buffers.
|
||||||
- [#967](https://github.com/influxdata/telegraf/issues/967): Buffer logging improvements.
|
- [#967](https://github.com/influxdata/telegraf/issues/967): Buffer logging improvements.
|
||||||
- [#1107](https://github.com/influxdata/telegraf/issues/1107): Support lustre2 job stats. Thanks @hanleyja!
|
- [#1107](https://github.com/influxdata/telegraf/issues/1107): Support lustre2 job stats. Thanks @hanleyja!
|
||||||
- [#1110](https://github.com/influxdata/telegraf/pull/1110): Sanitize * to - in graphite serializer. Thanks @goodeggs!
|
- [#1122](https://github.com/influxdata/telegraf/pull/1122): Support setting config path through env variable and default paths.
|
||||||
- [#1118] (https://github.com/influxdata/telegraf/pull/1118): Sanitize Counter names for `win_perf_counters` input.
|
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
|
@ -84,6 +83,8 @@ based on _prefix_ in addition to globs. This means that a filter like
|
||||||
- [#1089](https://github.com/influxdata/telegraf/issues/1089): Fix leaky TCP connections in phpfpm plugin.
|
- [#1089](https://github.com/influxdata/telegraf/issues/1089): Fix leaky TCP connections in phpfpm plugin.
|
||||||
- [#914](https://github.com/influxdata/telegraf/issues/914): Telegraf can drop metrics on full buffers.
|
- [#914](https://github.com/influxdata/telegraf/issues/914): Telegraf can drop metrics on full buffers.
|
||||||
- [#1098](https://github.com/influxdata/telegraf/issues/1098): Sanitize invalid OpenTSDB characters.
|
- [#1098](https://github.com/influxdata/telegraf/issues/1098): Sanitize invalid OpenTSDB characters.
|
||||||
|
- [#1110](https://github.com/influxdata/telegraf/pull/1110): Sanitize * to - in graphite serializer. Thanks @goodeggs!
|
||||||
|
- [#1118](https://github.com/influxdata/telegraf/pull/1118): Sanitize Counter names for `win_perf_counters` input.
|
||||||
|
|
||||||
## v0.12.1 [2016-04-14]
|
## v0.12.1 [2016-04-14]
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,13 @@ The flags are:
|
||||||
-quiet run in quiet mode
|
-quiet run in quiet mode
|
||||||
-version print the version to stdout
|
-version print the version to stdout
|
||||||
|
|
||||||
|
In addition to the -config flag, telegraf will also load the config file from
|
||||||
|
an environment variable or default location. Precedence is:
|
||||||
|
1. -config flag
|
||||||
|
2. $TELEGRAF_CONFIG_PATH environment variable
|
||||||
|
3. $HOME/.telegraf/telegraf.conf
|
||||||
|
4. /etc/telegraf/telegraf.conf
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
# generate a telegraf config file:
|
# generate a telegraf config file:
|
||||||
|
@ -98,12 +105,10 @@ func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
args := flag.Args()
|
args := flag.Args()
|
||||||
|
|
||||||
if flag.NFlag() == 0 && len(args) == 0 {
|
|
||||||
usageExit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
var inputFilters []string
|
var inputFilters []string
|
||||||
if *fInputFiltersLegacy != "" {
|
if *fInputFiltersLegacy != "" {
|
||||||
|
fmt.Printf("WARNING '--filter' flag is deprecated, please use" +
|
||||||
|
" '--input-filter'")
|
||||||
inputFilter := strings.TrimSpace(*fInputFiltersLegacy)
|
inputFilter := strings.TrimSpace(*fInputFiltersLegacy)
|
||||||
inputFilters = strings.Split(":"+inputFilter+":", ":")
|
inputFilters = strings.Split(":"+inputFilter+":", ":")
|
||||||
}
|
}
|
||||||
|
@ -114,6 +119,8 @@ func main() {
|
||||||
|
|
||||||
var outputFilters []string
|
var outputFilters []string
|
||||||
if *fOutputFiltersLegacy != "" {
|
if *fOutputFiltersLegacy != "" {
|
||||||
|
fmt.Printf("WARNING '--outputfilter' flag is deprecated, please use" +
|
||||||
|
" '--output-filter'")
|
||||||
outputFilter := strings.TrimSpace(*fOutputFiltersLegacy)
|
outputFilter := strings.TrimSpace(*fOutputFiltersLegacy)
|
||||||
outputFilters = strings.Split(":"+outputFilter+":", ":")
|
outputFilters = strings.Split(":"+outputFilter+":", ":")
|
||||||
}
|
}
|
||||||
|
@ -170,25 +177,19 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
// If no other options are specified, load the config file and run.
|
||||||
c *config.Config
|
c := config.NewConfig()
|
||||||
err error
|
c.OutputFilters = outputFilters
|
||||||
)
|
c.InputFilters = inputFilters
|
||||||
|
err := c.LoadConfig(*fConfig)
|
||||||
if *fConfig != "" {
|
if err != nil {
|
||||||
c = config.NewConfig()
|
fmt.Println(err)
|
||||||
c.OutputFilters = outputFilters
|
|
||||||
c.InputFilters = inputFilters
|
|
||||||
err = c.LoadConfig(*fConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fmt.Println("You must specify a config file. See telegraf --help")
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *fConfigDirectoryLegacy != "" {
|
if *fConfigDirectoryLegacy != "" {
|
||||||
|
fmt.Printf("WARNING '--configdirectory' flag is deprecated, please use" +
|
||||||
|
" '--config-directory'")
|
||||||
err = c.LoadDirectory(*fConfigDirectoryLegacy)
|
err = c.LoadDirectory(*fConfigDirectoryLegacy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
|
@ -15,8 +15,8 @@ To generate a file with specific inputs and outputs, you can use the
|
||||||
telegraf -sample-config -input-filter cpu:mem:net:swap -output-filter influxdb:kafka
|
telegraf -sample-config -input-filter cpu:mem:net:swap -output-filter influxdb:kafka
|
||||||
```
|
```
|
||||||
|
|
||||||
You can see the latest config file with all available plugins
|
You can see the latest config file with all available plugins here:
|
||||||
[here](https://github.com/influxdata/telegraf/blob/master/etc/telegraf.conf)
|
[telegraf.conf](https://github.com/influxdata/telegraf/blob/master/etc/telegraf.conf)
|
||||||
|
|
||||||
## Environment Variables
|
## Environment Variables
|
||||||
|
|
||||||
|
|
|
@ -412,8 +412,35 @@ func (c *Config) LoadDirectory(path string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to find a default config file at these locations (in order):
|
||||||
|
// 1. $TELEGRAF_CONFIG_PATH
|
||||||
|
// 2. $HOME/.telegraf/telegraf.conf
|
||||||
|
// 3. /etc/telegraf/telegraf.conf
|
||||||
|
//
|
||||||
|
func getDefaultConfigPath() (string, error) {
|
||||||
|
envfile := os.Getenv("TELEGRAF_CONFIG_PATH")
|
||||||
|
homefile := os.ExpandEnv("${HOME}/.telegraf/telegraf.conf")
|
||||||
|
etcfile := "/etc/telegraf/telegraf.conf"
|
||||||
|
for _, path := range []string{envfile, homefile, etcfile} {
|
||||||
|
if _, err := os.Stat(path); err == nil {
|
||||||
|
log.Printf("Using config file: %s", path)
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we got here, we didn't find a file in a default location
|
||||||
|
return "", fmt.Errorf("No config file specified, and could not find one"+
|
||||||
|
" in $TELEGRAF_CONFIG_PATH, %s, or %s", homefile, etcfile)
|
||||||
|
}
|
||||||
|
|
||||||
// LoadConfig loads the given config file and applies it to c
|
// LoadConfig loads the given config file and applies it to c
|
||||||
func (c *Config) LoadConfig(path string) error {
|
func (c *Config) LoadConfig(path string) error {
|
||||||
|
var err error
|
||||||
|
if path == "" {
|
||||||
|
if path, err = getDefaultConfigPath(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
tbl, err := parseFile(path)
|
tbl, err := parseFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error parsing %s, %s", path, err)
|
return fmt.Errorf("Error parsing %s, %s", path, err)
|
||||||
|
|
Loading…
Reference in New Issue