handleRuntime returns cheap runtime and process stats. Safe to hit on a running proxy; does not read pprof profiles.
(w http.ResponseWriter, _ *http.Request)
| 740 | // handleRuntime returns cheap runtime and process stats. Safe to hit on a |
| 741 | // running proxy; does not read pprof profiles. |
| 742 | func (h *Handler) handleRuntime(w http.ResponseWriter, _ *http.Request) { |
| 743 | var m runtime.MemStats |
| 744 | runtime.ReadMemStats(&m) |
| 745 | |
| 746 | clients := h.provider.ListClientsForDebug() |
| 747 | started := 0 |
| 748 | for _, c := range clients { |
| 749 | if c.HasClient { |
| 750 | started++ |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | resp := map[string]any{ |
| 755 | "uptime": time.Since(h.startTime).Round(time.Second).String(), |
| 756 | "goroutines": runtime.NumGoroutine(), |
| 757 | "num_cpu": runtime.NumCPU(), |
| 758 | "gomaxprocs": runtime.GOMAXPROCS(0), |
| 759 | "go_version": runtime.Version(), |
| 760 | "heap_alloc": m.HeapAlloc, |
| 761 | "heap_inuse": m.HeapInuse, |
| 762 | "heap_idle": m.HeapIdle, |
| 763 | "heap_released": m.HeapReleased, |
| 764 | "heap_sys": m.HeapSys, |
| 765 | "sys": m.Sys, |
| 766 | "live_objects": m.Mallocs - m.Frees, |
| 767 | "num_gc": m.NumGC, |
| 768 | "pause_total_ns": m.PauseTotalNs, |
| 769 | "clients": len(clients), |
| 770 | "started": started, |
| 771 | } |
| 772 | |
| 773 | if proc := readProcStatus(); proc != nil { |
| 774 | resp["vm_rss"] = proc["VmRSS"] |
| 775 | resp["vm_size"] = proc["VmSize"] |
| 776 | resp["vm_data"] = proc["VmData"] |
| 777 | } |
| 778 | |
| 779 | h.writeJSON(w, resp) |
| 780 | } |
| 781 | |
| 782 | // readProcStatus parses /proc/self/status on Linux and returns size fields |
| 783 | // in bytes. Returns nil on non-Linux or read failure. |
no test coverage detected