Improve ipvs input error strings and logging (#6530)
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
package ipvs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/bits"
|
||||
"strconv"
|
||||
@@ -11,6 +10,7 @@ import (
|
||||
|
||||
"github.com/docker/libnetwork/ipvs"
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/common/logrus"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
@@ -35,7 +35,7 @@ func (i *IPVS) Gather(acc telegraf.Accumulator) error {
|
||||
if i.handle == nil {
|
||||
h, err := ipvs.New("") // TODO: make the namespace configurable
|
||||
if err != nil {
|
||||
return errors.New("Unable to open IPVS handle")
|
||||
return fmt.Errorf("unable to open IPVS handle: %v", err)
|
||||
}
|
||||
i.handle = h
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func (i *IPVS) Gather(acc telegraf.Accumulator) error {
|
||||
if err != nil {
|
||||
i.handle.Close()
|
||||
i.handle = nil // trigger a reopen on next call to gather
|
||||
return errors.New("Failed to list IPVS services")
|
||||
return fmt.Errorf("failed to list IPVS services: %v", err)
|
||||
}
|
||||
for _, s := range services {
|
||||
fields := map[string]interface{}{
|
||||
@@ -61,7 +61,7 @@ func (i *IPVS) Gather(acc telegraf.Accumulator) error {
|
||||
|
||||
destinations, err := i.handle.GetDestinations(s)
|
||||
if err != nil {
|
||||
i.Log.Errorf("Failed to list destinations for a virtual server: %s", err.Error())
|
||||
i.Log.Errorf("Failed to list destinations for a virtual server: %v", err)
|
||||
continue // move on to the next virtual server
|
||||
}
|
||||
|
||||
@@ -148,5 +148,8 @@ func addressFamilyToString(af uint16) string {
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("ipvs", func() telegraf.Input { return &IPVS{} })
|
||||
inputs.Add("ipvs", func() telegraf.Input {
|
||||
logrus.InstallHook()
|
||||
return &IPVS{}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user