From 473bcd5aa16d568b328fece4a46c1535bf981cb4 Mon Sep 17 00:00:00 2001 From: Marcus Franke Date: Wed, 2 Nov 2016 10:48:36 +0100 Subject: [PATCH 1/2] [docs] enhanced the basic example To protect people from starting their exporter multiple times, one has to evaluate the error returned by http.ListenAndServe(). --- prometheus/doc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prometheus/doc.go b/prometheus/doc.go index b15a2d3..618c4de 100644 --- a/prometheus/doc.go +++ b/prometheus/doc.go @@ -59,7 +59,7 @@ // // The Handler function provides a default handler to expose metrics // // via an HTTP server. "/metrics" is the usual endpoint for that. // http.Handle("/metrics", promhttp.Handler()) -// http.ListenAndServe(":8080", nil) +// log.Fatal(http.ListenAndServe(":8080", nil)) // } // // From 17f1add33cedc24f83d52f6b00963b526e1be4e2 Mon Sep 17 00:00:00 2001 From: Marcus Franke Date: Wed, 2 Nov 2016 10:52:31 +0100 Subject: [PATCH 2/2] Changed example sources according to the basic documentation example --- examples/random/main.go | 3 ++- examples/simple/main.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/random/main.go b/examples/random/main.go index 5639571..955b21b 100644 --- a/examples/random/main.go +++ b/examples/random/main.go @@ -18,6 +18,7 @@ package main import ( "flag" + "log" "math" "math/rand" "net/http" @@ -99,5 +100,5 @@ func main() { // Expose the registered metrics via HTTP. http.Handle("/metrics", prometheus.Handler()) - http.ListenAndServe(*addr, nil) + log.Fatal(http.ListenAndServe(*addr, nil)) } diff --git a/examples/simple/main.go b/examples/simple/main.go index 19620d2..47f57ca 100644 --- a/examples/simple/main.go +++ b/examples/simple/main.go @@ -16,6 +16,7 @@ package main import ( "flag" + "log" "net/http" "github.com/prometheus/client_golang/prometheus" @@ -26,5 +27,5 @@ var addr = flag.String("listen-address", ":8080", "The address to listen on for func main() { flag.Parse() http.Handle("/metrics", prometheus.Handler()) - http.ListenAndServe(*addr, nil) + log.Fatal(http.ListenAndServe(*addr, nil)) }