mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 03:38:43 +00:00
chore: Optimize go runtime metrics (#7081)
* optimize go runtime metrics --------- Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
This commit is contained in:
parent
7b8010bea2
commit
408e8ebd6e
4 changed files with 50 additions and 32 deletions
cmd
internal/metrics
|
@ -23,14 +23,12 @@ import (
|
|||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors/version"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/prometheus-operator/prometheus-operator/internal/goruntime"
|
||||
logging "github.com/prometheus-operator/prometheus-operator/internal/log"
|
||||
"github.com/prometheus-operator/prometheus-operator/internal/metrics"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/admission"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/server"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/versionutil"
|
||||
|
@ -75,12 +73,8 @@ func main() {
|
|||
admit := admission.New(logger.With("component", "admissionwebhook"))
|
||||
admit.Register(mux)
|
||||
|
||||
r := prometheus.NewRegistry()
|
||||
r.MustRegister(
|
||||
collectors.NewGoCollector(),
|
||||
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
||||
version.NewCollector("prometheus_operator_admission_webhook"),
|
||||
)
|
||||
r := metrics.NewRegistry("prometheus_operator_admission_webhook")
|
||||
|
||||
mux.Handle("/metrics", promhttp.HandlerFor(r, promhttp.HandlerOpts{}))
|
||||
|
||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
|
||||
|
|
|
@ -24,14 +24,10 @@ import (
|
|||
"net/http/pprof"
|
||||
"os"
|
||||
"os/signal"
|
||||
"regexp"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/blang/semver/v4"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/prometheus/common/version"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
@ -48,6 +44,7 @@ import (
|
|||
|
||||
"github.com/prometheus-operator/prometheus-operator/internal/goruntime"
|
||||
logging "github.com/prometheus-operator/prometheus-operator/internal/log"
|
||||
"github.com/prometheus-operator/prometheus-operator/internal/metrics"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/admission"
|
||||
alertmanagercontroller "github.com/prometheus-operator/prometheus-operator/pkg/alertmanager"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring"
|
||||
|
@ -231,7 +228,7 @@ func run(fs *flag.FlagSet) int {
|
|||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
wg, ctx := errgroup.WithContext(ctx)
|
||||
r := prometheus.NewRegistry()
|
||||
r := metrics.NewRegistry("prometheus_operator")
|
||||
|
||||
k8sutil.MustRegisterClientGoMetrics(r)
|
||||
|
||||
|
@ -598,17 +595,7 @@ func run(fs *flag.FlagSet) int {
|
|||
admit := admission.New(logger.With("component", "admissionwebhook"))
|
||||
admit.Register(mux)
|
||||
|
||||
r.MustRegister(
|
||||
collectors.NewGoCollector(
|
||||
collectors.WithGoCollectorRuntimeMetrics(
|
||||
collectors.MetricsScheduler,
|
||||
collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile(`^/sync/.*`)},
|
||||
),
|
||||
),
|
||||
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
||||
versioncollector.NewCollector("prometheus_operator"),
|
||||
cfg.Gates,
|
||||
)
|
||||
r.MustRegister(cfg.Gates)
|
||||
|
||||
mux.Handle("/metrics", promhttp.HandlerFor(r, promhttp.HandlerOpts{}))
|
||||
mux.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
|
||||
|
|
|
@ -30,8 +30,6 @@ import (
|
|||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/oklog/run"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/prometheus/common/version"
|
||||
"github.com/prometheus/exporter-toolkit/web"
|
||||
|
@ -39,6 +37,7 @@ import (
|
|||
|
||||
"github.com/prometheus-operator/prometheus-operator/internal/goruntime"
|
||||
logging "github.com/prometheus-operator/prometheus-operator/internal/log"
|
||||
"github.com/prometheus-operator/prometheus-operator/internal/metrics"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/operator"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/versionutil"
|
||||
)
|
||||
|
@ -150,11 +149,7 @@ func main() {
|
|||
goruntime.SetMaxProcs(logger)
|
||||
goruntime.SetMemLimit(logger, *memlimitRatio)
|
||||
|
||||
r := prometheus.NewRegistry()
|
||||
r.MustRegister(
|
||||
collectors.NewGoCollector(),
|
||||
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
||||
)
|
||||
r := metrics.NewRegistry("prometheus_config_reloader")
|
||||
|
||||
var (
|
||||
g run.Group
|
||||
|
|
42
internal/metrics/metrics.go
Normal file
42
internal/metrics/metrics.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
// Copyright 2024 The prometheus-operator Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors/version"
|
||||
)
|
||||
|
||||
func NewRegistry(program string) *prometheus.Registry {
|
||||
r := prometheus.NewRegistry()
|
||||
|
||||
// default registers
|
||||
r.MustRegister(
|
||||
collectors.NewGoCollector(
|
||||
collectors.WithGoCollectorRuntimeMetrics(
|
||||
collectors.MetricsGC,
|
||||
collectors.MetricsScheduler,
|
||||
collectors.MetricsMemory,
|
||||
collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile(`^/sync/.*`)},
|
||||
),
|
||||
),
|
||||
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
||||
version.NewCollector(program),
|
||||
)
|
||||
return r
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue