safchain / ethtool

A simple ethtool "like" library for GO
Apache License 2.0
116 stars 69 forks source link

panic: runtime error: slice bounds out of range [:-1] #51

Open 0xFEEDC0DE64 opened 2 years ago

0xFEEDC0DE64 commented 2 years ago

I tried enabling ethtool in my influx telegraf, but now the service fails and crashes:

Mai 11 12:28:40 odroid-hc4-00 systemd[1]: Started The plugin-driven server agent for reporting metrics into InfluxDB.
Mai 11 12:28:40 odroid-hc4-00 telegraf[61949]: 2022-05-11T10:28:40Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"odroid-hc4-00", Flush Interval:10s
Mai 11 12:28:40 odroid-hc4-00 telegraf[61949]: 2022-05-11T10:28:40Z W! [inputs.smart] nvme not found: verify that nvme is installed and it is in your PATH (or specified in config) to gather vendor specific attributes: provided path does not exist: []
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]: panic: runtime error: slice bounds out of range [:-1]
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]: goroutine 30 [running]:
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]: github.com/safchain/ethtool.(*Ethtool).Stats(0x4000c6fab8, {0x400090628c, 0x4})
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]:         /go/pkg/mod/github.com/safchain/ethtool@v0.0.0-20200218184317-f459e2d13664/ethtool.go:595 +0x460
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]: github.com/influxdata/telegraf/plugins/inputs/ethtool.(*CommandEthtool).Stats(0x400019d218, {0x400090628c, 0x4})
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]:         /go/src/github.com/influxdata/telegraf/plugins/inputs/ethtool/ethtool_linux.go:159 +0x3c
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]: github.com/influxdata/telegraf/plugins/inputs/ethtool.(*Ethtool).gatherEthtoolStats(0x40005ca0e0, {0x2, 0x5dc, {0x400090628c, 0x4}, {0x4000024634, 0x6, 0x5cc}, 0x13}, {0x5764120, ...})
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]:         /go/src/github.com/influxdata/telegraf/plugins/inputs/ethtool/ethtool_linux.go:77 +0x170
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]: github.com/influxdata/telegraf/plugins/inputs/ethtool.(*Ethtool).Gather.func1(0x40005ca0e0, {0x5764120, 0x40008fb720}, 0x4000906460, {0x2, 0x5dc, {0x400090628c, 0x4}, {0x4000024634, 0x6, ...}, ...})
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]:         /go/src/github.com/influxdata/telegraf/plugins/inputs/ethtool/ethtool_linux.go:46 +0x54
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]: created by github.com/influxdata/telegraf/plugins/inputs/ethtool.(*Ethtool).Gather
Mai 11 12:28:50 odroid-hc4-00 telegraf[61949]:         /go/src/github.com/influxdata/telegraf/plugins/inputs/ethtool/ethtool_linux.go:45 +0x22c
Mai 11 12:28:50 odroid-hc4-00 systemd[1]: telegraf.service: Main process exited, code=exited, status=2/INVALIDARGUMENT

Output of my ethtool:

[feedc0de@odroid-hc4-00 ~]$ sudo ethtool eth0
Settings for eth0:
        Supported ports: [ TP    MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supported pause frame use: Symmetric Receive-only
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: Symmetric Receive-only
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Link partner advertised link modes:  10baseT/Half 10baseT/Full
                                             100baseT/Half 100baseT/Full
                                             1000baseT/Full
        Link partner advertised pause frame use: No
        Link partner advertised auto-negotiation: Yes
        Link partner advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Auto-negotiation: on
        master-slave cfg: preferred slave
        master-slave status: slave
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: external
        MDI-X: Unknown
        Supports Wake-on: ug
        Wake-on: d
        Current message level: 0x0000003f (63)
                               drv probe link timer ifdown ifup
        Link detected: yes

influx telegraf config:

[[inputs.ethtool]]
  interface_include = ["eth0"]
  # interface_exclude = ["eth1"]