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:
+10
-1
@@ -34,6 +34,7 @@ import (
|
||||
"github.com/fatedier/frp/pkg/config/source"
|
||||
v1 "github.com/fatedier/frp/pkg/config/v1"
|
||||
"github.com/fatedier/frp/pkg/config/v1/validation"
|
||||
"github.com/fatedier/frp/pkg/metrics/text"
|
||||
"github.com/fatedier/frp/pkg/msg"
|
||||
"github.com/fatedier/frp/pkg/policy/security"
|
||||
httppkg "github.com/fatedier/frp/pkg/util/http"
|
||||
@@ -199,7 +200,15 @@ func NewService(options ServiceOptions) (*Service, error) {
|
||||
}
|
||||
webServer = ws
|
||||
}
|
||||
metricsServer, err := httppkg.NewMetricsServer(options.Common.MetricsServer, nil)
|
||||
// frpc exposes Go runtime metrics only. They are written by pkg/metrics/text
|
||||
// so that client_golang and protobuf stay out of the frpc binary.
|
||||
var metricsHandler http.Handler
|
||||
if options.Common.MetricsServer.Port > 0 {
|
||||
registry := text.NewRegistry()
|
||||
registry.RegisterRuntime()
|
||||
metricsHandler = registry.Handler()
|
||||
}
|
||||
metricsServer, err := httppkg.NewMetricsServer(options.Common.MetricsServer, metricsHandler)
|
||||
if err != nil {
|
||||
if webServer != nil {
|
||||
_ = webServer.Close()
|
||||
|
||||
Reference in New Issue
Block a user