mirror of
https://github.com/fatedier/frp.git
synced 2026-10-20 21:23:29 +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:
@@ -16,6 +16,7 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
@@ -82,10 +83,19 @@ func TestServiceMetricsServerLifecycle(t *testing.T) {
|
||||
assertLifecycleAdminPort(t, address, true)
|
||||
}()
|
||||
client := &http.Client{Timeout: 3 * time.Second}
|
||||
for path, status := range map[string]int{"/healthz": http.StatusOK, "/metrics": http.StatusNotFound} {
|
||||
resp, err := client.Get("http://" + address + path)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, status, resp.StatusCode)
|
||||
require.NoError(t, resp.Body.Close())
|
||||
}
|
||||
resp, err := client.Get("http://" + address + "/healthz")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
require.NoError(t, resp.Body.Close())
|
||||
|
||||
// frpc serves Go runtime metrics only, and no credentials are configured
|
||||
// here, so this endpoint is reachable without authentication.
|
||||
resp, err = client.Get("http://" + address + "/metrics")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, resp.Body.Close())
|
||||
require.Contains(t, string(body), "go_goroutines")
|
||||
require.NotContains(t, string(body), "frp_")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user