Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
make profiling tunable
Browse files Browse the repository at this point in the history
  • Loading branch information
carmark committed Dec 4, 2015
1 parent f0ab29e commit c54f9d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"flag"
"fmt"
"net/http"
_ "net/http/pprof"
"net/http/pprof"
"os"
"os/signal"
"runtime"
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions docs/runtime_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c54f9d3

Please sign in to comment.