@@ -35,11 +35,18 @@ type FileStat struct {
3535
3636 // maps full file paths to globmatch obj
3737 globs map [string ]* globpath.GlobPath
38+
39+ // files that were missing - we only log the first time it's not found.
40+ missingFiles map [string ]bool
41+ // files that had an error in Stat - we only log the first error.
42+ filesWithErrors map [string ]bool
3843}
3944
4045func NewFileStat () * FileStat {
4146 return & FileStat {
42- globs : make (map [string ]* globpath.GlobPath ),
47+ globs : make (map [string ]* globpath.GlobPath ),
48+ missingFiles : make (map [string ]bool ),
49+ filesWithErrors : make (map [string ]bool ),
4350 }
4451}
4552
@@ -85,12 +92,23 @@ func (f *FileStat) Gather(acc telegraf.Accumulator) error {
8592 fileInfo , err := os .Stat (fileName )
8693 if os .IsNotExist (err ) {
8794 fields ["exists" ] = int64 (0 )
95+ acc .AddFields ("filestat" , fields , tags )
96+ if ! f .missingFiles [fileName ] {
97+ f .Log .Warnf ("File %q not found" , fileName )
98+ f .missingFiles [fileName ] = true
99+ }
100+ continue
88101 }
102+ f .missingFiles [fileName ] = false
89103
90104 if fileInfo == nil {
91- f .Log .Errorf ("Unable to get info for file %q, possible permissions issue" ,
92- fileName )
105+ if ! f .filesWithErrors [fileName ] {
106+ f .filesWithErrors [fileName ] = true
107+ f .Log .Errorf ("Unable to get info for file %q: %v" ,
108+ fileName , err )
109+ }
93110 } else {
111+ f .filesWithErrors [fileName ] = false
94112 fields ["size_bytes" ] = fileInfo .Size ()
95113 fields ["modification_time" ] = fileInfo .ModTime ().UnixNano ()
96114 }
0 commit comments