33package ipvs
44
55import (
6- "errors"
76 "fmt"
87 "math/bits"
98 "strconv"
109 "syscall"
1110
1211 "github.com/docker/libnetwork/ipvs"
1312 "github.com/influxdata/telegraf"
13+ "github.com/influxdata/telegraf/plugins/common/logrus"
1414 "github.com/influxdata/telegraf/plugins/inputs"
1515)
1616
@@ -35,7 +35,7 @@ func (i *IPVS) Gather(acc telegraf.Accumulator) error {
3535 if i .handle == nil {
3636 h , err := ipvs .New ("" ) // TODO: make the namespace configurable
3737 if err != nil {
38- return errors . New ( "Unable to open IPVS handle" )
38+ return fmt . Errorf ( "unable to open IPVS handle: %v" , err )
3939 }
4040 i .handle = h
4141 }
@@ -44,7 +44,7 @@ func (i *IPVS) Gather(acc telegraf.Accumulator) error {
4444 if err != nil {
4545 i .handle .Close ()
4646 i .handle = nil // trigger a reopen on next call to gather
47- return errors . New ( "Failed to list IPVS services" )
47+ return fmt . Errorf ( "failed to list IPVS services: %v" , err )
4848 }
4949 for _ , s := range services {
5050 fields := map [string ]interface {}{
@@ -61,7 +61,7 @@ func (i *IPVS) Gather(acc telegraf.Accumulator) error {
6161
6262 destinations , err := i .handle .GetDestinations (s )
6363 if err != nil {
64- i .Log .Errorf ("Failed to list destinations for a virtual server: %s " , err . Error () )
64+ i .Log .Errorf ("Failed to list destinations for a virtual server: %v " , err )
6565 continue // move on to the next virtual server
6666 }
6767
@@ -148,5 +148,8 @@ func addressFamilyToString(af uint16) string {
148148}
149149
150150func init () {
151- inputs .Add ("ipvs" , func () telegraf.Input { return & IPVS {} })
151+ inputs .Add ("ipvs" , func () telegraf.Input {
152+ logrus .InstallHook ()
153+ return & IPVS {}
154+ })
152155}
0 commit comments