Skip to content

Commit

Permalink
On metric writes, ignore errors and try to serve as many metrics as p…
Browse files Browse the repository at this point in the history
…ossible
  • Loading branch information
frodenas committed Apr 9, 2018
1 parent 29f135f commit de76257
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions firehose_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"
"gopkg.in/alecthomas/kingpin.v2"
Expand Down Expand Up @@ -111,6 +112,12 @@ func init() {
prometheus.MustRegister(version.NewCollector(*metricsNamespace))
}

type logger struct{}

func (l logger) Println(v ...interface{}) {
log.Error(v)
}

type basicAuthHandler struct {
handler http.HandlerFunc
username string
Expand All @@ -130,11 +137,20 @@ func (h *basicAuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

func prometheusHandler() http.Handler {
handler := prometheus.Handler()
handler := promhttp.InstrumentMetricHandler(
prometheus.DefaultRegisterer,
promhttp.HandlerFor(
prometheus.DefaultGatherer,
promhttp.HandlerOpts{
ErrorLog: logger{},
ErrorHandling: promhttp.ContinueOnError,
},
),
)

if *authUsername != "" && *authPassword != "" {
handler = &basicAuthHandler{
handler: prometheus.Handler().ServeHTTP,
handler: handler.ServeHTTP,
username: *authUsername,
password: *authPassword,
}
Expand Down

0 comments on commit de76257

Please sign in to comment.