From d65fa08b70416eb7885bd4493eb6d30ec18bf83c Mon Sep 17 00:00:00 2001 From: kongfei605 Date: Tue, 27 Feb 2024 18:56:27 +0800 Subject: [PATCH] fix: file collector default params for darwin and windows (#812) --- inputs/node_exporter/collector/file.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/inputs/node_exporter/collector/file.go b/inputs/node_exporter/collector/file.go index 26996fa4..02f6eb7a 100644 --- a/inputs/node_exporter/collector/file.go +++ b/inputs/node_exporter/collector/file.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "os" + "runtime" "strings" "github.com/prometheus/client_golang/prometheus" @@ -33,6 +34,9 @@ func NewFileNotifyCollector() (Collector, error) { ), } for _, fileName := range strings.Split(*fileList, ",") { + if len(strings.TrimSpace(fileName)) == 0 { + continue + } if data, err := f.readFile(fileName); err != nil { panic(err.Error()) } else { @@ -57,7 +61,11 @@ func (f *fileListCollector) readFile(fileName string) ([]byte, error) { func fileCollectorInit(params map[string]string) { files, ok := params["collector.file.notifylist"] if !ok { - *fileList = "/etc/passwd,/etc/shadow" + if runtime.GOOS == "linux" { + *fileList = "/etc/passwd,/etc/shadow" + } else { + *fileList = "" + } } else { *fileList = files }