diff --git a/pkg/mcs/scheduling/server/metrics.go b/pkg/basicserver/metrics.go similarity index 57% rename from pkg/mcs/scheduling/server/metrics.go rename to pkg/basicserver/metrics.go index b3f5b7b41de..8f26216d696 100644 --- a/pkg/mcs/scheduling/server/metrics.go +++ b/pkg/basicserver/metrics.go @@ -16,22 +16,27 @@ package server import "github.com/prometheus/client_golang/prometheus" -const ( - namespace = "scheduling" - serverSubsystem = "server" -) - var ( - // Meta & Server info. - serverInfo = prometheus.NewGaugeVec( + // ServerMaxProcsGauge record the maxprocs. + ServerMaxProcsGauge = prometheus.NewGauge( + prometheus.GaugeOpts{ + Namespace: "pd", + Subsystem: "service", + Name: "maxprocs", + Help: "The value of GOMAXPROCS.", + }) + + // ServerInfoGauge indicates the pd server info including version and git hash. + ServerInfoGauge = prometheus.NewGaugeVec( prometheus.GaugeOpts{ - Namespace: namespace, - Subsystem: serverSubsystem, + Namespace: "pd", + Subsystem: "server", Name: "info", - Help: "Indicate the scheduling server info, and the value is the start timestamp (s).", + Help: "Indicate the pd server info, and the value is the start timestamp (s).", }, []string{"version", "hash"}) ) func init() { - prometheus.MustRegister(serverInfo) + prometheus.MustRegister(ServerMaxProcsGauge) + prometheus.MustRegister(ServerInfoGauge) } diff --git a/pkg/mcs/resourcemanager/server/metrics.go b/pkg/mcs/resourcemanager/server/metrics.go index 4322ed1a640..6bb90c45d12 100644 --- a/pkg/mcs/resourcemanager/server/metrics.go +++ b/pkg/mcs/resourcemanager/server/metrics.go @@ -32,14 +32,6 @@ const ( ) var ( - // Meta & Server info. - serverInfo = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: namespace, - Subsystem: serverSubsystem, - Name: "info", - Help: "Indicate the resource manager server info, and the value is the start timestamp (s).", - }, []string{"version", "hash"}) // RU cost metrics. // `sum` is added to the name to maintain compatibility with the previous use of histogram. readRequestUnitCost = prometheus.NewCounterVec( @@ -111,7 +103,6 @@ var ( ) func init() { - prometheus.MustRegister(serverInfo) prometheus.MustRegister(readRequestUnitCost) prometheus.MustRegister(writeRequestUnitCost) prometheus.MustRegister(sqlLayerRequestUnitCost) diff --git a/pkg/mcs/resourcemanager/server/server.go b/pkg/mcs/resourcemanager/server/server.go index 43d426bfc40..2d02fd00434 100644 --- a/pkg/mcs/resourcemanager/server/server.go +++ b/pkg/mcs/resourcemanager/server/server.go @@ -19,6 +19,7 @@ import ( "net/http" "os" "os/signal" + "runtime" "strconv" "sync" "sync/atomic" @@ -294,7 +295,8 @@ func (s *Server) startServer() (err error) { log.Info("init cluster id", zap.Uint64("cluster-id", s.clusterID)) // The independent Resource Manager service still reuses PD version info since PD and Resource Manager are just // different service modes provided by the same pd-server binary - serverInfo.WithLabelValues(versioninfo.PDReleaseVersion, versioninfo.PDGitHash).Set(float64(time.Now().Unix())) + bs.ServerInfoGauge.WithLabelValues(versioninfo.PDReleaseVersion, versioninfo.PDGitHash).Set(float64(time.Now().Unix())) + bs.ServerMaxProcsGauge.Set(float64(runtime.GOMAXPROCS(0))) uniqueName := s.cfg.GetAdvertiseListenAddr() uniqueID := memberutil.GenerateUniqueID(uniqueName) diff --git a/pkg/mcs/scheduling/server/server.go b/pkg/mcs/scheduling/server/server.go index 8ee8b81ae47..8013f1d0e7b 100644 --- a/pkg/mcs/scheduling/server/server.go +++ b/pkg/mcs/scheduling/server/server.go @@ -20,6 +20,7 @@ import ( "net/http" "os" "os/signal" + "runtime" "strconv" "sync" "sync/atomic" @@ -409,8 +410,8 @@ func (s *Server) startServer() (err error) { log.Info("init cluster id", zap.Uint64("cluster-id", s.clusterID)) // The independent Scheduling service still reuses PD version info since PD and Scheduling are just // different service modes provided by the same pd-server binary - serverInfo.WithLabelValues(versioninfo.PDReleaseVersion, versioninfo.PDGitHash).Set(float64(time.Now().Unix())) - + bs.ServerInfoGauge.WithLabelValues(versioninfo.PDReleaseVersion, versioninfo.PDGitHash).Set(float64(time.Now().Unix())) + bs.ServerMaxProcsGauge.Set(float64(runtime.GOMAXPROCS(0))) s.serviceID = &discovery.ServiceRegistryEntry{ServiceAddr: s.cfg.AdvertiseListenAddr} uniqueName := s.cfg.GetAdvertiseListenAddr() uniqueID := memberutil.GenerateUniqueID(uniqueName) diff --git a/pkg/mcs/tso/server/metrics.go b/pkg/mcs/tso/server/metrics.go index 288d650e1e7..4845fbc39a2 100644 --- a/pkg/mcs/tso/server/metrics.go +++ b/pkg/mcs/tso/server/metrics.go @@ -35,14 +35,6 @@ var ( Help: "Record critical metadata.", }, []string{"type"}) - serverInfo = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: namespace, - Subsystem: "server", - Name: "info", - Help: "Indicate the tso server info, and the value is the start timestamp (s).", - }, []string{"version", "hash"}) - tsoHandleDuration = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Namespace: namespace, @@ -56,6 +48,5 @@ var ( func init() { prometheus.MustRegister(timeJumpBackCounter) prometheus.MustRegister(metaDataGauge) - prometheus.MustRegister(serverInfo) prometheus.MustRegister(tsoHandleDuration) } diff --git a/pkg/mcs/tso/server/server.go b/pkg/mcs/tso/server/server.go index 1a2430477d8..55473efc8bb 100644 --- a/pkg/mcs/tso/server/server.go +++ b/pkg/mcs/tso/server/server.go @@ -20,6 +20,7 @@ import ( "net/http" "os" "os/signal" + "runtime" "strconv" "sync" "sync/atomic" @@ -359,7 +360,8 @@ func (s *Server) startServer() (err error) { metaDataGauge.WithLabelValues(fmt.Sprintf("cluster%d", s.clusterID)).Set(0) // The independent TSO service still reuses PD version info since PD and TSO are just // different service modes provided by the same pd-server binary - serverInfo.WithLabelValues(versioninfo.PDReleaseVersion, versioninfo.PDGitHash).Set(float64(time.Now().Unix())) + bs.ServerInfoGauge.WithLabelValues(versioninfo.PDReleaseVersion, versioninfo.PDGitHash).Set(float64(time.Now().Unix())) + bs.ServerMaxProcsGauge.Set(float64(runtime.GOMAXPROCS(0))) // Initialize the TSO service. s.serverLoopCtx, s.serverLoopCancel = context.WithCancel(s.Context()) diff --git a/server/metrics.go b/server/metrics.go index 54c5830dc52..e06a0cc20dd 100644 --- a/server/metrics.go +++ b/server/metrics.go @@ -136,14 +136,6 @@ var ( Buckets: prometheus.ExponentialBuckets(0.0001, 2, 29), // 0.1ms ~ 7hours }, []string{"address", "store"}) - serverInfo = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: "pd", - Subsystem: "server", - Name: "info", - Help: "Indicate the pd server info, and the value is the start timestamp (s).", - }, []string{"version", "hash"}) - serviceAuditHistogram = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Namespace: "pd", @@ -152,13 +144,6 @@ var ( Help: "PD server service handling audit", Buckets: prometheus.DefBuckets, }, []string{"service", "method", "caller_id", "ip"}) - serverMaxProcs = prometheus.NewGauge( - prometheus.GaugeOpts{ - Namespace: "pd", - Subsystem: "service", - Name: "maxprocs", - Help: "The value of GOMAXPROCS.", - }) forwardFailCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ @@ -181,11 +166,9 @@ func init() { prometheus.MustRegister(tsoHandleDuration) prometheus.MustRegister(regionHeartbeatHandleDuration) prometheus.MustRegister(storeHeartbeatHandleDuration) - prometheus.MustRegister(serverInfo) prometheus.MustRegister(bucketReportCounter) prometheus.MustRegister(bucketReportLatency) prometheus.MustRegister(serviceAuditHistogram) prometheus.MustRegister(bucketReportInterval) - prometheus.MustRegister(serverMaxProcs) prometheus.MustRegister(forwardFailCounter) } diff --git a/server/server.go b/server/server.go index fcf71922a09..21ab983b3d1 100644 --- a/server/server.go +++ b/server/server.go @@ -43,6 +43,7 @@ import ( "github.com/pingcap/log" "github.com/pingcap/sysutil" "github.com/tikv/pd/pkg/audit" + bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/encryption" "github.com/tikv/pd/pkg/errs" @@ -428,7 +429,7 @@ func (s *Server) startServer(ctx context.Context) error { log.Info("init cluster id", zap.Uint64("cluster-id", s.clusterID)) // It may lose accuracy if use float64 to store uint64. So we store the cluster id in label. metadataGauge.WithLabelValues(fmt.Sprintf("cluster%d", s.clusterID)).Set(0) - serverInfo.WithLabelValues(versioninfo.PDReleaseVersion, versioninfo.PDGitHash).Set(float64(time.Now().Unix())) + bs.ServerInfoGauge.WithLabelValues(versioninfo.PDReleaseVersion, versioninfo.PDGitHash).Set(float64(time.Now().Unix())) s.rootPath = endpoint.PDRootPath(s.clusterID) s.member.InitMemberInfo(s.cfg.AdvertiseClientUrls, s.cfg.AdvertisePeerUrls, s.Name(), s.rootPath) @@ -504,7 +505,7 @@ func (s *Server) startServer(ctx context.Context) error { // Server has started. atomic.StoreInt64(&s.isRunning, 1) - serverMaxProcs.Set(float64(runtime.GOMAXPROCS(0))) + bs.ServerMaxProcsGauge.Set(float64(runtime.GOMAXPROCS(0))) return nil } diff --git a/tests/integrations/mcs/resourcemanager/server_test.go b/tests/integrations/mcs/resourcemanager/server_test.go index d3837ad15f3..4e1fb018d56 100644 --- a/tests/integrations/mcs/resourcemanager/server_test.go +++ b/tests/integrations/mcs/resourcemanager/server_test.go @@ -101,7 +101,7 @@ func TestResourceManagerServer(t *testing.T) { re.Equal(http.StatusOK, resp.StatusCode) respBytes, err := io.ReadAll(resp.Body) re.NoError(err) - re.Contains(string(respBytes), "resource_manager_server_info") + re.Contains(string(respBytes), "pd_server_info") } // Test status handler diff --git a/tests/integrations/mcs/scheduling/api_test.go b/tests/integrations/mcs/scheduling/api_test.go index 177f959b953..2572ae459d5 100644 --- a/tests/integrations/mcs/scheduling/api_test.go +++ b/tests/integrations/mcs/scheduling/api_test.go @@ -566,7 +566,7 @@ func (suite *apiTestSuite) checkMetrics(cluster *tests.TestCluster) { re.Equal(http.StatusOK, resp.StatusCode) respBytes, err := io.ReadAll(resp.Body) re.NoError(err) - re.Contains(string(respBytes), "scheduling_server_info") + re.Contains(string(respBytes), "pd_server_info") } func (suite *apiTestSuite) TestStatus() { diff --git a/tests/integrations/mcs/tso/api_test.go b/tests/integrations/mcs/tso/api_test.go index a5d68cfa90f..b72da5ab7f6 100644 --- a/tests/integrations/mcs/tso/api_test.go +++ b/tests/integrations/mcs/tso/api_test.go @@ -256,7 +256,7 @@ func (suite *tsoAPITestSuite) TestMetrics() { re.Equal(http.StatusOK, resp.StatusCode) respBytes, err := io.ReadAll(resp.Body) re.NoError(err) - re.Contains(string(respBytes), "tso_server_info") + re.Contains(string(respBytes), "pd_server_info") } func (suite *tsoAPITestSuite) TestStatus() {