Skip to content

Commit

Permalink
Add error descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2brain committed Mar 22, 2020
1 parent 031d164 commit 9000137
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package collector
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"log"
"os"
"strconv"
Expand All @@ -20,7 +20,7 @@ import (
// Signals.
const (
SIGRTMIN = syscall.Signal(32)
SIGJSON = syscall.Signal(SIGRTMIN + 4)
SIGJSON = SIGRTMIN + 4
)

// States.
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`<html>
_, _ = w.Write([]byte(`<html>
<head><title>Keepalived Exporter</title></head>
<body>
<h1>Keepalived Exporter</h1>
Expand Down

0 comments on commit 9000137

Please sign in to comment.