Debugger returns the DebugHandler registered on mux at /debug/, creating it if necessary.
(mux *http.ServeMux)
| 44 | // Debugger returns the DebugHandler registered on mux at /debug/, |
| 45 | // creating it if necessary. |
| 46 | func Debugger(mux *http.ServeMux) *DebugHandler { |
| 47 | h, pat := mux.Handler(&http.Request{URL: &url.URL{Path: "/debug/"}}) |
| 48 | if d, ok := h.(*DebugHandler); ok && pat == "/debug/" { |
| 49 | return d |
| 50 | } |
| 51 | ret := &DebugHandler{ |
| 52 | mux: mux, |
| 53 | title: fmt.Sprintf("%s debug", version.CmdName()), |
| 54 | } |
| 55 | mux.Handle("/debug/", ret) |
| 56 | |
| 57 | ret.KVFunc("Uptime", func() any { return varz.Uptime() }) |
| 58 | ret.KV("Version", version.Long()) |
| 59 | ret.Handle("vars", "Metrics (Go)", expvar.Handler()) |
| 60 | if PrometheusHandler.IsSet() { |
| 61 | PrometheusHandler.Get()(ret) |
| 62 | } else { |
| 63 | ret.Handle("varz", "Metrics (Prometheus)", http.HandlerFunc(varz.Handler)) |
| 64 | } |
| 65 | |
| 66 | addProfilingHandlers(ret) |
| 67 | ret.Handle("gc", "force GC", http.HandlerFunc(gcHandler)) |
| 68 | hostname, err := os.Hostname() |
| 69 | if err == nil { |
| 70 | ret.KV("Machine", hostname) |
| 71 | } |
| 72 | return ret |
| 73 | } |
| 74 | |
| 75 | // ServeHTTP implements http.Handler. |
| 76 | func (d *DebugHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
searching dependent graphs…