diff --git a/ipn/ipnlocal/peerapi.go b/ipn/ipnlocal/peerapi.go index 4ccf231ec..c7641122b 100644 --- a/ipn/ipnlocal/peerapi.go +++ b/ipn/ipnlocal/peerapi.go @@ -36,6 +36,7 @@ "tailscale.com/net/interfaces" "tailscale.com/syncs" "tailscale.com/tailcfg" + "tailscale.com/util/clientmetric" "tailscale.com/wgengine" ) @@ -502,13 +503,16 @@ func (h *peerAPIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.handlePeerPut(w, r) return } - if r.URL.Path == "/v0/goroutines" { + switch r.URL.Path { + case "/v0/goroutines": h.handleServeGoroutines(w, r) return - } - if r.URL.Path == "/v0/env" { + case "/v0/env": h.handleServeEnv(w, r) return + case "/v0/metrics": + h.handleServeMetrics(w, r) + return } who := h.peerUser.DisplayName fmt.Fprintf(w, ` @@ -736,3 +740,12 @@ func (h *peerAPIHandler) handleServeEnv(w http.ResponseWriter, r *http.Request) w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(data) } + +func (h *peerAPIHandler) handleServeMetrics(w http.ResponseWriter, r *http.Request) { + if !h.isSelf { + http.Error(w, "not owner", http.StatusForbidden) + return + } + w.Header().Set("Content-Type", "text/plain") + clientmetric.WritePrometheusExpositionFormat(w) +}