influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.93k stars 5.6k forks source link

Telegraf 0.13.1 panic in Disk Plugin #1297

Closed lswith closed 8 years ago

lswith commented 8 years ago

Bug report

System info:

Telegraf 0.13.1 DISTRIB_ID=Ubuntu DISTRIB_RELEASE=12.04 DISTRIB_CODENAME=precise DISTRIB_DESCRIPTION="Ubuntu 12.04.5 LTS"

Relevant Config:

#
# INPUTS:
#
[[inputs.cpu]]
  percpu = true
  totalcpu = true
[[inputs.disk]]
[[inputs.diskio]]
[[inputs.kernel]]
[[inputs.mem]]
[[inputs.net]]
[[inputs.netstat]]
[[inputs.processes]]
[[inputs.puppetagent]]
[[inputs.swap]]
[[inputs.system]]

Error Message:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x63fd09]

goroutine 98 [running]:
panic(0x107ebc0, 0xc820010080)
    /usr/local/go/src/runtime/panic.go:481 +0x3e6
github.com/influxdata/telegraf/plugins/inputs/system.(*systemPS).DiskUsage(0x1c78550, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /home/ubuntu/telegraf-build/src/github.com/influxdata/telegraf/plugins/inputs/system/ps.go:87 +0x829
github.com/influxdata/telegraf/plugins/inputs/system.(*DiskStats).Gather(0xc82005c1e0, 0x7f369a02ba88, 0xc8203f8000, 0x0, 0x0)
    /home/ubuntu/telegraf-build/src/github.com/influxdata/telegraf/plugins/inputs/system/disk.go:44 +0xd9
github.com/influxdata/telegraf/agent.gatherWithTimeout.func1(0xc8203f40c0, 0xc82005f110, 0xc8203f8000)
    /home/ubuntu/telegraf-build/src/github.com/influxdata/telegraf/agent/agent.go:174 +0x73
created by github.com/influxdata/telegraf/agent.gatherWithTimeout
    /home/ubuntu/telegraf-build/src/github.com/influxdata/telegraf/agent/agent.go:175 +0xe0
alimousazy commented 8 years ago

This patch will check for error and return it back instead of panic

diff --git a/plugins/inputs/system/ps.go b/plugins/inputs/system/ps.go
index 23bfe16..fd1b261 100644
--- a/plugins/inputs/system/ps.go
+++ b/plugins/inputs/system/ps.go
@@ -84,6 +84,9 @@ func (s *systemPS) DiskUsage(
                mountpoint := os.Getenv("HOST_MOUNT_PREFIX") + p.Mountpoint
                if _, err := os.Stat(mountpoint); err == nil {
                        du, err := disk.Usage(mountpoint)
+      if err != nil {
+        return nil, err
+      }
                        du.Path = p.Mountpoint
                        if err != nil {
                                return nil, err
joshuaspence commented 8 years ago

Hmm, but why is it failing in the first place?

sparrc commented 8 years ago

with that change we'll get the error message and log it, rather than panicking :)

joshuaspence commented 8 years ago

Makes sense

lachesis commented 8 years ago
2016/08/04 03:40:00 ERROR in input [disk]: error getting disk usage info: too many levels of symbolic links