mirror of
https://github.com/fatedier/frp.git
synced 2026-10-21 07:13:27 +08:00
feat(client): serve Go runtime metrics on metricsServer (#5579)
Add pkg/metrics/text, a small Prometheus text-format writer, and use it for frpc's /metrics. The endpoint lives only on metricsServer and is covered by its Basic Auth, like the other endpoints there. The package emits the Go runtime families and, on Linux, the process families read from /proc. Their names, types and help strings match client_golang's default collectors, so existing Go runtime dashboards keep working. It deliberately emits no frp_ business metrics and none of client_golang's promhttp_ handler metrics. Writing the subset ourselves keeps client_golang and protobuf out of the frpc binary; both are still used by frps and by the tests here.
This commit is contained in:
@@ -47,6 +47,21 @@ var _ = ginkgo.Describe("[Feature: Metrics Server]", func() {
|
||||
}, 5*time.Second, 50*time.Millisecond).Should(gomega.BeTrue())
|
||||
}
|
||||
|
||||
// frpc serves Go runtime metrics only; no process, business or handler
|
||||
// instrumentation metrics may appear there, on any platform.
|
||||
expectRuntimeMetrics := func(port int) {
|
||||
framework.NewRequestExpect(f).Request(metricsRequest(port, "/metrics", false)).
|
||||
Ensure(framework.ExpectResponseCode(http.StatusUnauthorized))
|
||||
framework.NewRequestExpect(f).Request(metricsRequest(port, "/metrics", true)).Ensure(func(resp *request.Response) bool {
|
||||
body := string(resp.Content)
|
||||
return resp.Code == http.StatusOK &&
|
||||
strings.Contains(body, "go_goroutines") &&
|
||||
!strings.Contains(body, "process_") &&
|
||||
!strings.Contains(body, "frp_") &&
|
||||
!strings.Contains(body, "promhttp_")
|
||||
})
|
||||
}
|
||||
|
||||
ginkgo.It("serves anonymous health alongside both web servers", func() {
|
||||
serverMetrics, clientMetrics := f.AllocPort(), f.AllocPort()
|
||||
serverWeb, clientWeb := f.AllocPort(), f.AllocPort()
|
||||
@@ -102,7 +117,7 @@ webServer.password = "admin-secret"
|
||||
framework.NewRequestExpect(f).Request(metricsRequest(port, "/healthz", false)).Ensure(framework.ExpectResponseCode(http.StatusOK))
|
||||
}
|
||||
expectBusinessMetrics(serverPort)
|
||||
framework.NewRequestExpect(f).Request(metricsRequest(clientPort, "/metrics", true)).Ensure(framework.ExpectResponseCode(http.StatusNotFound))
|
||||
expectRuntimeMetrics(clientPort)
|
||||
})
|
||||
|
||||
ginkgo.It("collects once when both metrics endpoints are enabled", func() {
|
||||
|
||||
Reference in New Issue
Block a user