Browse code

add option to set host for profile endpoint

pweil- authored on 2016/09/29 02:00:40
Showing 4 changed files
... ...
@@ -512,7 +512,7 @@ OpenShift integrates the go `pprof` tooling to make it easy to capture CPU and h
512 512
   * `cpu` - will start a CPU profile on startup and write `./cpu.pprof`.  Contains samples for the entire run at the native sampling resolution (100hz). Note: CPU profiling for Go does not currently work on Mac OS X - the stats are not correctly sampled
513 513
   * `mem` - generate a running heap dump that tracks allocations to `./mem.pprof`
514 514
   * `block` -  will start a block wait time analysis and write `./block.pprof`
515
-  * `web` - start the pprof webserver in process at http://127.0.0.1:6060/debug/pprof (you can open this in a browser). This supports `OPENSHIFT_PROFILE_PORT=` to change default port `6060`.
515
+  * `web` - start the pprof webserver in process at http://127.0.0.1:6060/debug/pprof (you can open this in a browser). This supports `OPENSHIFT_PROFILE_HOST=` and `OPENSHIFT_PROFILE_PORT=` to change default ip `127.0.0.1` and default port `6060`.
516 516
 
517 517
 In order to start the server in CPU profiling mode, run:
518 518
 
... ...
@@ -59,9 +59,10 @@ func startProfiler() {
59 59
 	if cmdutil.Env("OPENSHIFT_PROFILE", "") == "web" {
60 60
 		go func() {
61 61
 			runtime.SetBlockProfileRate(1)
62
-			profile_port := cmdutil.Env("OPENSHIFT_PROFILE_PORT", "6060")
63
-			log.Infof(fmt.Sprintf("Starting profiling endpoint at http://127.0.0.1:%s/debug/pprof/", profile_port))
64
-			log.Fatal(http.ListenAndServe(fmt.Sprintf("127.0.0.1:%s", profile_port), nil))
62
+			profilePort := cmdutil.Env("OPENSHIFT_PROFILE_PORT", "6060")
63
+			profileHost := cmdutil.Env("OPENSHIFT_PROFILE_HOST", "127.0.0.1")
64
+			log.Infof(fmt.Sprintf("Starting profiling endpoint at http://%s:%s/debug/pprof/", profileHost, profilePort))
65
+			log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%s", profileHost, profilePort), nil))
65 66
 		}()
66 67
 	}
67 68
 }
... ...
@@ -48,9 +48,10 @@ func startProfiler() {
48 48
 	if cmdutil.Env("OPENSHIFT_PROFILE", "") == "web" {
49 49
 		go func() {
50 50
 			runtime.SetBlockProfileRate(1)
51
-			profile_port := cmdutil.Env("OPENSHIFT_PROFILE_PORT", "6060")
52
-			glog.Infof(fmt.Sprintf("Starting profiling endpoint at http://127.0.0.1:%s/debug/pprof/", profile_port))
53
-			glog.Fatal(http.ListenAndServe(fmt.Sprintf("127.0.0.1:%s", profile_port), nil))
51
+			profilePort := cmdutil.Env("OPENSHIFT_PROFILE_PORT", "6060")
52
+			profileHost := cmdutil.Env("OPENSHIFT_PROFILE_HOST", "127.0.0.1")
53
+			glog.Infof(fmt.Sprintf("Starting profiling endpoint at http://%s:%s/debug/pprof/", profileHost, profilePort))
54
+			glog.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%s", profileHost, profilePort), nil))
54 55
 		}()
55 56
 	}
56 57
 }
... ...
@@ -288,9 +288,10 @@ func startProfiler() {
288 288
 	if cmdutil.Env("OPENSHIFT_PROFILE", "") == "web" {
289 289
 		go func() {
290 290
 			runtime.SetBlockProfileRate(1)
291
-			profile_port := cmdutil.Env("OPENSHIFT_PROFILE_PORT", "6060")
292
-			glog.Infof(fmt.Sprintf("Starting profiling endpoint at http://127.0.0.1:%s/debug/pprof/", profile_port))
293
-			glog.Fatal(http.ListenAndServe(fmt.Sprintf("127.0.0.1:%s", profile_port), nil))
291
+			profilePort := cmdutil.Env("OPENSHIFT_PROFILE_PORT", "6060")
292
+			profileHost := cmdutil.Env("OPENSHIFT_PROFILE_HOST", "127.0.0.1")
293
+			glog.Infof(fmt.Sprintf("Starting profiling endpoint at http://%s:%s/debug/pprof/", profileHost, profilePort))
294
+			glog.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%s", profileHost, profilePort), nil))
294 295
 		}()
295 296
 	}
296 297
 }