Fix possible panic when file info cannot be gotten

closes #2061
This commit is contained in:
Cameron Sparr 2016-12-13 14:49:11 +00:00
parent 07684fb030
commit e097ae9632
No known key found for this signature in database
GPG Key ID: 19E67263DCB25D0F
2 changed files with 10 additions and 2 deletions

View File

@ -27,6 +27,7 @@
- [#2146](https://github.com/influxdata/telegraf/issues/2146): Fix potential panic in aggregator plugin metric maker. - [#2146](https://github.com/influxdata/telegraf/issues/2146): Fix potential panic in aggregator plugin metric maker.
- [#1843](https://github.com/influxdata/telegraf/pull/1843) & [#1668](https://github.com/influxdata/telegraf/issues/1668): Add optional ability to define PID as a tag. - [#1843](https://github.com/influxdata/telegraf/pull/1843) & [#1668](https://github.com/influxdata/telegraf/issues/1668): Add optional ability to define PID as a tag.
- [#1730](https://github.com/influxdata/telegraf/issues/1730): Fix win_perf_counters not gathering non-English counters. - [#1730](https://github.com/influxdata/telegraf/issues/1730): Fix win_perf_counters not gathering non-English counters.
- [#2061](https://github.com/influxdata/telegraf/issues/2061): Fix panic when file stat info cannot be collected due to permissions or other issue(s).
## v1.1.2 [2016-12-12] ## v1.1.2 [2016-12-12]

View File

@ -4,6 +4,7 @@ import (
"crypto/md5" "crypto/md5"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
@ -79,7 +80,13 @@ func (f *FileStat) Gather(acc telegraf.Accumulator) error {
} }
fields := map[string]interface{}{ fields := map[string]interface{}{
"exists": int64(1), "exists": int64(1),
"size_bytes": fileInfo.Size(), }
if fileInfo == nil {
log.Printf("E! Unable to get info for file [%s], possible permissions issue",
fileName)
} else {
fields["size_bytes"] = fileInfo.Size()
} }
if f.Md5 { if f.Md5 {