aboutsummaryrefslogtreecommitdiff
path: root/middleware/pprof/pprof.go
diff options
context:
space:
mode:
Diffstat (limited to 'middleware/pprof/pprof.go')
-rw-r--r--middleware/pprof/pprof.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/middleware/pprof/pprof.go b/middleware/pprof/pprof.go
new file mode 100644
index 000000000..677690ff8
--- /dev/null
+++ b/middleware/pprof/pprof.go
@@ -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
+}