add pprof support
This commit is contained in:
@@ -27,6 +27,7 @@ func main() {
|
|||||||
flag.TextVar(&level, "log-level", zapcore.InfoLevel, "logger level")
|
flag.TextVar(&level, "log-level", zapcore.InfoLevel, "logger level")
|
||||||
flag.StringVar(&conf.MetricsBindAddress, "metrics-address", "127.0.0.1:8080", "The address the metric endpoint binds to.")
|
flag.StringVar(&conf.MetricsBindAddress, "metrics-address", "127.0.0.1:8080", "The address the metric endpoint binds to.")
|
||||||
flag.BoolVar(&conf.LeaderElection, "enable-leader-election", false, "Enable leader election for controller manager")
|
flag.BoolVar(&conf.LeaderElection, "enable-leader-election", false, "Enable leader election for controller manager")
|
||||||
|
flag.BoolVar(&conf.PProf, "enable-pprof", false, "Enable profile debug")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
// 初始化日志格式
|
// 初始化日志格式
|
||||||
ctrl.SetLogger(zap.New(func(o *zap.Options) {
|
ctrl.SetLogger(zap.New(func(o *zap.Options) {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package k8s
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
|
|
||||||
v1 "monitor/pkg/apis/v1"
|
v1 "monitor/pkg/apis/v1"
|
||||||
|
|
||||||
@@ -16,6 +18,7 @@ import (
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ctrl.Options
|
ctrl.Options
|
||||||
|
PProf bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
@@ -41,6 +44,14 @@ func NewManager(conf Config) (*Manager, error) {
|
|||||||
return nil, fmt.Errorf("unable to add scheme %w", err)
|
return nil, fmt.Errorf("unable to add scheme %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.PProf {
|
||||||
|
mgr.AddMetricsExtraHandler("/debug/pprof/", http.HandlerFunc(pprof.Index))
|
||||||
|
mgr.AddMetricsExtraHandler("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
|
||||||
|
mgr.AddMetricsExtraHandler("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
|
||||||
|
mgr.AddMetricsExtraHandler("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
|
||||||
|
mgr.AddMetricsExtraHandler("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
|
||||||
|
}
|
||||||
|
|
||||||
return &Manager{mgr: mgr}, nil
|
return &Manager{mgr: mgr}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user