Continue scrape with duplicated metrics

Problems of a single collector, like duplicated metrics read via the
textfile collector, should not fail the collection and export of other
metrics.
This commit is contained in:
Tobias Schmidt 2017-03-13 23:55:19 -03:00
commit dace41e3d4
2 changed files with 93 additions and 49 deletions

View file

@ -158,10 +158,16 @@ func main() {
log.Infof(" - %s", n)
}
prometheus.MustRegister(NodeCollector{collectors: collectors})
if err := prometheus.Register(NodeCollector{collectors: collectors}); err != nil {
log.Fatalf("Couldn't register collector: %s", err)
}
handler := promhttp.HandlerFor(prometheus.DefaultGatherer,
promhttp.HandlerOpts{ErrorLog: log.NewErrorLogger()})
promhttp.HandlerOpts{
ErrorLog: log.NewErrorLogger(),
ErrorHandling: promhttp.ContinueOnError,
})
// TODO(ts): Remove deprecated and problematic InstrumentHandler usage.
http.Handle(*metricsPath, prometheus.InstrumentHandler("prometheus", handler))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>