From c1c75dd76bc221de4009851e26599a0b6c63c640 Mon Sep 17 00:00:00 2001 From: Phil Porada Date: Fri, 4 Aug 2017 15:47:26 -0400 Subject: [PATCH 1/3] Changed the logging to use the prometheus logger --- unbound_exporter.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/unbound_exporter.go b/unbound_exporter.go index 9978e7c..1cb0312 100644 --- a/unbound_exporter.go +++ b/unbound_exporter.go @@ -21,13 +21,13 @@ import ( "fmt" "io" "io/ioutil" - "log" "net/http" "os" "regexp" "strconv" "strings" + "github.com/prometheus/common/log" "github.com/prometheus/client_golang/prometheus" ) @@ -251,7 +251,6 @@ func CollectFromReader(file io.Reader, ch chan<- prometheus.Metric) error { scanner.Text()) } - gotMatch := false for _, metric := range unboundMetrics { matches := metric.pattern.FindStringSubmatch(fields[0]) if matches != nil { @@ -265,14 +264,9 @@ func CollectFromReader(file io.Reader, ch chan<- prometheus.Metric) error { value, matches[1:]...) - gotMatch = true break } } - if !gotMatch { - // log.Printf("Metric %q doesn't match and pattern!", fields[0]) - } - } return scanner.Err() } @@ -352,7 +346,7 @@ func (e *UnboundExporter) Collect(ch chan<- prometheus.Metric) { prometheus.GaugeValue, 1.0) } else { - log.Printf("Failed to scrape socket: %s", err) + log.Error("Failed to scrape socket: %s", err) ch <- prometheus.MustNewConstMetric( unboundUpDesc, prometheus.GaugeValue, @@ -371,6 +365,7 @@ func main() { ) flag.Parse() + log.Info("Starting unbound_exporter") exporter, err := NewUnboundExporter(*unboundHost, *unboundCa, *unboundCert, *unboundKey) if err != nil { panic(err) @@ -388,5 +383,6 @@ func main() { `)) }) + log.Info("Listening on", *listenAddress) log.Fatal(http.ListenAndServe(*listenAddress, nil)) } From 343344a7afbe54ef2315ff88f235cc96350bd3fc Mon Sep 17 00:00:00 2001 From: Phil Porada Date: Fri, 4 Aug 2017 16:00:03 -0400 Subject: [PATCH 2/3] Updated log line --- unbound_exporter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unbound_exporter.go b/unbound_exporter.go index 1cb0312..abe611b 100644 --- a/unbound_exporter.go +++ b/unbound_exporter.go @@ -383,6 +383,6 @@ func main() { `)) }) - log.Info("Listening on", *listenAddress) + log.Info("Listening on address:port => ", *listenAddress) log.Fatal(http.ListenAndServe(*listenAddress, nil)) } From 9ec36c5edac99d3908951020d1a42802e09b7bd8 Mon Sep 17 00:00:00 2001 From: Phil Porada Date: Fri, 4 Aug 2017 16:01:04 -0400 Subject: [PATCH 3/3] Ran gofmt --- unbound_exporter.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unbound_exporter.go b/unbound_exporter.go index abe611b..8c64999 100644 --- a/unbound_exporter.go +++ b/unbound_exporter.go @@ -27,8 +27,8 @@ import ( "strconv" "strings" - "github.com/prometheus/common/log" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/common/log" ) var ( @@ -365,7 +365,7 @@ func main() { ) flag.Parse() - log.Info("Starting unbound_exporter") + log.Info("Starting unbound_exporter") exporter, err := NewUnboundExporter(*unboundHost, *unboundCa, *unboundCert, *unboundKey) if err != nil { panic(err) @@ -383,6 +383,6 @@ func main() { `)) }) - log.Info("Listening on address:port => ", *listenAddress) + log.Info("Listening on address:port => ", *listenAddress) log.Fatal(http.ListenAndServe(*listenAddress, nil)) }