You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The advantages of using `rdb` over the existing `/net/http/pprof`handlers are:
5
+
Package `netbug` provides access to an `http.Handler` that accesses the profiling and debug tools available in the `/net/http/pprof`and `/runtime/pprof` packages.
6
6
7
-
1. You can register the handler under an arbitrary route-prefix. A use-case might be to have a secret endpoint for keeping this information hidden from prying eyes on production boxes;
8
-
2. It pulls together all the handlers from `/net/http/pprof` and `/runtime/pprof` into a single index page, for when you can't quite remember the URL for the profile you want; and
9
-
3. You can register the handlers onto `http.ServeMux`'s that aren't `http.DefaultServeMux`.
7
+
The advantages of using `netbug` over the existing `/net/http/pprof` handlers are:
8
+
9
+
1. You can register the handler under an arbitrary route-prefix. A use-case might be to have a secret endpoint for keeping this information hidden from prying eyes, rather than `/debug/pprof`;
10
+
2. It pulls together all the handlers from `/net/http/pprof`*and*`/runtime/pprof` into a single index page, for when you can't quite remember the URL for the profile you want;
11
+
3. You can register the handlers onto `http.ServeMux`'s that aren't `http.DefaultServeMux`;
12
+
4. It provides an optional handler that requires a token URL parameter. This is useful if you want that little bit of extra security (use this over HTTPS connections only).
10
13
11
14
**Note**:
12
-
It still imports `/net/http/pprof`, which means the `/debug/pprof` routes in that package get registered on `http.DefaultServeMux`. If you're using this package to avoid those routes being registered, you should use it with your own `http.ServeMux`.
15
+
It still imports `/net/http/pprof`, which means the `/debug/pprof` routes in that package *still* get registered on `http.DefaultServeMux`.
16
+
If you're using this package to avoid those routes being registered, you should use it with your *own*`http.ServeMux`.
13
17
14
-
`rdb` is trying to cater for the situation where you want all profiling tools available remotely on your running services, but you don't want to expose the `/debug/pprof` routes that `net/http/pprof` forces you to expose.
18
+
`netbug` is trying to cater for the situation where you want all profiling tools available remotely on your running services, but you don't want to expose the `/debug/pprof` routes that `net/http/pprof` forces you to expose.
15
19
16
20
## How do I use it?
17
-
All you have to do is give `rdb` the `http.ServeMux` you want to register the handlers on, and you're away.
21
+
In the simplest case give `netbug` the `http.ServeMux` you want to register the handlers on, as well as where you want to register the handler and you're away.
**Obviously** this form of authentication is pointless if you're not accessing the routes over an HTTPS connection.
70
+
If you want to use a different form of authentication, e.g., HTTP Basic Authentication, then you can use the handler returned by `netbug.Handler()`, and wrap it with handlers provided by packages like [github.com/abbot/go-http-auth](https://github.com/abbot/go-http-auth/).
41
71
42
72
### What can you do with it?
43
73
44
-
It just wraps the behaviour of the `/net/http/pprof` and `/runtime/pprof` packages.
74
+
It just wraps the behaviour of the [/net/http/pprof](http://golang.org/pkg/net/http/pprof/) and [/runtime/pprof](http://golang.org/pkg/runtime/pprof/) packages.
45
75
Check out their documentation to see what's available.
46
76
As an example though, if you want to run a 30-second CPU profile on your running service it's really simple:
47
77
48
78
```
49
-
$ go tool pprof https://example.com/some-hidden-prefix/debug/pprof/profile
79
+
$ go tool pprof https://example.com/myroute/profile
50
80
```
51
81
52
82
## Background
@@ -58,9 +88,11 @@ However, there are a couple of problems with the `net/http/pprof` package.
58
88
59
89
1. It assumes you're cool about the relevant handlers being registered under the `/debug/pprof` route.
60
90
2. It assumes you're cool about handlers being registered on `http.DefaultServeMux`.
91
+
3. You can't wrap the handlers in any way, say to add authentication or other logic.
61
92
62
-
You can sort of fix (1) and (2) by digging around the `net/http/pprof` package and registering all all the exported handlers under different paths on your own `http.ServeMux`, but you still have the problem of the index page—which is useful to visit if you don't profile much—using hard-coded paths. It doesn't quite work well.
63
-
Also, the index page doesn't provide you with easy links to the debug information that the `net/http/pprof` has handlers for.
93
+
You can sort of fix (1) and (2) by digging around the `net/http/pprof` package and registering all all the exported handlers under different paths on your own `http.ServeMux`, but you still have the problem of the index page—which is useful to visit if you don't profile much—using hard-coded paths.
94
+
It doesn't really work well.
95
+
Also, the index page doesn't provide you with easy links to the debug information that the `net/http/pprof` package has handlers for.
64
96
65
-
So, `rdb` is just a simple package to fix (1) and (2).
97
+
`netdebug` is just a small package to fix these issues.
0 commit comments