Skip to content

Commit

Permalink
fix: file collector default params for darwin and windows (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongfei605 authored Feb 27, 2024
1 parent afe93ed commit d65fa08
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion inputs/node_exporter/collector/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
"runtime"
"strings"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit d65fa08

Please sign in to comment.