Pprof listen (#639)
* add listen addr option * Add listen address option to pprof * There is configuration * code styling
This commit is contained in:
parent
4c9351b0a3
commit
f359aea2fa
4 changed files with 34 additions and 9 deletions
|
@ -11,14 +11,14 @@ For more information, please see [Go's pprof
|
|||
documentation](https://golang.org/pkg/net/http/pprof/) and read
|
||||
[Profiling Go Programs](https://blog.golang.org/profiling-go-programs).
|
||||
|
||||
There is not configuration.
|
||||
|
||||
## Syntax
|
||||
|
||||
~~~
|
||||
pprof
|
||||
pprof [ADDRESS]
|
||||
~~~
|
||||
|
||||
If not specified, ADDRESS defaults to localhost:6053.
|
||||
|
||||
## Examples
|
||||
|
||||
Enable pprof endpoints:
|
||||
|
@ -26,3 +26,15 @@ Enable pprof endpoints:
|
|||
~~~
|
||||
pprof
|
||||
~~~
|
||||
|
||||
Listen on an alternate address:
|
||||
|
||||
~~~
|
||||
pprof 10.9.8.7:6060
|
||||
~~~
|
||||
|
||||
Listen on an all addresses on port 6060:
|
||||
|
||||
~~~
|
||||
pprof :6060
|
||||
~~~
|
||||
|
|
|
@ -10,12 +10,13 @@ import (
|
|||
)
|
||||
|
||||
type handler struct {
|
||||
ln net.Listener
|
||||
mux *http.ServeMux
|
||||
addr string
|
||||
ln net.Listener
|
||||
mux *http.ServeMux
|
||||
}
|
||||
|
||||
func (h *handler) Startup() error {
|
||||
ln, err := net.Listen("tcp", addr)
|
||||
ln, err := net.Listen("tcp", h.addr)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed to start pprof handler: %s", err)
|
||||
return err
|
||||
|
@ -44,6 +45,5 @@ func (h *handler) Shutdown() error {
|
|||
}
|
||||
|
||||
const (
|
||||
addr = "localhost:6053"
|
||||
path = "/debug/pprof"
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package pprof
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/coredns/coredns/middleware"
|
||||
|
@ -8,6 +9,8 @@ import (
|
|||
"github.com/mholt/caddy"
|
||||
)
|
||||
|
||||
const defaultAddr = "localhost:6053"
|
||||
|
||||
func init() {
|
||||
caddy.RegisterPlugin("pprof", caddy.Plugin{
|
||||
ServerType: "dns",
|
||||
|
@ -17,11 +20,20 @@ func init() {
|
|||
|
||||
func setup(c *caddy.Controller) error {
|
||||
found := false
|
||||
h := &handler{addr: defaultAddr}
|
||||
for c.Next() {
|
||||
if found {
|
||||
return middleware.Error("pprof", c.Err("pprof can only be specified once"))
|
||||
}
|
||||
if len(c.RemainingArgs()) != 0 {
|
||||
args := c.RemainingArgs()
|
||||
if len(args) == 1 {
|
||||
h.addr = args[0]
|
||||
_, _, e := net.SplitHostPort(h.addr)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
if len(args) > 1 {
|
||||
return middleware.Error("pprof", c.ArgErr())
|
||||
}
|
||||
if c.NextBlock() {
|
||||
|
@ -30,7 +42,6 @@ func setup(c *caddy.Controller) error {
|
|||
found = true
|
||||
}
|
||||
|
||||
h := &handler{}
|
||||
pprofOnce.Do(func() {
|
||||
c.OnStartup(h.Startup)
|
||||
c.OnShutdown(h.Shutdown)
|
||||
|
|
|
@ -12,6 +12,8 @@ func TestPProf(t *testing.T) {
|
|||
shouldErr bool
|
||||
}{
|
||||
{`pprof`, false},
|
||||
{`pprof 1.2.3.4:1234`, false},
|
||||
{`pprof :1234`, false},
|
||||
{`pprof {}`, true},
|
||||
{`pprof /foo`, true},
|
||||
{`pprof {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue