From 90001371ab2ffc9d3ce53f3d4af690ad37d6523e Mon Sep 17 00:00:00 2001 From: Milan Nikolic Date: Sun, 22 Mar 2020 15:04:16 +0100 Subject: [PATCH] Add error descriptions --- collector/collector.go | 14 +++++++------- main.go | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/collector/collector.go b/collector/collector.go index f79c280..b6ae740 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -3,7 +3,7 @@ package collector import ( "bufio" "encoding/json" - "errors" + "fmt" "log" "os" "strconv" @@ -20,7 +20,7 @@ import ( // Signals. const ( SIGRTMIN = syscall.Signal(32) - SIGJSON = syscall.Signal(SIGRTMIN + 4) + SIGJSON = SIGRTMIN + 4 ) // States. @@ -210,14 +210,14 @@ func (k *KACollector) Collect(ch chan<- prometheus.Metric) { svcs, err := k.handle.GetServices() if err != nil { ch <- prometheus.MustNewConstMetric(k.metrics["keepalived_up"], prometheus.GaugeValue, 0) - log.Printf("keepalived_exporter: %v", err) + log.Printf("keepalived_exporter: services: %v", err) return } for _, s := range svcs { dsts, err := k.handle.GetDestinations(s) if err != nil { - log.Printf("keepalived_exporter: %v", err) + log.Printf("keepalived_exporter: destinations: %v", err) continue } @@ -273,17 +273,17 @@ func (k *KACollector) signal(sig syscall.Signal) error { } if pid == 0 { - return errors.New("cannot find pid") + return fmt.Errorf("cannot find pid") } proc, err := os.FindProcess(int(pid)) if err != nil { - return err + return fmt.Errorf("process %v: %v", pid, err) } err = proc.Signal(sig) if err != nil { - return err + return fmt.Errorf("signal %v: %v", sig, err) } time.Sleep(100 * time.Millisecond) diff --git a/main.go b/main.go index 1113f97..a7732d2 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,7 @@ func main() { http.Handle(*metricsPath, promhttp.HandlerFor(registry, promhttp.HandlerOpts{})) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(` + _, _ = w.Write([]byte(` Keepalived Exporter

Keepalived Exporter