ipn/ipnlocal: export client metrics over peerapi to owner

Updates #3307

Change-Id: I41b1f3c16af5f385575e8d6cea70ae8386504dd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/3344/head
Brad Fitzpatrick 3 years ago committed by Brad Fitzpatrick
parent d24ed3f68e
commit 4a59a2781a

@ -36,6 +36,7 @@ import (
"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, `<html>
@ -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)
}

Loading…
Cancel
Save