github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/server/metrics_server.go (about)

     1  // Copyright 2020 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package server
    15  
    16  import (
    17  	"os"
    18  	"runtime"
    19  	"strconv"
    20  
    21  	"github.com/prometheus/client_golang/prometheus"
    22  )
    23  
    24  var (
    25  	etcdHealthCheckDuration = prometheus.NewHistogramVec(
    26  		prometheus.HistogramOpts{
    27  			Namespace: "ticdc",
    28  			Subsystem: "server",
    29  			Name:      "etcd_health_check_duration",
    30  			Help:      "Bucketed histogram of processing time (s) of flushing events in processor",
    31  			Buckets:   prometheus.ExponentialBuckets(0.0001 /* 0.1ms */, 2, 18),
    32  		}, []string{"pd"})
    33  
    34  	goGC = prometheus.NewGauge(
    35  		prometheus.GaugeOpts{
    36  			Namespace: "ticdc",
    37  			Subsystem: "server",
    38  			Name:      "go_gc",
    39  			Help:      "The value of GOGC",
    40  		})
    41  
    42  	goMaxProcs = prometheus.NewGauge(
    43  		prometheus.GaugeOpts{
    44  			Namespace: "ticdc",
    45  			Subsystem: "server",
    46  			Name:      "go_max_procs",
    47  			Help:      "The value of GOMAXPROCS",
    48  		})
    49  )
    50  
    51  // RecordGoRuntimeSettings records GOGC settings.
    52  func RecordGoRuntimeSettings() {
    53  	// The default GOGC value is 100. See debug.SetGCPercent.
    54  	gogcValue := 100
    55  	if val, err := strconv.Atoi(os.Getenv("GOGC")); err == nil {
    56  		gogcValue = val
    57  	}
    58  	goGC.Set(float64(gogcValue))
    59  
    60  	maxProcs := runtime.GOMAXPROCS(0)
    61  	goMaxProcs.Set(float64(maxProcs))
    62  }
    63  
    64  // initServerMetrics registers all metrics used in processor
    65  func initServerMetrics(registry *prometheus.Registry) {
    66  	registry.MustRegister(etcdHealthCheckDuration)
    67  	registry.MustRegister(goGC)
    68  	registry.MustRegister(goMaxProcs)
    69  }