make profiling tunable

This commit is contained in:
Lei Xue 2015-12-04 18:35:05 +08:00
parent f0ab29e1fa
commit c54f9d3758
2 changed files with 13 additions and 3 deletions

View File

@ -18,7 +18,7 @@ import (
"flag"
"fmt"
"net/http"
_ "net/http/pprof"
"net/http/pprof"
"os"
"os/signal"
"runtime"
@ -50,6 +50,8 @@ var prometheusEndpoint = flag.String("prometheus_endpoint", "/metrics", "Endpoin
var maxHousekeepingInterval = flag.Duration("max_housekeeping_interval", 60*time.Second, "Largest interval to allow between container housekeepings")
var allowDynamicHousekeeping = flag.Bool("allow_dynamic_housekeeping", true, "Whether to allow the housekeeping interval to be dynamic")
var enableProfiling = flag.Bool("profiling", false, "Enable profiling via web interface host:port/debug/pprof/")
func main() {
defer glog.Flush()
flag.Parse()
@ -76,7 +78,14 @@ func main() {
glog.Fatalf("Failed to create a Container Manager: %s", err)
}
mux := http.DefaultServeMux
mux := http.NewServeMux()
if *enableProfiling {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
}
// Register all HTTP handlers.
err = cadvisorhttp.RegisterHandlers(mux, containerManager, *httpAuthFile, *httpAuthRealm, *httpDigestFile, *httpDigestRealm)
@ -97,7 +106,7 @@ func main() {
glog.Infof("Starting cAdvisor version: %s-%s on port %d", version.Info["version"], version.Info["revision"], *argPort)
addr := fmt.Sprintf("%s:%d", *argIp, *argPort)
glog.Fatal(http.ListenAndServe(addr, nil))
glog.Fatal(http.ListenAndServe(addr, mux))
}
func setMaxProcs() {

View File

@ -62,6 +62,7 @@ cAdvisor-native flags that help in debugging:
```
--log_cadvisor_usage=false: Whether to log the usage of the cAdvisor container
--version=false: print cAdvisor version and exit
--profiling=false: Enable profiling via web interface host:port/debug/pprof/
```
From [glog](https://github.com/golang/glog) here are some flags we find useful: