mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-28 23:19:46 -08:00
Merge pull request #53 from prometheus/web-pprof
Remove memprofile file, add pprof HTTP endpoint instead.
This commit is contained in:
commit
30cf7f8c73
|
@ -6,9 +6,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime/pprof"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -171,37 +171,19 @@ func main() {
|
||||||
password: *authPass,
|
password: *authPass,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
go func() {
|
|
||||||
http.Handle(*metricsPath, handler)
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Write([]byte(`<html>
|
|
||||||
<head><title>Node Exporter</title></head>
|
|
||||||
<body>
|
|
||||||
<h1>Node Exporter</h1>
|
|
||||||
<p><a href="` + *metricsPath + `">Metrics</a></p>
|
|
||||||
</body>
|
|
||||||
</html>`))
|
|
||||||
})
|
|
||||||
err := http.ListenAndServe(*listenAddress, nil)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
for {
|
http.Handle(*metricsPath, handler)
|
||||||
select {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
case <-sigUsr1:
|
w.Write([]byte(`<html>
|
||||||
glog.Infof("got signal")
|
<head><title>Node Exporter</title></head>
|
||||||
if *memProfile != "" {
|
<body>
|
||||||
glog.Infof("Writing memory profile to %s", *memProfile)
|
<h1>Node Exporter</h1>
|
||||||
f, err := os.Create(*memProfile)
|
<p><a href="` + *metricsPath + `">Metrics</a></p>
|
||||||
if err != nil {
|
</body>
|
||||||
glog.Fatal(err)
|
</html>`))
|
||||||
}
|
})
|
||||||
pprof.WriteHeapProfile(f)
|
err = http.ListenAndServe(*listenAddress, nil)
|
||||||
f.Close()
|
if err != nil {
|
||||||
}
|
glog.Fatal(err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue