influxdb/telegraf/plugins/inputs/file.go

36 lines
884 B
Go
Raw Normal View History

2018-10-05 21:43:01 +00:00
package inputs
import (
"fmt"
"strconv"
"strings"
)
// File is based on telegraf input File plugin.
type File struct {
2018-10-16 00:38:36 +00:00
baseInput
2018-10-05 21:43:01 +00:00
Files []string `json:"files"`
}
2018-10-16 00:38:36 +00:00
// PluginName is based on telegraf plugin name.
func (f *File) PluginName() string {
return "file"
}
2018-10-05 21:43:01 +00:00
// TOML encodes to toml string
func (f *File) TOML() string {
s := make([]string, len(f.Files))
2018-10-05 21:43:01 +00:00
for k, v := range f.Files {
2018-10-05 21:43:01 +00:00
s[k] = strconv.Quote(v)
}
2018-10-16 00:38:36 +00:00
return fmt.Sprintf(`[[inputs.%s]]
2018-10-05 21:43:01 +00:00
## Files to parse each interval.
## These accept standard unix glob matching rules, but with the addition of
## ** as a "super asterisk". ie:
## /var/log/**.log -> recursively find all .log files in /var/log
## /var/log/*/*.log -> find all .log files with a parent dir in /var/log
## /var/log/apache.log -> only read the apache log file
files = [%s]
2018-10-16 00:38:36 +00:00
`, f.PluginName(), strings.Join(s, ", "))
2018-10-05 21:43:01 +00:00
}