pprof middleware (#138)
Add pprof middleware, enabled by pprof directive.
This commit is contained in:
parent
7a8d943bcc
commit
2700eece2e
8 changed files with 130 additions and 4 deletions
32
middleware/pprof/pprof.go
Normal file
32
middleware/pprof/pprof.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package pprof
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
const addr = "localhost:8053"
|
||||
|
||||
type Handler struct {
|
||||
Next middleware.Handler
|
||||
}
|
||||
|
||||
// ServeDNS passes all other requests up the chain.
|
||||
func (h *Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
return h.Next.ServeDNS(ctx, w, r)
|
||||
}
|
||||
|
||||
func (h *Handler) Start() error {
|
||||
go func() {
|
||||
if err := http.ListenAndServe(addr, nil); err != nil {
|
||||
log.Printf("[ERROR] Failed to start pprof handler: %s", err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue