Use promhttp and setup logger

This commit is contained in:
Johannes 'fish' Ziemke 2017-01-05 19:30:48 +01:00
commit 3983cd58ff
3 changed files with 212 additions and 5 deletions

View file

@ -25,6 +25,7 @@ import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"
"github.com/prometheus/node_exporter/collector"
@ -157,12 +158,11 @@ func main() {
log.Infof(" - %s", n)
}
nodeCollector := NodeCollector{collectors: collectors}
prometheus.MustRegister(nodeCollector)
prometheus.MustRegister(NodeCollector{collectors: collectors})
handler := promhttp.HandlerFor(prometheus.DefaultGatherer,
promhttp.HandlerOpts{ErrorLog: log.NewErrorLogger()})
handler := prometheus.Handler()
http.Handle(*metricsPath, handler)
http.Handle(*metricsPath, prometheus.InstrumentHandler("prometheus", handler))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Node Exporter</title></head>