Skip to content

Commit

Permalink
log errors from the prometheus handler
Browse files Browse the repository at this point in the history
Set the ErrorLogger of the prometheus handler to our logger.
This helps to debug prometheus related issues, if they should occur.
  • Loading branch information
fho authored Sep 7, 2023
1 parent 812c5db commit 4a78aae
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/jamiealquiza/envy"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

jenkinsexporter "github.com/simplesurance/jenkins-exporter/internal"
Expand All @@ -40,6 +41,7 @@ const (
)

var logger = log.New(os.Stderr, "", 0)
var promLogger = log.New(os.Stderr, "prometheus: ", 0)
var debugLogger = log.New(io.Discard, "", 0)

var (
Expand Down Expand Up @@ -422,7 +424,17 @@ func main() {

logConfiguration()

http.Handle("/", promhttp.Handler())
http.Handle(
"/",
promhttp.InstrumentMetricHandler(
prometheus.DefaultRegisterer,
promhttp.HandlerFor(
prometheus.DefaultGatherer,
promhttp.HandlerOpts{ErrorLog: promLogger},
),
),
)

go func() {
logger.Printf("prometheus http server listening on %s", *listenAddr)
err := http.ListenAndServe(*listenAddr, nil)
Expand Down

0 comments on commit 4a78aae

Please sign in to comment.